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

Commit 01a9597

Browse files
Migrate Unit Tests to NUnit (#1090)
* Migrate to NUnit * Update Tests * Update Azure Pipelines * Update TextCaseConverter_Tests.cs * Update DateTimeOffsetConverter_Tests.cs * Increase Timeout * Increase Timeout * Add `const int defaultTimeoutThreshold` Co-authored-by: Gerald Versluis <[email protected]>
1 parent 0285677 commit 01a9597

File tree

57 files changed

+1263
-1289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1263
-1289
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,7 @@ jobs:
199199
- task: CmdLine@2
200200
displayName: 'Run Unit Tests'
201201
inputs:
202-
script: |
203-
dotnet restore $(PathToUnitTestCsproj) /p:Configuration=Release
204-
$(PathToMsBuildOnMacOS) $(PathToUnitTestCsproj) /p:Configuration=Release /restore /t:Build
205-
206-
echo "********** Running Unit Tests on .NET Framework (xUnit does not support dotnet test for .NET Framework: https://xunit.net/docs/getting-started/netfx/cmdline) **********"
207-
208-
# UnitTestDLL for .NET Framework 4.6.1 Result: `find . -name Xamarin.CommunityToolkit.UnitTests.dll | grep bin | grep 461`
209-
# XUnit Console Runner for .NET Framework 4.6.1 Result: `find ~/.nuget/packages | grep net461 | grep xunit.console.exe | grep -v config`
210-
211-
mono "`find ~/.nuget/packages | grep net461 | grep xunit.console.exe | grep -v config`" "`find . -name Xamarin.CommunityToolkit.UnitTests.dll | grep bin | grep 461`"
212-
213-
echo "***** Running Unit Tests on .NET Core *****"
214-
dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release /p:Platform="macOS"
202+
script: 'dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release'
215203
- task: CmdLine@2
216204
displayName: 'Pack NuGets'
217205
inputs:

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/CharactersValidationBehavior_Tests.cs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,41 @@
22
using Xamarin.CommunityToolkit.Behaviors;
33
using Xamarin.CommunityToolkit.UnitTests.Mocks;
44
using Xamarin.Forms;
5-
using Xunit;
5+
using NUnit.Framework;
66

77
namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
88
{
99
public class CharactersValidationBehavior_Tests
1010
{
11-
public CharactersValidationBehavior_Tests()
12-
=> Device.PlatformServices = new MockPlatformServices();
11+
[SetUp]
12+
public void Setup() => Device.PlatformServices = new MockPlatformServices();
1313

14-
[Theory]
15-
[InlineData(CharacterType.Any, 1, 2, "A", true)]
16-
[InlineData(CharacterType.Any, 0, int.MaxValue, "", true)]
17-
[InlineData(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWaWWWW", true)]
18-
[InlineData(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaaRRaaaa", true)]
19-
[InlineData(CharacterType.Letter, 4, int.MaxValue, "aaaaaaRRaaaa", true)]
20-
[InlineData(CharacterType.Digit, 1, int.MaxValue, "-1d", true)]
21-
[InlineData(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3r", true)]
22-
[InlineData(CharacterType.NonAlphanumericSymbol, 10, int.MaxValue, "@-&^%!+()/", true)]
23-
[InlineData(CharacterType.LowercaseLatinLetter, 2, int.MaxValue, "HHHH a r.", true)]
24-
[InlineData(CharacterType.UppercaseLatinLetter, 2, int.MaxValue, "aaaaaa....R.R.R.aaaa", true)]
25-
[InlineData(CharacterType.LatinLetter, 5, int.MaxValue, "12345bBbBb", true)]
26-
[InlineData(CharacterType.Whitespace, 0, int.MaxValue, ";lkjhgfd@+fasf", true)]
27-
[InlineData(CharacterType.Any, 2, 2, "A", false)]
28-
[InlineData(CharacterType.Any, 2, 2, "AaA", false)]
29-
[InlineData(CharacterType.Any, 1, int.MaxValue, "", false)]
30-
[InlineData(CharacterType.Any, 1, int.MaxValue, null, false)]
31-
[InlineData(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWW", false)]
32-
[InlineData(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaa", false)]
33-
[InlineData(CharacterType.Letter, 4, int.MaxValue, "wHo", false)]
34-
[InlineData(CharacterType.Digit, 1, int.MaxValue, "-d", false)]
35-
[InlineData(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3", false)]
36-
[InlineData(CharacterType.NonAlphanumericSymbol, 1, int.MaxValue, "WWWWWWWW", false)]
37-
[InlineData(CharacterType.LowercaseLatinLetter, 1, int.MaxValue, "Кириллица", false)]
38-
[InlineData(CharacterType.UppercaseLatinLetter, 1, int.MaxValue, "КИРИЛЛИЦА", false)]
39-
[InlineData(CharacterType.LatinLetter, 1, int.MaxValue, "Это Кириллица!", false)]
40-
[InlineData(CharacterType.Whitespace, 0, 0, "WWWWWW WWWWW", false)]
14+
[TestCase(CharacterType.Any, 1, 2, "A", true)]
15+
[TestCase(CharacterType.Any, 0, int.MaxValue, "", true)]
16+
[TestCase(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWaWWWW", true)]
17+
[TestCase(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaaRRaaaa", true)]
18+
[TestCase(CharacterType.Letter, 4, int.MaxValue, "aaaaaaRRaaaa", true)]
19+
[TestCase(CharacterType.Digit, 1, int.MaxValue, "-1d", true)]
20+
[TestCase(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3r", true)]
21+
[TestCase(CharacterType.NonAlphanumericSymbol, 10, int.MaxValue, "@-&^%!+()/", true)]
22+
[TestCase(CharacterType.LowercaseLatinLetter, 2, int.MaxValue, "HHHH a r.", true)]
23+
[TestCase(CharacterType.UppercaseLatinLetter, 2, int.MaxValue, "aaaaaa....R.R.R.aaaa", true)]
24+
[TestCase(CharacterType.LatinLetter, 5, int.MaxValue, "12345bBbBb", true)]
25+
[TestCase(CharacterType.Whitespace, 0, int.MaxValue, ";lkjhgfd@+fasf", true)]
26+
[TestCase(CharacterType.Any, 2, 2, "A", false)]
27+
[TestCase(CharacterType.Any, 2, 2, "AaA", false)]
28+
[TestCase(CharacterType.Any, 1, int.MaxValue, "", false)]
29+
[TestCase(CharacterType.Any, 1, int.MaxValue, null, false)]
30+
[TestCase(CharacterType.LowercaseLetter, 1, int.MaxValue, "WWWWWW", false)]
31+
[TestCase(CharacterType.UppercaseLetter, 1, int.MaxValue, "aaaaaa", false)]
32+
[TestCase(CharacterType.Letter, 4, int.MaxValue, "wHo", false)]
33+
[TestCase(CharacterType.Digit, 1, int.MaxValue, "-d", false)]
34+
[TestCase(CharacterType.Alphanumeric, 2, int.MaxValue, "@-3", false)]
35+
[TestCase(CharacterType.NonAlphanumericSymbol, 1, int.MaxValue, "WWWWWWWW", false)]
36+
[TestCase(CharacterType.LowercaseLatinLetter, 1, int.MaxValue, "Кириллица", false)]
37+
[TestCase(CharacterType.UppercaseLatinLetter, 1, int.MaxValue, "КИРИЛЛИЦА", false)]
38+
[TestCase(CharacterType.LatinLetter, 1, int.MaxValue, "Это Кириллица!", false)]
39+
[TestCase(CharacterType.Whitespace, 0, 0, "WWWWWW WWWWW", false)]
4140
public async Task IsValid(CharacterType characterType, int minimumCharactersNumber, int maximumCharactersNumber, string value, bool expectedValue)
4241
{
4342
// Arrange
@@ -58,7 +57,7 @@ public async Task IsValid(CharacterType characterType, int minimumCharactersNumb
5857
await behavior.ForceValidate();
5958

6059
// Assert
61-
Assert.Equal(expectedValue, behavior.IsValid);
60+
Assert.AreEqual(expectedValue, behavior.IsValid);
6261
}
6362
}
6463
}

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/EventToCommandBehavior_Tests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
using Xamarin.CommunityToolkit.Behaviors;
33
using Xamarin.CommunityToolkit.UnitTests.Mocks;
44
using Xamarin.Forms;
5-
using Xunit;
5+
using NUnit.Framework;
66

77
namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
88
{
99
public class EventToCommandBehavior_Tests
1010
{
11-
public EventToCommandBehavior_Tests()
12-
=> Device.PlatformServices = new MockPlatformServices();
11+
[SetUp]
12+
public void SetUp() => Device.PlatformServices = new MockPlatformServices();
1313

14-
[Fact]
14+
[Test]
1515
public void ArgumentExceptionIfSpecifiedEventDoesNotExist()
1616
{
1717
var listView = new ListView();
@@ -22,7 +22,7 @@ public void ArgumentExceptionIfSpecifiedEventDoesNotExist()
2222
Assert.Throws<ArgumentException>(() => listView.Behaviors.Add(behavior));
2323
}
2424

25-
[Fact]
25+
[Test]
2626
public void NoExceptionIfSpecifiedEventExists()
2727
{
2828
var listView = new ListView();
@@ -33,7 +33,7 @@ public void NoExceptionIfSpecifiedEventExists()
3333
listView.Behaviors.Add(behavior);
3434
}
3535

36-
[Fact]
36+
[Test]
3737
public void NoExceptionIfAttachedToPage()
3838
{
3939
var page = new ContentPage();

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/ImpliedOrderGridBehavior_Tests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22
using Xamarin.CommunityToolkit.Behaviors;
33
using Xamarin.Forms;
4-
using Xunit;
4+
using NUnit.Framework;
55

66
namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
77
{
88
public class ImpliedOrderGridBehavior_Tests
99
{
10-
[Fact]
10+
[Test]
1111
public void CorrectRowColumnAssignment()
1212
{
1313
var grid = new Grid();
@@ -73,7 +73,7 @@ public void CorrectRowColumnAssignment()
7373
AssertExpectedCoordinates(grid, new Label(), 4, 0);
7474
}
7575

76-
[Fact]
76+
[Test]
7777
public void ThrowsOnManualAssignmentToUsedCell()
7878
{
7979
var grid = CreateExceptionTestGrid();
@@ -89,7 +89,7 @@ public void ThrowsOnManualAssignmentToUsedCell()
8989
Assert.Throws<Exception>(() => grid.Children.Add(throwLabel));
9090
}
9191

92-
[Fact]
92+
[Test]
9393
public void ThrowsOnCellsExceeded()
9494
{
9595
var grid = CreateExceptionTestGrid();
@@ -110,7 +110,7 @@ public void ThrowsOnCellsExceeded()
110110
Assert.Throws<Exception>(() => grid.Children.Add(new Label()));
111111
}
112112

113-
[Fact]
113+
[Test]
114114
public void ThrowsOnSpanExceedsColumns()
115115
{
116116
var grid = CreateExceptionTestGrid();
@@ -121,7 +121,7 @@ public void ThrowsOnSpanExceedsColumns()
121121
Assert.Throws<Exception>(() => grid.Children.Add(throwLabel));
122122
}
123123

124-
[Fact]
124+
[Test]
125125
public void ThrowsOnSpanExceedsRows()
126126
{
127127
var grid = CreateExceptionTestGrid();
@@ -149,8 +149,8 @@ Grid CreateExceptionTestGrid()
149149
void AssertExpectedCoordinates(Grid grid, View view, int row, int column)
150150
{
151151
grid.Children.Add(view);
152-
Assert.Equal(row, Grid.GetRow(view));
153-
Assert.Equal(column, Grid.GetColumn(view));
152+
Assert.AreEqual(row, Grid.GetRow(view));
153+
Assert.AreEqual(column, Grid.GetColumn(view));
154154
}
155155
}
156156
}

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MaxLengthReachedBehavior_Tests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using System.Windows.Input;
33
using Xamarin.CommunityToolkit.Behaviors;
44
using Xamarin.Forms;
5-
using Xunit;
5+
using NUnit.Framework;
66

77
namespace Xamarin.CommunityToolkit.UnitTests.Behaviors
88
{
99
public class MaxLengthReachedBehavior_Tests
1010
{
11-
[Fact]
11+
[Test]
1212
public void ShouldExecuteCommandWhenMaxLengthHasBeenReached()
1313
{
1414
// arrange
@@ -20,10 +20,10 @@ public void ShouldExecuteCommandWhenMaxLengthHasBeenReached()
2020
entry.Text += "2";
2121

2222
// assert
23-
Assert.True(commandHasBeenExecuted);
23+
Assert.IsTrue(commandHasBeenExecuted);
2424
}
2525

26-
[Fact]
26+
[Test]
2727
public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached()
2828
{
2929
// arrange
@@ -35,10 +35,10 @@ public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached()
3535
entry.Text += "2";
3636

3737
// assert
38-
Assert.True(eventHandlerHasBeenInvoked);
38+
Assert.IsTrue(eventHandlerHasBeenInvoked);
3939
}
4040

41-
[Fact]
41+
[Test]
4242
public void ShouldExecuteCommandWithTextValueNoLargerThenMaxLength()
4343
{
4444
// arrange
@@ -51,10 +51,10 @@ public void ShouldExecuteCommandWithTextValueNoLargerThenMaxLength()
5151
entry.Text = "123456789";
5252

5353
// assert
54-
Assert.Equal(expectedLength, actualLength);
54+
Assert.AreEqual(expectedLength, actualLength);
5555
}
5656

57-
[Fact]
57+
[Test]
5858
public void ShouldInvokeEventHandlerWithTextValueNoLargerThenMaxLength()
5959
{
6060
// arrange
@@ -67,10 +67,10 @@ public void ShouldInvokeEventHandlerWithTextValueNoLargerThenMaxLength()
6767
entry.Text = "123456789";
6868

6969
// assert
70-
Assert.Equal(expectedLength, actualLength);
70+
Assert.AreEqual(expectedLength, actualLength);
7171
}
7272

73-
[Fact]
73+
[Test]
7474
public void ShouldNotExecuteCommandBeforeMaxLengthHasBeenReached()
7575
{
7676
// arrange
@@ -84,7 +84,7 @@ public void ShouldNotExecuteCommandBeforeMaxLengthHasBeenReached()
8484
Assert.False(commandHasBeenExecuted);
8585
}
8686

87-
[Fact]
87+
[Test]
8888
public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached()
8989
{
9090
// arrange
@@ -98,7 +98,7 @@ public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached()
9898
Assert.False(eventHandlerHasBeenInvoked);
9999
}
100100

101-
[Fact]
101+
[Test]
102102
public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached()
103103
{
104104
// arrange
@@ -113,7 +113,7 @@ public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached()
113113
Assert.False(entry.IsFocused);
114114
}
115115

116-
[Fact]
116+
[Test]
117117
public void ShouldNotDismissKeyboardBeforeMaxLengthHasBeenReached()
118118
{
119119
// arrange
@@ -124,10 +124,10 @@ public void ShouldNotDismissKeyboardBeforeMaxLengthHasBeenReached()
124124
entry.Text = "1";
125125

126126
// assert
127-
Assert.True(entry.IsFocused);
127+
Assert.IsTrue(entry.IsFocused);
128128
}
129129

130-
[Fact]
130+
[Test]
131131
public void ShouldNotDismissKeyboardWhenOptionSetToFalse()
132132
{
133133
// arrange
@@ -139,7 +139,7 @@ public void ShouldNotDismissKeyboardWhenOptionSetToFalse()
139139
entry.Text += "1";
140140

141141
// assert
142-
Assert.True(entry.IsFocused);
142+
Assert.IsTrue(entry.IsFocused);
143143
}
144144

145145
Entry CreateEntry(int? maxLength = 2,

0 commit comments

Comments
 (0)