Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Migrate Unit Tests to NUnit #1090

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,7 @@ jobs:
- task: CmdLine@2
displayName: 'Run Unit Tests'
inputs:
script: |
dotnet restore $(PathToUnitTestCsproj) /p:Configuration=Release
$(PathToMsBuildOnMacOS) $(PathToUnitTestCsproj) /p:Configuration=Release /restore /t:Build

echo "********** Running Unit Tests on .NET Framework (xUnit does not support dotnet test for .NET Framework: https://xunit.net/docs/getting-started/netfx/cmdline) **********"

# UnitTestDLL for .NET Framework 4.6.1 Result: `find . -name Xamarin.CommunityToolkit.UnitTests.dll | grep bin | grep 461`
# XUnit Console Runner for .NET Framework 4.6.1 Result: `find ~/.nuget/packages | grep net461 | grep xunit.console.exe | grep -v config`

mono "`find ~/.nuget/packages | grep net461 | grep xunit.console.exe | grep -v config`" "`find . -name Xamarin.CommunityToolkit.UnitTests.dll | grep bin | grep 461`"

echo "***** Running Unit Tests on .NET Core *****"
dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release /p:Platform="macOS"
script: 'dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release'
- task: CmdLine@2
displayName: 'Pack NuGets'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.CommunityToolkit.UnitTests.Mocks;
using Xamarin.Forms;
using Xunit;
using NUnit.Framework;

namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
{
public class CharactersValidationBehavior_Tests
{
public CharactersValidationBehavior_Tests()
=> Device.PlatformServices = new MockPlatformServices();
[SetUp]
public void Setup() => Device.PlatformServices = new MockPlatformServices();

[Theory]
[InlineData(CharacterType.Any, 1, 2, "A", true)]
[InlineData(CharacterType.Any, 0, int.MaxValue, "", true)]
[InlineData(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWaWWWW", true)]
[InlineData(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaaRRaaaa", true)]
[InlineData(CharacterType.Letter, 4, int.MaxValue, "aaaaaaRRaaaa", true)]
[InlineData(CharacterType.Digit, 1, int.MaxValue, "-1d", true)]
[InlineData(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3r", true)]
[InlineData(CharacterType.NonAlphanumericSymbol, 10, int.MaxValue, "@-&^%!+()/", true)]
[InlineData(CharacterType.LowercaseLatinLetter, 2, int.MaxValue, "HHHH a r.", true)]
[InlineData(CharacterType.UppercaseLatinLetter, 2, int.MaxValue, "aaaaaa....R.R.R.aaaa", true)]
[InlineData(CharacterType.LatinLetter, 5, int.MaxValue, "12345bBbBb", true)]
[InlineData(CharacterType.Whitespace, 0, int.MaxValue, ";lkjhgfd@+fasf", true)]
[InlineData(CharacterType.Any, 2, 2, "A", false)]
[InlineData(CharacterType.Any, 2, 2, "AaA", false)]
[InlineData(CharacterType.Any, 1, int.MaxValue, "", false)]
[InlineData(CharacterType.Any, 1, int.MaxValue, null, false)]
[InlineData(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWW", false)]
[InlineData(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaa", false)]
[InlineData(CharacterType.Letter, 4, int.MaxValue, "wHo", false)]
[InlineData(CharacterType.Digit, 1, int.MaxValue, "-d", false)]
[InlineData(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3", false)]
[InlineData(CharacterType.NonAlphanumericSymbol, 1, int.MaxValue, "WWWWWWWW", false)]
[InlineData(CharacterType.LowercaseLatinLetter, 1, int.MaxValue, "Кириллица", false)]
[InlineData(CharacterType.UppercaseLatinLetter, 1, int.MaxValue, "КИРИЛЛИЦА", false)]
[InlineData(CharacterType.LatinLetter, 1, int.MaxValue, "Это Кириллица!", false)]
[InlineData(CharacterType.Whitespace, 0, 0, "WWWWWW WWWWW", false)]
[TestCase(CharacterType.Any, 1, 2, "A", true)]
[TestCase(CharacterType.Any, 0, int.MaxValue, "", true)]
[TestCase(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWaWWWW", true)]
[TestCase(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaaRRaaaa", true)]
[TestCase(CharacterType.Letter, 4, int.MaxValue, "aaaaaaRRaaaa", true)]
[TestCase(CharacterType.Digit, 1, int.MaxValue, "-1d", true)]
[TestCase(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3r", true)]
[TestCase(CharacterType.NonAlphanumericSymbol, 10, int.MaxValue, "@-&^%!+()/", true)]
[TestCase(CharacterType.LowercaseLatinLetter, 2, int.MaxValue, "HHHH a r.", true)]
[TestCase(CharacterType.UppercaseLatinLetter, 2, int.MaxValue, "aaaaaa....R.R.R.aaaa", true)]
[TestCase(CharacterType.LatinLetter, 5, int.MaxValue, "12345bBbBb", true)]
[TestCase(CharacterType.Whitespace, 0, int.MaxValue, ";lkjhgfd@+fasf", true)]
[TestCase(CharacterType.Any, 2, 2, "A", false)]
[TestCase(CharacterType.Any, 2, 2, "AaA", false)]
[TestCase(CharacterType.Any, 1, int.MaxValue, "", false)]
[TestCase(CharacterType.Any, 1, int.MaxValue, null, false)]
[TestCase(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWW", false)]
[TestCase(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaa", false)]
[TestCase(CharacterType.Letter, 4, int.MaxValue, "wHo", false)]
[TestCase(CharacterType.Digit, 1, int.MaxValue, "-d", false)]
[TestCase(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3", false)]
[TestCase(CharacterType.NonAlphanumericSymbol, 1, int.MaxValue, "WWWWWWWW", false)]
[TestCase(CharacterType.LowercaseLatinLetter, 1, int.MaxValue, "Кириллица", false)]
[TestCase(CharacterType.UppercaseLatinLetter, 1, int.MaxValue, "КИРИЛЛИЦА", false)]
[TestCase(CharacterType.LatinLetter, 1, int.MaxValue, "Это Кириллица!", false)]
[TestCase(CharacterType.Whitespace, 0, 0, "WWWWWW WWWWW", false)]
public async Task IsValid(CharacterType characterType, int minimumCharactersNumber, int maximumCharactersNumber, string value, bool expectedValue)
{
// Arrange
Expand All @@ -58,7 +57,7 @@ public async Task IsValid(CharacterType characterType, int minimumCharactersNumb
await behavior.ForceValidate();

// Assert
Assert.Equal(expectedValue, behavior.IsValid);
Assert.AreEqual(expectedValue, behavior.IsValid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.CommunityToolkit.UnitTests.Mocks;
using Xamarin.Forms;
using Xunit;
using NUnit.Framework;

namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
{
public class EventToCommandBehavior_Tests
{
public EventToCommandBehavior_Tests()
=> Device.PlatformServices = new MockPlatformServices();
[SetUp]
public void SetUp() => Device.PlatformServices = new MockPlatformServices();

[Fact]
[Test]
public void ArgumentExceptionIfSpecifiedEventDoesNotExist()
{
var listView = new ListView();
Expand All @@ -22,7 +22,7 @@ public void ArgumentExceptionIfSpecifiedEventDoesNotExist()
Assert.Throws<ArgumentException>(() => listView.Behaviors.Add(behavior));
}

[Fact]
[Test]
public void NoExceptionIfSpecifiedEventExists()
{
var listView = new ListView();
Expand All @@ -33,7 +33,7 @@ public void NoExceptionIfSpecifiedEventExists()
listView.Behaviors.Add(behavior);
}

[Fact]
[Test]
public void NoExceptionIfAttachedToPage()
{
var page = new ContentPage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.Forms;
using Xunit;
using NUnit.Framework;

namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
{
public class ImpliedOrderGridBehavior_Tests
{
[Fact]
[Test]
public void CorrectRowColumnAssignment()
{
var grid = new Grid();
Expand Down Expand Up @@ -73,7 +73,7 @@ public void CorrectRowColumnAssignment()
AssertExpectedCoordinates(grid, new Label(), 4, 0);
}

[Fact]
[Test]
public void ThrowsOnManualAssignmentToUsedCell()
{
var grid = CreateExceptionTestGrid();
Expand All @@ -89,7 +89,7 @@ public void ThrowsOnManualAssignmentToUsedCell()
Assert.Throws<Exception>(() => grid.Children.Add(throwLabel));
}

[Fact]
[Test]
public void ThrowsOnCellsExceeded()
{
var grid = CreateExceptionTestGrid();
Expand All @@ -110,7 +110,7 @@ public void ThrowsOnCellsExceeded()
Assert.Throws<Exception>(() => grid.Children.Add(new Label()));
}

[Fact]
[Test]
public void ThrowsOnSpanExceedsColumns()
{
var grid = CreateExceptionTestGrid();
Expand All @@ -121,7 +121,7 @@ public void ThrowsOnSpanExceedsColumns()
Assert.Throws<Exception>(() => grid.Children.Add(throwLabel));
}

[Fact]
[Test]
public void ThrowsOnSpanExceedsRows()
{
var grid = CreateExceptionTestGrid();
Expand Down Expand Up @@ -149,8 +149,8 @@ Grid CreateExceptionTestGrid()
void AssertExpectedCoordinates(Grid grid, View view, int row, int column)
{
grid.Children.Add(view);
Assert.Equal(row, Grid.GetRow(view));
Assert.Equal(column, Grid.GetColumn(view));
Assert.AreEqual(row, Grid.GetRow(view));
Assert.AreEqual(column, Grid.GetColumn(view));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.Windows.Input;
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.Forms;
using Xunit;
using NUnit.Framework;

namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
{
public class MaxLengthReachedBehavior_Tests
{
[Fact]
[Test]
public void ShouldExecuteCommandWhenMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -20,10 +20,10 @@ public void ShouldExecuteCommandWhenMaxLengthHasBeenReached()
entry.Text += "2";

// assert
Assert.True(commandHasBeenExecuted);
Assert.IsTrue(commandHasBeenExecuted);
}

[Fact]
[Test]
public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -35,10 +35,10 @@ public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached()
entry.Text += "2";

// assert
Assert.True(eventHandlerHasBeenInvoked);
Assert.IsTrue(eventHandlerHasBeenInvoked);
}

[Fact]
[Test]
public void ShouldExecuteCommandWithTextValueNoLargerThenMaxLength()
{
// arrange
Expand All @@ -51,10 +51,10 @@ public void ShouldExecuteCommandWithTextValueNoLargerThenMaxLength()
entry.Text = "123456789";

// assert
Assert.Equal(expectedLength, actualLength);
Assert.AreEqual(expectedLength, actualLength);
}

[Fact]
[Test]
public void ShouldInvokeEventHandlerWithTextValueNoLargerThenMaxLength()
{
// arrange
Expand All @@ -67,10 +67,10 @@ public void ShouldInvokeEventHandlerWithTextValueNoLargerThenMaxLength()
entry.Text = "123456789";

// assert
Assert.Equal(expectedLength, actualLength);
Assert.AreEqual(expectedLength, actualLength);
}

[Fact]
[Test]
public void ShouldNotExecuteCommandBeforeMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -84,7 +84,7 @@ public void ShouldNotExecuteCommandBeforeMaxLengthHasBeenReached()
Assert.False(commandHasBeenExecuted);
}

[Fact]
[Test]
public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -98,7 +98,7 @@ public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached()
Assert.False(eventHandlerHasBeenInvoked);
}

[Fact]
[Test]
public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -113,7 +113,7 @@ public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached()
Assert.False(entry.IsFocused);
}

[Fact]
[Test]
public void ShouldNotDismissKeyboardBeforeMaxLengthHasBeenReached()
{
// arrange
Expand All @@ -124,10 +124,10 @@ public void ShouldNotDismissKeyboardBeforeMaxLengthHasBeenReached()
entry.Text = "1";

// assert
Assert.True(entry.IsFocused);
Assert.IsTrue(entry.IsFocused);
}

[Fact]
[Test]
public void ShouldNotDismissKeyboardWhenOptionSetToFalse()
{
// arrange
Expand All @@ -139,7 +139,7 @@ public void ShouldNotDismissKeyboardWhenOptionSetToFalse()
entry.Text += "1";

// assert
Assert.True(entry.IsFocused);
Assert.IsTrue(entry.IsFocused);
}

Entry CreateEntry(int? maxLength = 2,
Expand Down
Loading