diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2755fac31..b27fb0ddc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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: diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/CharactersValidationBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/CharactersValidationBehavior_Tests.cs index c70d51ceb..f9c9f3a2e 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/CharactersValidationBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/CharactersValidationBehavior_Tests.cs @@ -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 @@ -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); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/EventToCommandBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/EventToCommandBehavior_Tests.cs index 91787df9b..6806ed5a1 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/EventToCommandBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/EventToCommandBehavior_Tests.cs @@ -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(); @@ -22,7 +22,7 @@ public void ArgumentExceptionIfSpecifiedEventDoesNotExist() Assert.Throws(() => listView.Behaviors.Add(behavior)); } - [Fact] + [Test] public void NoExceptionIfSpecifiedEventExists() { var listView = new ListView(); @@ -33,7 +33,7 @@ public void NoExceptionIfSpecifiedEventExists() listView.Behaviors.Add(behavior); } - [Fact] + [Test] public void NoExceptionIfAttachedToPage() { var page = new ContentPage(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/ImpliedOrderGridBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/ImpliedOrderGridBehavior_Tests.cs index e02fb2e88..91ee07778 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/ImpliedOrderGridBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/ImpliedOrderGridBehavior_Tests.cs @@ -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(); @@ -73,7 +73,7 @@ public void CorrectRowColumnAssignment() AssertExpectedCoordinates(grid, new Label(), 4, 0); } - [Fact] + [Test] public void ThrowsOnManualAssignmentToUsedCell() { var grid = CreateExceptionTestGrid(); @@ -89,7 +89,7 @@ public void ThrowsOnManualAssignmentToUsedCell() Assert.Throws(() => grid.Children.Add(throwLabel)); } - [Fact] + [Test] public void ThrowsOnCellsExceeded() { var grid = CreateExceptionTestGrid(); @@ -110,7 +110,7 @@ public void ThrowsOnCellsExceeded() Assert.Throws(() => grid.Children.Add(new Label())); } - [Fact] + [Test] public void ThrowsOnSpanExceedsColumns() { var grid = CreateExceptionTestGrid(); @@ -121,7 +121,7 @@ public void ThrowsOnSpanExceedsColumns() Assert.Throws(() => grid.Children.Add(throwLabel)); } - [Fact] + [Test] public void ThrowsOnSpanExceedsRows() { var grid = CreateExceptionTestGrid(); @@ -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)); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MaxLengthReachedBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MaxLengthReachedBehavior_Tests.cs index 721f4427c..b6d66d3ff 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MaxLengthReachedBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MaxLengthReachedBehavior_Tests.cs @@ -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 @@ -20,10 +20,10 @@ public void ShouldExecuteCommandWhenMaxLengthHasBeenReached() entry.Text += "2"; // assert - Assert.True(commandHasBeenExecuted); + Assert.IsTrue(commandHasBeenExecuted); } - [Fact] + [Test] public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached() { // arrange @@ -35,10 +35,10 @@ public void ShouldInvokeEventHandlerWhenMaxLengthHasBeenReached() entry.Text += "2"; // assert - Assert.True(eventHandlerHasBeenInvoked); + Assert.IsTrue(eventHandlerHasBeenInvoked); } - [Fact] + [Test] public void ShouldExecuteCommandWithTextValueNoLargerThenMaxLength() { // arrange @@ -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 @@ -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 @@ -84,7 +84,7 @@ public void ShouldNotExecuteCommandBeforeMaxLengthHasBeenReached() Assert.False(commandHasBeenExecuted); } - [Fact] + [Test] public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached() { // arrange @@ -98,7 +98,7 @@ public void ShouldNotInvokeEventHandlerBeforeMaxLengthHasBeenReached() Assert.False(eventHandlerHasBeenInvoked); } - [Fact] + [Test] public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached() { // arrange @@ -113,7 +113,7 @@ public void ShouldDismissKeyboardWhenMaxLengthHasBeenReached() Assert.False(entry.IsFocused); } - [Fact] + [Test] public void ShouldNotDismissKeyboardBeforeMaxLengthHasBeenReached() { // arrange @@ -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 @@ -139,7 +139,7 @@ public void ShouldNotDismissKeyboardWhenOptionSetToFalse() entry.Text += "1"; // assert - Assert.True(entry.IsFocused); + Assert.IsTrue(entry.IsFocused); } Entry CreateEntry(int? maxLength = 2, diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MultiValidationBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MultiValidationBehavior_Tests.cs index f5e320902..bfb8a2648 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MultiValidationBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/MultiValidationBehavior_Tests.cs @@ -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 MultiValidationBehavior_Tests { - public MultiValidationBehavior_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 @@ -61,7 +60,7 @@ public async Task IsValid(CharacterType characterType, int minimumCharactersNumb await multiBehavior.ForceValidate(); // Assert - Assert.Equal(expectedValue, multiBehavior.IsValid); + Assert.AreEqual(expectedValue, multiBehavior.IsValid); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/NumericValidationBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/NumericValidationBehavior_Tests.cs index a199bcd06..711eea8cb 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/NumericValidationBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/NumericValidationBehavior_Tests.cs @@ -3,48 +3,47 @@ using Xamarin.CommunityToolkit.Behaviors; using Xamarin.CommunityToolkit.UnitTests.Mocks; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Behaviors { public class NumericValidationBehavior_Tests { - public NumericValidationBehavior_Tests() - => Device.PlatformServices = new MockPlatformServices(); + [SetUp] + public void Setup() => Device.PlatformServices = new MockPlatformServices(); - [Theory] - [InlineData("en-US", "15.2", 1.0, 16.0, 0, 16, true)] - [InlineData("en-US", "15.", 1.0, 16.0, 0, 1, true)] - [InlineData("en-US", "15.88", 1.0, 16.0, 2, 2, true)] - [InlineData("en-US", "0.99", 0.9, 2.0, 0, 16, true)] - [InlineData("en-US", ".99", 0.9, 2.0, 0, 16, true)] - [InlineData("en-US", "1,115.2", 1.0, 2000.0, 0, 16, true)] - [InlineData("de-DE", "15,2", 1.0, 16.0, 0, 16, true)] - [InlineData("de-DE", "15,", 1.0, 16.0, 0, 1, true)] - [InlineData("de-DE", "15,88", 1.0, 16.0, 2, 2, true)] - [InlineData("de-DE", "0,99", 0.9, 2.0, 0, 16, true)] - [InlineData("de-DE", ",99", 0.9, 2.0, 0, 16, true)] - [InlineData("de-DE", "1.115,2", 1.0, 2000.0, 0, 16, true)] - [InlineData("en-US", "15.3", 16.0, 20.0, 0, 16, false)] - [InlineData("en-US", "15.3", 0.0, 15.0, 0, 16, false)] - [InlineData("en-US", "15.", 1.0, 16.0, 0, 0, false)] - [InlineData("en-US", ".7", 0.0, 16.0, 0, 0, false)] - [InlineData("en-US", "15", 1.0, 16.0, 1, 16, false)] - [InlineData("en-US", "", 0.0, 16.0, 0, 16, false)] - [InlineData("en-US", " ", 0.0, 16.0, 0, 16, false)] - [InlineData("en-US", null, 0.0, 16.0, 0, 16, false)] - [InlineData("en-US", "15,2", 1.0, 16.0, 0, 16, false)] - [InlineData("en-US", "1.115,2", 1.0, 2000.0, 0, 16, false)] - [InlineData("de-DE", "15,3", 16.0, 20.0, 0, 16, false)] - [InlineData("de-DE", "15,3", 0.0, 15.0, 0, 16, false)] - [InlineData("de-DE", "15,", 1.0, 16.0, 0, 0, false)] - [InlineData("de-DE", ",7", 0.0, 16.0, 0, 0, false)] - [InlineData("de-DE", "15", 1.0, 16.0, 1, 16, false)] - [InlineData("de-DE", "", 0.0, 16.0, 0, 16, false)] - [InlineData("de-DE", " ", 0.0, 16.0, 0, 16, false)] - [InlineData("de-DE", null, 0.0, 16.0, 0, 16, false)] - [InlineData("de-DE", "15.2", 1.0, 16.0, 0, 16, false)] - [InlineData("de-DE", "1,115.2", 1.0, 2000.0, 0, 16, false)] + [TestCase("en-US", "15.2", 1.0, 16.0, 0, 16, true)] + [TestCase("en-US", "15.", 1.0, 16.0, 0, 1, true)] + [TestCase("en-US", "15.88", 1.0, 16.0, 2, 2, true)] + [TestCase("en-US", "0.99", 0.9, 2.0, 0, 16, true)] + [TestCase("en-US", ".99", 0.9, 2.0, 0, 16, true)] + [TestCase("en-US", "1,115.2", 1.0, 2000.0, 0, 16, true)] + [TestCase("de-DE", "15,2", 1.0, 16.0, 0, 16, true)] + [TestCase("de-DE", "15,", 1.0, 16.0, 0, 1, true)] + [TestCase("de-DE", "15,88", 1.0, 16.0, 2, 2, true)] + [TestCase("de-DE", "0,99", 0.9, 2.0, 0, 16, true)] + [TestCase("de-DE", ",99", 0.9, 2.0, 0, 16, true)] + [TestCase("de-DE", "1.115,2", 1.0, 2000.0, 0, 16, true)] + [TestCase("en-US", "15.3", 16.0, 20.0, 0, 16, false)] + [TestCase("en-US", "15.3", 0.0, 15.0, 0, 16, false)] + [TestCase("en-US", "15.", 1.0, 16.0, 0, 0, false)] + [TestCase("en-US", ".7", 0.0, 16.0, 0, 0, false)] + [TestCase("en-US", "15", 1.0, 16.0, 1, 16, false)] + [TestCase("en-US", "", 0.0, 16.0, 0, 16, false)] + [TestCase("en-US", " ", 0.0, 16.0, 0, 16, false)] + [TestCase("en-US", null, 0.0, 16.0, 0, 16, false)] + [TestCase("en-US", "15,2", 1.0, 16.0, 0, 16, false)] + [TestCase("en-US", "1.115,2", 1.0, 2000.0, 0, 16, false)] + [TestCase("de-DE", "15,3", 16.0, 20.0, 0, 16, false)] + [TestCase("de-DE", "15,3", 0.0, 15.0, 0, 16, false)] + [TestCase("de-DE", "15,", 1.0, 16.0, 0, 0, false)] + [TestCase("de-DE", ",7", 0.0, 16.0, 0, 0, false)] + [TestCase("de-DE", "15", 1.0, 16.0, 1, 16, false)] + [TestCase("de-DE", "", 0.0, 16.0, 0, 16, false)] + [TestCase("de-DE", " ", 0.0, 16.0, 0, 16, false)] + [TestCase("de-DE", null, 0.0, 16.0, 0, 16, false)] + [TestCase("de-DE", "15.2", 1.0, 16.0, 0, 16, false)] + [TestCase("de-DE", "1,115.2", 1.0, 2000.0, 0, 16, false)] public async Task IsValid(string culture, string value, double minValue, double maxValue, int minDecimalPlaces, int maxDecimalPlaces, bool expectedValue) { // Arrange @@ -71,7 +70,7 @@ public async Task IsValid(string culture, string value, double minValue, double await behavior.ForceValidate(); // Assert - Assert.Equal(expectedValue, behavior.IsValid); + Assert.AreEqual(expectedValue, behavior.IsValid); } finally { diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/RequiredStringValidationBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/RequiredStringValidationBehavior_Tests.cs index 4677da082..e0bcd48f7 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/RequiredStringValidationBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/RequiredStringValidationBehavior_Tests.cs @@ -1,16 +1,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 RequiredStringValidationBehavior_Tests { - public RequiredStringValidationBehavior_Tests() - => Device.PlatformServices = new MockPlatformServices(); + [SetUp] + public void Setup() => Device.PlatformServices = new MockPlatformServices(); - [Fact] + [Test] public void IsValidTrueWhenBothIsNull_Test() { // Arrange @@ -24,10 +24,10 @@ public void IsValidTrueWhenBothIsNull_Test() confirmPasswordEntry.Behaviors.Add(confirmPasswordBehavior); // Assert - Assert.True(confirmPasswordBehavior.IsValid); + Assert.IsTrue(confirmPasswordBehavior.IsValid); } - [Fact] + [Test] public void IsValidFalseWhenOneIsNull_Test() { // Arrange @@ -47,7 +47,7 @@ public void IsValidFalseWhenOneIsNull_Test() Assert.False(confirmPasswordBehavior.IsValid); } - [Fact] + [Test] public void IsValidTrueWhenEnterSameText_Test() { // Arrange @@ -63,10 +63,10 @@ public void IsValidTrueWhenEnterSameText_Test() confirmPasswordEntry.Text = "123456"; // Assert - Assert.True(confirmPasswordBehavior.IsValid); + Assert.IsTrue(confirmPasswordBehavior.IsValid); } - [Fact] + [Test] public void IsValidFalseWhenEnterDifferentText_Test() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/SetFocusOnEntryCompleted_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/SetFocusOnEntryCompleted_Tests.cs index 9baf711bc..84a9b7380 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/SetFocusOnEntryCompleted_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/SetFocusOnEntryCompleted_Tests.cs @@ -1,12 +1,12 @@ using Xamarin.CommunityToolkit.Behaviors; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Behaviors { public class SetFocusOnEntryCompleted_Tests { - [Fact] + [Test] public void DoesNotSetFocusBeforeCompletion() { // arrange @@ -21,7 +21,7 @@ public void DoesNotSetFocusBeforeCompletion() Assert.False(entry2.IsFocused); } - [Fact] + [Test] public void SetsFocusWhenCompleted() { // arrange @@ -33,7 +33,7 @@ public void SetsFocusWhenCompleted() entry1.SendCompleted(); // assert - Assert.True(entry2.IsFocused); + Assert.IsTrue(entry2.IsFocused); } public Entry CreateEntry(VisualElement? nextElement = null) diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UriValidationBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UriValidationBehavior_Tests.cs index 03c78c0fd..647b8688f 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UriValidationBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UriValidationBehavior_Tests.cs @@ -3,22 +3,21 @@ using Xamarin.CommunityToolkit.Behaviors; using Xamarin.CommunityToolkit.UnitTests.Mocks; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Behaviors { public class UriValidationBehavior_Tests { - public UriValidationBehavior_Tests() - => Device.PlatformServices = new MockPlatformServices(); + [SetUp] + public void Setup() => Device.PlatformServices = new MockPlatformServices(); - [Theory] - [InlineData(@"http://microsoft.com", UriKind.Absolute, true)] - [InlineData(@"microsoft/xamarin/news", UriKind.Relative, true)] - [InlineData(@"http://microsoft.com", UriKind.RelativeOrAbsolute, true)] - [InlineData(@"microsoftcom", UriKind.Absolute, false)] - [InlineData(@"microsoft\\\\\xamarin/news", UriKind.Relative, false)] - [InlineData(@"ht\\\.com", UriKind.RelativeOrAbsolute, false)] + [TestCase(@"http://microsoft.com", UriKind.Absolute, true)] + [TestCase(@"microsoft/xamarin/news", UriKind.Relative, true)] + [TestCase(@"http://microsoft.com", UriKind.RelativeOrAbsolute, true)] + [TestCase(@"microsoftcom", UriKind.Absolute, false)] + [TestCase(@"microsoft\\\\\xamarin/news", UriKind.Relative, false)] + [TestCase(@"ht\\\.com", UriKind.RelativeOrAbsolute, false)] public async Task IsValid(string value, UriKind uriKind, bool expectedValue) { // Arrange @@ -41,7 +40,7 @@ public async Task IsValid(string value, UriKind uriKind, bool expectedValue) await behavior.ForceValidate(); // Assert - Assert.Equal(expectedValue, behavior.IsValid); + Assert.AreEqual(expectedValue, behavior.IsValid); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UserStoppedTypingBehavior_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UserStoppedTypingBehavior_Tests.cs index b8ddc0563..b7d91f471 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UserStoppedTypingBehavior_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UserStoppedTypingBehavior_Tests.cs @@ -2,7 +2,7 @@ using System.Windows.Input; using Xamarin.CommunityToolkit.Behaviors; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Behaviors { @@ -10,44 +10,45 @@ public class UserStoppedTypingBehavior_Tests { const int defaultTimeThreshold = 1000; const int defaultLengthThreshold = 0; + const int defaultTimeoutThreshold = defaultTimeThreshold * 2; - [Fact] + [Test] public async Task ShouldExecuteCommandWhenTimeThresholdHasExpired() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true)); + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true)); // act entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.True(commandHasBeenExecuted); + Assert.IsTrue(commandHasBeenExecuted); } - [Fact] + [Test] public async Task ShouldExecuteCommandWithSpecificParameterWhenSpecified() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true), + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true), commandParameter: true); // act entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.True(commandHasBeenExecuted); + Assert.IsTrue(commandHasBeenExecuted); } - [Fact] + [Test] public async Task ShouldNotExecuteCommandBeforeTimeThresholdHasExpired() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true)); + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true)); // act entry.Text = "1"; @@ -57,25 +58,25 @@ public async Task ShouldNotExecuteCommandBeforeTimeThresholdHasExpired() Assert.False(commandHasBeenExecuted); } - [Fact] + [Test] public async Task ShouldOnlyExectueCommandOnceWhenTextChangedHasOccurredMultipleTimes() { // arrange var timesExecuted = 0; - var entry = CreateEntryWithBehavior(command: new Command((s) => timesExecuted++)); + var entry = CreateEntryWithBehavior(command: new Command(_ => timesExecuted++)); // act entry.Text = "1"; entry.Text = "12"; entry.Text = "123"; entry.Text = "1234"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.Equal(1, timesExecuted); + Assert.AreEqual(1, timesExecuted); } - [Fact] + [Test] public async Task ShouldDismissKeyboardWhenTimeThresholdHasExpired() { // arrange @@ -85,47 +86,47 @@ public async Task ShouldDismissKeyboardWhenTimeThresholdHasExpired() entry.Focus(); entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert Assert.False(entry.IsFocused); } - [Fact] + [Test] public async Task ShouldExecuteCommandWhenMinimumLengthThreholdHasBeenReached() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true), + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true), lengthThreshold: 3); // act entry.Text = "1"; entry.Text = "12"; entry.Text = "123"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.True(commandHasBeenExecuted); + Assert.IsTrue(commandHasBeenExecuted); } - [Fact] + [Test] public async Task ShouldNotExecuteCommandWhenMinimumLengthThreholdHasNotBeenReached() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true), + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true), lengthThreshold: 2); // act entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert Assert.False(commandHasBeenExecuted); } - [Fact] + [Test] public async Task ShouldNotDismissKeyboardWhenMinimumLengthThreholdHasNotBeenReached() { // arrange @@ -136,25 +137,25 @@ public async Task ShouldNotDismissKeyboardWhenMinimumLengthThreholdHasNotBeenRea entry.Focus(); entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.True(entry.IsFocused); + Assert.IsTrue(entry.IsFocused); } - [Fact] + [Test] public async Task ShouldExecuteCommandImmediatelyWhenMinimumLengthThreholdHasNotBeenSet() { // arrange var commandHasBeenExecuted = false; - var entry = CreateEntryWithBehavior(command: new Command((s) => commandHasBeenExecuted = true)); + var entry = CreateEntryWithBehavior(command: new Command(_ => commandHasBeenExecuted = true)); // act entry.Text = "1"; - await Task.Delay(defaultTimeThreshold + 100); + await Task.Delay(defaultTimeoutThreshold); // assert - Assert.True(commandHasBeenExecuted); + Assert.IsTrue(commandHasBeenExecuted); } public Entry CreateEntryWithBehavior(int timeThreshold = defaultTimeThreshold, diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/BoolToObjectConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/BoolToObjectConverter_Tests.cs index 29d952be8..5a3c224e2 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/BoolToObjectConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/BoolToObjectConverter_Tests.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -10,9 +10,8 @@ public class BoolToObjectConverter_Tests public const string TrueTestObject = nameof(TrueTestObject); public const string FalseTestObject = nameof(FalseTestObject); - [Theory] - [InlineData(true, TrueTestObject, FalseTestObject, TrueTestObject)] - [InlineData(false, TrueTestObject, FalseTestObject, FalseTestObject)] + [TestCase(true, TrueTestObject, FalseTestObject, TrueTestObject)] + [TestCase(false, TrueTestObject, FalseTestObject, FalseTestObject)] public void BoolToObjectConvert(bool value, object trueObject, object falseObject, object expectedResult) { var boolObjectConverter = new BoolToObjectConverter(); @@ -21,12 +20,11 @@ public void BoolToObjectConvert(bool value, object trueObject, object falseObjec var result = boolObjectConverter.Convert(value, typeof(BoolToObjectConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(TrueTestObject, TrueTestObject, FalseTestObject, true)] - [InlineData(FalseTestObject, TrueTestObject, FalseTestObject, false)] + [TestCase(TrueTestObject, TrueTestObject, FalseTestObject, true)] + [TestCase(FalseTestObject, TrueTestObject, FalseTestObject, false)] public void BoolToObjectConvertBack(object value, object trueObject, object falseObject, bool expectedResult) { var boolObjectConverter = new BoolToObjectConverter(); @@ -35,11 +33,10 @@ public void BoolToObjectConvertBack(object value, object trueObject, object fals var result = boolObjectConverter.ConvertBack(value, typeof(BoolToObjectConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData("")] + [TestCase("")] public void BoolToObjectInValidValuesThrowArgumenException(object value) { var boolObjectConverter = new BoolToObjectConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ByteArrayToImageSourceConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ByteArrayToImageSourceConverter_Tests.cs index 83be6ff6d..e2b3a54d8 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ByteArrayToImageSourceConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ByteArrayToImageSourceConverter_Tests.cs @@ -3,13 +3,13 @@ using System.IO; using Xamarin.CommunityToolkit.Converters; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class ByteArrayToImageSourceConverter_Tests { - [Fact] + [Test] public void ByteArrayToImageSourceConverter() { var byteArray = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; @@ -22,11 +22,11 @@ public void ByteArrayToImageSourceConverter() var result = byteArrayToImageSourceConverter.Convert(byteArray, typeof(ByteArrayToImageSourceConverter), null, CultureInfo.CurrentCulture); - Assert.True(StreamEquals(GetStreamFromImageSource((ImageSource?)result), memoryStream)); + Assert.IsTrue(StreamEquals(GetStreamFromImageSource((ImageSource?)result), memoryStream)); } - [Theory] - [InlineData("Random String Value")] + + [TestCase("Random String Value")] public void InvalidConverterValuesReturnsNull(object value) { var byteArrayToImageSourceConverter = new ByteArrayToImageSourceConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DateTimeOffsetConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DateTimeOffsetConverter_Tests.cs index 27df80bd6..7a9ef254b 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DateTimeOffsetConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DateTimeOffsetConverter_Tests.cs @@ -2,24 +2,25 @@ using System.Collections.Generic; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class DateTimeOffsetConverter_Tests { - static DateTime testDateTimeNow = DateTime.Now; - static DateTime testDateTimeLocal = new DateTime(2020, 08, 25, 13, 37, 00, DateTimeKind.Local); - static DateTime testDateTimeUtc = new DateTime(2020, 08, 25, 13, 37, 00, DateTimeKind.Utc); - static DateTime testDateTimeUnspecified = new DateTime(2020, 08, 25, 13, 37, 00); - static DateTimeOffset testDateTimeOffsetNow = new DateTimeOffset(testDateTimeNow); - static DateTimeOffset testDateTimeOffsetLocal = new DateTimeOffset(2020, 08, 25, 13, 37, 00, DateTimeOffset.Now.Offset); - static DateTimeOffset testDateTimeOffsetUtc = new DateTimeOffset(2020, 08, 25, 13, 37, 00, DateTimeOffset.UtcNow.Offset); + static readonly DateTime testDateTimeNow = DateTime.Now; + static readonly DateTime testDateTimeLocal = new DateTime(2020, 08, 25, 13, 37, 00, DateTimeKind.Local); + static readonly DateTime testDateTimeUtc = new DateTime(2020, 08, 25, 13, 37, 00, DateTimeKind.Utc); + static readonly DateTime testDateTimeUnspecified = new DateTime(2020, 08, 25, 13, 37, 00); + + static readonly DateTimeOffset testDateTimeOffsetNow = new DateTimeOffset(testDateTimeNow); + static readonly DateTimeOffset testDateTimeOffsetLocal = new DateTimeOffset(2020, 08, 25, 13, 37, 00, DateTimeOffset.Now.Offset); + static readonly DateTimeOffset testDateTimeOffsetUtc = new DateTimeOffset(2020, 08, 25, 13, 37, 00, DateTimeOffset.UtcNow.Offset); public static IEnumerable GetData() => new List { - new object[] { testDateTimeNow, testDateTimeNow }, + new object[] { testDateTimeOffsetNow, testDateTimeNow }, new object[] { DateTimeOffset.MinValue, DateTime.MinValue }, new object[] { DateTimeOffset.MaxValue, DateTime.MaxValue }, new object[] { testDateTimeOffsetLocal, testDateTimeLocal }, @@ -30,7 +31,7 @@ public class DateTimeOffsetConverter_Tests public static IEnumerable GetDataReverse() => new List { - new object[] { testDateTimeNow, testDateTimeNow }, + new object[] { testDateTimeNow, testDateTimeOffsetNow }, new object[] { DateTime.MinValue, DateTimeOffset.MinValue }, new object[] { DateTime.MaxValue, DateTimeOffset.MaxValue }, new object[] { testDateTimeLocal, testDateTimeOffsetLocal }, @@ -38,8 +39,7 @@ public class DateTimeOffsetConverter_Tests new object[] { testDateTimeUnspecified, testDateTimeOffsetUtc }, }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void DateTimeOffsetConverter(DateTimeOffset value, DateTime expectedResult) { var dateTimeOffsetConverter = new DateTimeOffsetConverter(); @@ -47,11 +47,10 @@ public void DateTimeOffsetConverter(DateTimeOffset value, DateTime expectedResul var result = dateTimeOffsetConverter.Convert(value, typeof(DateTimeOffsetConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(expectedResult, result); + Assert.AreEqual(expectedResult, result); } - [Theory] - [MemberData(nameof(GetDataReverse))] + [TestCaseSource(nameof(GetDataReverse))] public void DateTimeOffsetConverterBack(DateTime value, DateTimeOffset expectedResult) { var dateTimeOffsetConverter = new DateTimeOffsetConverter(); @@ -59,10 +58,10 @@ public void DateTimeOffsetConverterBack(DateTime value, DateTimeOffset expectedR var result = dateTimeOffsetConverter.ConvertBack(value, typeof(DateTimeOffsetConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(expectedResult, result); + Assert.AreEqual(expectedResult, result); } - [Fact] + [Test] public void DateTimeOffsetConverter_GivenInvalidParameters_ThrowsException() { var dateTimeOffsetConverter = new DateTimeOffsetConverter(); @@ -72,7 +71,7 @@ public void DateTimeOffsetConverter_GivenInvalidParameters_ThrowsException() CultureInfo.CurrentCulture)); } - [Fact] + [Test] public void DateTimeOffsetConverterBack_GivenInvalidParameters_ThrowsException() { var dateTimeOffsetConverter = new DateTimeOffsetConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DoubleToIntConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DoubleToIntConverter_Tests.cs index 4462a3cea..f8811bfb8 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DoubleToIntConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/DoubleToIntConverter_Tests.cs @@ -1,39 +1,36 @@ using System; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class DoubleToIntConverter_Tests { - [Theory] - [InlineData(2.5, 2)] - [InlineData(2.55, 3)] - [InlineData(2.555, 3)] - [InlineData(2.555, 652, 255)] + [TestCase(2.5, 2)] + [TestCase(2.55, 3)] + [TestCase(2.555, 3)] + [TestCase(2.555, 652, 255)] public void DoubleToIntConverter(double value, int expectedResult, object? ratio = null) { var doubleToIntConverter = new DoubleToIntConverter(); var result = doubleToIntConverter.Convert(value, typeof(DoubleToIntConverter_Tests), ratio, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(2, 2)] + [TestCase(2, 2)] public void DoubleToIntConverterBack(int value, double expectedResult, object? ratio = null) { var doubleToIntConverter = new DoubleToIntConverter(); var result = doubleToIntConverter.ConvertBack(value, typeof(DoubleToIntConverter_Tests), ratio, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData("")] + [TestCase("")] public void DoubleToIntInValidValuesThrowArgumenException(object value) { var doubleToIntConverter = new DoubleToIntConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EnumToBoolConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EnumToBoolConverter_Tests.cs index 30780f511..5044ea02b 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EnumToBoolConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EnumToBoolConverter_Tests.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.Linq; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -30,35 +30,32 @@ public enum TestFlaggedEnumForEnumToBoolConverter public class EnumToBoolConverter_Tests { - [Fact] + [Test] public void EnumToBoolConvertBack_ThrowsNotImplementedException() { var enumToBoolConverter = new EnumToBoolConverter(); Assert.Throws(() => - enumToBoolConverter.ConvertBack(TestEnumForEnumToBoolConverter.Five, typeof(bool), null, - CultureInfo.InvariantCulture)); + enumToBoolConverter.ConvertBack(TestEnumForEnumToBoolConverter.Five, typeof(bool), null, CultureInfo.InvariantCulture)); } - [Theory] - [InlineData("a string")] - [InlineData(42)] - [InlineData(null)] - [InlineData(false)] + [TestCase("a string")] + [TestCase(42)] + [TestCase(null)] + [TestCase(false)] public void EnumToBoolConvert_ValueNotEnum_ThrowsArgumentException(object value) { var enumToBoolConverter = new EnumToBoolConverter(); - Assert.Throws("value", () => enumToBoolConverter.Convert(value, typeof(bool), - TestEnumForEnumToBoolConverter.Five, CultureInfo.InvariantCulture)); + Assert.Throws(() => + enumToBoolConverter.Convert(value, typeof(bool), TestEnumForEnumToBoolConverter.Five, CultureInfo.InvariantCulture)); } - [Theory] - [InlineData("a string")] - [InlineData(42)] - [InlineData(null)] - [InlineData(false)] - [InlineData(TestFlaggedEnumForEnumToBoolConverter.Four)] + [TestCase("a string")] + [TestCase(42)] + [TestCase(null)] + [TestCase(false)] + [TestCase(TestFlaggedEnumForEnumToBoolConverter.Four)] public void EnumToBoolConvert_ParameterNotSameEnum_ReturnsFalse(object parameter) { var enumToBoolConverter = new EnumToBoolConverter(); @@ -68,83 +65,28 @@ public void EnumToBoolConvert_ParameterNotSameEnum_ReturnsFalse(object parameter Assert.False(result as bool?); } - [Theory] - [MemberData(nameof(ConvertTestData))] - public void EnumToBoolConvert_Validation(object[] trueValues, object value, object parameter, - bool expectedResult) + [TestCase(null, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Five, true)] + [TestCase(null, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six, false)] + [TestCase(new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six, true)] + [TestCase(new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Six, null, true)] + [TestCase(new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.One, TestEnumForEnumToBoolConverter.Five, false)] + [TestCase(new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Two, null, false)] + [TestCase(new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.One, null, true)] + [TestCase(new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Two, null, true)] + [TestCase(new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Three, null, true)] + [TestCase(new object?[] { TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Four, null, false)] + [TestCase(null, TestFlaggedEnumForEnumToBoolConverter.One, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, true)] + [TestCase(null, TestFlaggedEnumForEnumToBoolConverter.Three, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, true)] + [TestCase(null, TestFlaggedEnumForEnumToBoolConverter.Two, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, false)] + [TestCase(null, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, true)] + [TestCase(null, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Two | TestFlaggedEnumForEnumToBoolConverter.Three, TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three, false)] + public void EnumToBoolConvert_Validation(object?[]? trueValues, object? value, object parameter, bool expectedResult) { var enumToBoolConverter = new EnumToBoolConverter(); trueValues?.OfType().ToList().ForEach(fe => enumToBoolConverter.TrueValues.Add(fe)); var result = enumToBoolConverter.Convert(value, typeof(bool), parameter, CultureInfo.InvariantCulture); - Assert.Equal(expectedResult, result); - } - - public static IEnumerable ConvertTestData() - { - // Simple enum - yield return new object?[] - { - null, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Five, true - }; - yield return new object?[] - { - null, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six, false - }; - yield return new object?[] - { - new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six, true - }; - yield return new object?[] - { - new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Six, null, true - }; - yield return new object?[] - { - new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.One, TestEnumForEnumToBoolConverter.Five, false - }; - yield return new object?[] - { - new object?[] { TestEnumForEnumToBoolConverter.Five, TestEnumForEnumToBoolConverter.Six }, TestEnumForEnumToBoolConverter.Two, null, false - }; - - // Flagged enum - yield return new object?[] - { - new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.One, null, true - }; - yield return new object?[] - { - new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Two, null, true - }; - yield return new object?[] - { - new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Three, null, true - }; - yield return new object?[] - { - new object?[] { (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), TestFlaggedEnumForEnumToBoolConverter.Two }, TestFlaggedEnumForEnumToBoolConverter.Four, null, false - }; - yield return new object?[] - { - null, TestFlaggedEnumForEnumToBoolConverter.One, (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), true - }; - yield return new object?[] - { - null, TestFlaggedEnumForEnumToBoolConverter.Three, (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), true - }; - yield return new object?[] - { - null, TestFlaggedEnumForEnumToBoolConverter.Two, (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), false - }; - yield return new object?[] - { - null, (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), true - }; - yield return new object?[] - { - null, (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Two | TestFlaggedEnumForEnumToBoolConverter.Three), (TestFlaggedEnumForEnumToBoolConverter.One | TestFlaggedEnumForEnumToBoolConverter.Three), false - }; + Assert.AreEqual(expectedResult, result); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EqualConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EqualConverter_Tests.cs index d82c2013c..b90f98d58 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EqualConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/EqualConverter_Tests.cs @@ -1,6 +1,6 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -8,29 +8,27 @@ public class EqualConverter_Tests { public const string TestValue = nameof(TestValue); - [Theory] - [InlineData(200, 200)] - [InlineData(TestValue, TestValue)] + [TestCase(200, 200)] + [TestCase(TestValue, TestValue)] public void IsEqual(object value, object comparedValue) { var equalConverter = new EqualConverter(); var result = equalConverter.Convert(value, typeof(EqualConverter_Tests), comparedValue, CultureInfo.CurrentCulture); - Assert.IsType(result); - Assert.True((bool)result); + Assert.IsInstanceOf(result); + Assert.IsTrue((bool)result); } - [Theory] - [InlineData(200, 400)] - [InlineData(TestValue, "")] + [TestCase(200, 400)] + [TestCase(TestValue, "")] public void IsNotEqual(object value, object comparedValue) { var equalConverter = new EqualConverter(); var result = equalConverter.Convert(value, typeof(EqualConverter_Tests), comparedValue, CultureInfo.CurrentCulture); - Assert.IsType(result); + Assert.IsInstanceOf(result); Assert.False((bool)result); } } diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IndexToArrayItemConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IndexToArrayItemConverter_Tests.cs index 66468f228..24d25a3a8 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IndexToArrayItemConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IndexToArrayItemConverter_Tests.cs @@ -1,37 +1,34 @@ using System; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class IndexToArrayItemConverter_Tests { - [Theory] - [InlineData(new int[] { 1, 2, 3, 4, 5 }, 2, 3)] - [InlineData(new string[] { "Val1", "Val2", "Val3" }, 0, "Val1")] - [InlineData(new double[] { 1.3, 4.3, 4.3 }, 1, 4.3)] + [TestCase(new int[] { 1, 2, 3, 4, 5 }, 2, 3)] + [TestCase(new string[] { "Val1", "Val2", "Val3" }, 0, "Val1")] + [TestCase(new double[] { 1.3, 4.3, 4.3 }, 1, 4.3)] public void IndexToArrayConverter(Array value, int position, object expectedResult) { var indexToArrayConverter = new IndexToArrayItemConverter(); var result = indexToArrayConverter.Convert(position, typeof(IndexToArrayItemConverter_Tests), value, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(null, null)] - [InlineData(null, 100)] + [TestCase(null, null)] + [TestCase(null, 100)] public void IndexToArrayInValidValuesThrowArgumenException(object value, object position) { var indexToArrayConverter = new IndexToArrayItemConverter(); Assert.Throws(() => indexToArrayConverter.Convert(position, typeof(IndexToArrayItemConverter), value, CultureInfo.CurrentCulture)); } - [Theory] - [InlineData(new int[] { 1, 2, 3, 4, 5 }, 100)] - [InlineData(new int[] { 1, 2, 3, 4, 5 }, -1)] + [TestCase(new int[] { 1, 2, 3, 4, 5 }, 100)] + [TestCase(new int[] { 1, 2, 3, 4, 5 }, -1)] public void IndexToArrayInValidValuesThrowArgumenOutOfRangeException(object value, object position) { var indexToArrayConverter = new IndexToArrayItemConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IntToBoolConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IntToBoolConverter_Tests.cs index 50c6e3e2b..8158f03a4 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IntToBoolConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IntToBoolConverter_Tests.cs @@ -1,50 +1,46 @@ using System; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class IntToBoolConverter_Tests { - [Theory] - [InlineData(1, true)] - [InlineData(0, false)] + [TestCase(1, true)] + [TestCase(0, false)] public void IndexToArrayConverter(int value, bool expectedResult) { var intToBoolConverter = new IntToBoolConverter(); var result = intToBoolConverter.Convert(value, typeof(IntToBoolConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(true, 1)] - [InlineData(false, 0)] + [TestCase(true, 1)] + [TestCase(false, 0)] public void IndexToArrayConverterBack(bool value, int expectedResult) { var intToBoolConverter = new IntToBoolConverter(); var result = intToBoolConverter.ConvertBack(value, typeof(IntToBoolConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(2.5)] - [InlineData("")] - [InlineData(null)] + [TestCase(2.5)] + [TestCase("")] + [TestCase(null)] public void InValidConverterValuesThrowArgumenException(object value) { var intToBoolConverter = new IntToBoolConverter(); Assert.Throws(() => intToBoolConverter.Convert(value, typeof(IndexToArrayItemConverter), null, CultureInfo.CurrentCulture)); } - [Theory] - [InlineData(2.5)] - [InlineData("")] - [InlineData(null)] + [TestCase(2.5)] + [TestCase("")] + [TestCase(null)] public void InValidConverterBackValuesThrowArgumenException(object value) { var intToBoolConverter = new IntToBoolConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/InvertedBoolConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/InvertedBoolConverter_Tests.cs index 552392a10..d599751a8 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/InvertedBoolConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/InvertedBoolConverter_Tests.cs @@ -1,28 +1,26 @@ using System; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class InvertedBoolConverter_Tests { - [Theory] - [InlineData(true, false)] - [InlineData(false, true)] + [TestCase(true, false)] + [TestCase(false, true)] public void InverterBoolConverter(bool value, bool expectedResult) { var inverterBoolConverter = new InvertedBoolConverter(); var result = inverterBoolConverter.Convert(value, typeof(InvertedBoolConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(2)] - [InlineData("")] - [InlineData(null)] + [TestCase(2)] + [TestCase("")] + [TestCase(null)] public void InValidConverterValuesThrowArgumenException(object value) { var inverterBoolConverter = new InvertedBoolConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs index d45e29aa6..d7fff526d 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs @@ -1,23 +1,22 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class IsNotNullOrEmptyConverter_Tests { - [Theory] - [InlineData("Test", true)] - [InlineData(typeof(IsNotNullOrEmptyConverter), true)] - [InlineData(null, false)] - [InlineData("", false)] + [TestCase("Test", true)] + [TestCase(typeof(IsNotNullOrEmptyConverter), true)] + [TestCase(null, false)] + [TestCase("", false)] public void IsNotNullOrEmptyConverter(object value, bool expectedResult) { var isNotNullOrEmptyConverter = new IsNotNullOrEmptyConverter(); var result = isNotNullOrEmptyConverter.Convert(value, typeof(IsNotNullOrEmptyConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs index 662b4c7ab..2c51f8768 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs @@ -1,23 +1,22 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class IsNullOrEmptyConverter_Tests { - [Theory] - [InlineData(null, true)] - [InlineData("", true)] - [InlineData("Test", false)] - [InlineData(typeof(IsNullOrEmptyConverter), false)] + [TestCase(null, true)] + [TestCase("", true)] + [TestCase("Test", false)] + [TestCase(typeof(IsNullOrEmptyConverter), false)] public void IsNullOrEmptyConverter(object value, bool expectedResult) { var isNullOrEmptyConverter = new IsNullOrEmptyConverter(); var result = isNullOrEmptyConverter.Convert(value, typeof(IsNotNullOrEmptyConverter_Tests), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemSelectedEventArgsConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemSelectedEventArgsConverter_Tests.cs index 28aaaa68d..8ed7c3192 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemSelectedEventArgsConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemSelectedEventArgsConverter_Tests.cs @@ -3,7 +3,7 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -16,22 +16,20 @@ public class ItemSelectedEventArgsConverter_Tests // We know it's deprecated, still good to test it #pragma warning disable CS0618 // Type or member is obsolete new object[] { new SelectedItemChangedEventArgs(expectedValue), expectedValue }, - new object?[] { null, null }, + new object?[] { null, null }, #pragma warning restore CS0618 // Type or member is obsolete }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void ItemSelectedEventArgsConverter(SelectedItemChangedEventArgs value, object expectedResult) { var itemSelectedEventArgsConverter = new ItemSelectedEventArgsConverter(); var result = itemSelectedEventArgsConverter.Convert(value, typeof(ItemSelectedEventArgsConverter), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData("Random String")] + [TestCase("Random String")] public void InvalidConverterValuesThrowsArgumenException(object value) { var itemSelectedEventArgsConverter = new ItemSelectedEventArgsConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemTappedEventArgsConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemTappedEventArgsConverter_Tests.cs index 23abe0864..7c8008042 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemTappedEventArgsConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemTappedEventArgsConverter_Tests.cs @@ -3,7 +3,7 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -20,19 +20,17 @@ public class ItemTappedEventArgsConverter_Tests #pragma warning restore CS0618 // Type or member is obsolete }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void ItemTappedEventArgsConverter(ItemTappedEventArgs value, object expectedResult) { var itemTappedEventArgsConverter = new ItemTappedEventArgsConverter(); var result = itemTappedEventArgsConverter.Convert(value, typeof(ItemTappedEventArgsConverter), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData("Random String")] + [TestCase("Random String")] public void InValidConverterValuesThrowArgumenException(object value) { var itemTappedEventArgsConverter = new ItemTappedEventArgsConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNotNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNotNullOrEmptyConverter_Tests.cs index 5a7e534da..f2217796d 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNotNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNotNullOrEmptyConverter_Tests.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.Linq; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -17,19 +17,17 @@ public class ListIsNotNullOrEmptyConverter_Tests new object[] { Enumerable.Range(1, 3), true }, }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void ListIsNotNullOrEmptyConverter(object value, bool expectedResult) { var listIsNotNullOrEmptyConverter = new ListIsNotNullOrEmptyConverter(); var result = listIsNotNullOrEmptyConverter.Convert(value, typeof(ListIsNotNullOrEmptyConverter), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(0)] + [TestCase(0)] public void InValidConverterValuesThrowArgumenException(object value) { var listIsNotNullOrEmptyConverter = new ListIsNotNullOrEmptyConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNullOrEmptyConverter_Tests.cs index 67be9dfd8..3762ebc29 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListIsNullOrEmptyConverter_Tests.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.Linq; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -17,19 +17,17 @@ public class ListIsNullOrEmptyConverter_Tests new object[] { Enumerable.Range(1, 3), false }, }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void ListIsNullOrEmptyConverter(object value, bool expectedResult) { var listIstNullOrEmptyConverter = new ListIsNullOrEmptyConverter(); var result = listIstNullOrEmptyConverter.Convert(value, typeof(ListIsNullOrEmptyConverter), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(0)] + [TestCase(0)] public void InValidConverterValuesThrowArgumenException(object value) { var listIstNullOrEmptyConverter = new ListIsNullOrEmptyConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListToStringConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListToStringConverter_Tests.cs index 6580d9f35..2779ac09d 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListToStringConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ListToStringConverter_Tests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -18,19 +18,17 @@ public class ListToStringConverter_Tests new object?[] { new string[] { "A", "B", "C" }, null, "ABC" }, }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void ListToStringConverter(object value, object parameter, object expectedResult) { var listToStringConverter = new ListToStringConverter(); var result = listToStringConverter.Convert(value, null, parameter, null); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [InlineData(0)] + [TestCase(0)] public void InValidConverterValuesThrowArgumenException(object value) { var listToStringConverter = new ListToStringConverter(); @@ -38,8 +36,7 @@ public void InValidConverterValuesThrowArgumenException(object value) Assert.Throws(() => listToStringConverter.Convert(value, null, null, null)); } - [Theory] - [InlineData(0)] + [TestCase(0)] public void InValidConverterParametersThrowArgumenException(object parameter) { var listToStringConverter = new ListToStringConverter(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/MultiConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/MultiConverter_Tests.cs index 5595109f8..78bdb4971 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/MultiConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/MultiConverter_Tests.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -12,15 +12,14 @@ public class MultiConverter_Tests new object[] { new List() { { new MultiConverterParameter() { Value = "Param 1", } }, { new MultiConverterParameter() { Value = "Param 2", } } } }, }; - [Theory] - [MemberData(nameof(GetData))] + [TestCaseSource(nameof(GetData))] public void MultiConverter(object value) { var multiConverter = new MultiConverter(); var result = multiConverter.Convert(value, typeof(MultiConverter), null, CultureInfo.CurrentCulture); - Assert.Equal(result, value); + Assert.AreEqual(result, value); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/NotEqualConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/NotEqualConverter_Tests.cs index 5d9abe64d..0faad61c4 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/NotEqualConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/NotEqualConverter_Tests.cs @@ -1,23 +1,22 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class NotEqualConverter_Tests { - [Theory] - [InlineData(true, true, false)] - [InlineData(int.MaxValue, int.MinValue, true)] - [InlineData("Test", true, true)] - [InlineData(null, null, false)] + [TestCase(true, true, false)] + [TestCase(int.MaxValue, int.MinValue, true)] + [TestCase("Test", true, true)] + [TestCase(null, null, false)] public void NotEqualConverter(object value, object comparedValue, bool expectedResult) { var notEqualConverter = new NotEqualConverter(); var result = notEqualConverter.Convert(value, typeof(NotEqualConverter_Tests), comparedValue, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/TextCaseConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/TextCaseConverter_Tests.cs index e05912354..d22cd6785 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/TextCaseConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/TextCaseConverter_Tests.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Globalization; +using NUnit.Framework; using Xamarin.CommunityToolkit.Converters; using Xamarin.CommunityToolkit.UnitTests.Mocks; -using Xunit; namespace Xamarin.CommunityToolkit.UnitTests.Converters { @@ -12,40 +11,36 @@ public class TextCaseConverter_Tests const string test = nameof(test); const string t = nameof(t); - static IEnumerable GetTestData() + static IEnumerable GetTestData() { - yield return new object[] { test, TextCaseType.Lower, test }; - yield return new object[] { test, TextCaseType.Upper, "TEST" }; - yield return new object[] { test, TextCaseType.None, test }; - yield return new object[] { test, TextCaseType.FirstUpperRestLower, "Test" }; - yield return new object[] { t, TextCaseType.Upper, "T" }; - yield return new object[] { t, TextCaseType.Lower, t }; - yield return new object[] { t, TextCaseType.None, t }; - yield return new object[] { t, TextCaseType.FirstUpperRestLower, "T" }; - yield return new object[] { string.Empty, TextCaseType.FirstUpperRestLower, string.Empty }; -#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - yield return new object[] { null, TextCaseType.None, null }; -#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. - yield return new object[] { MockEnum.Foo, TextCaseType.Lower, "foo" }; - yield return new object[] { MockEnum.Bar, TextCaseType.None, "Bar" }; - yield return new object[] { MockEnum.Baz, TextCaseType.Upper, "BAZ" }; - yield return new object[] { new MockItem { Title = "Test Item", Completed = true }, TextCaseType.Upper, "TEST ITEM IS COMPLETED" }; + yield return new object?[] { test, TextCaseType.Lower, test }; + yield return new object?[] { test, TextCaseType.Upper, "TEST" }; + yield return new object?[] { test, TextCaseType.None, test }; + yield return new object?[] { test, TextCaseType.FirstUpperRestLower, "Test" }; + yield return new object?[] { t, TextCaseType.Upper, "T" }; + yield return new object?[] { t, TextCaseType.Lower, t }; + yield return new object?[] { t, TextCaseType.None, t }; + yield return new object?[] { t, TextCaseType.FirstUpperRestLower, "T" }; + yield return new object?[] { string.Empty, TextCaseType.FirstUpperRestLower, string.Empty }; + yield return new object?[] { null, TextCaseType.None, null }; + yield return new object?[] { MockEnum.Foo, TextCaseType.Lower, "foo" }; + yield return new object?[] { MockEnum.Bar, TextCaseType.None, "Bar" }; + yield return new object?[] { MockEnum.Baz, TextCaseType.Upper, "BAZ" }; + yield return new object?[] { new MockItem { Title = "Test Item", Completed = true }, TextCaseType.Upper, "TEST ITEM IS COMPLETED" }; } - [Theory] - [MemberData(nameof(GetTestData))] - [InlineData(null, null, null)] + [TestCaseSource(nameof(GetTestData))] + [TestCase(null, null, null)] public void TextCaseConverterWithParameter(object? value, object? comparedValue, object? expectedResult) { var textCaseConverter = new TextCaseConverter(); var result = textCaseConverter.Convert(value, typeof(string), comparedValue, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } - [Theory] - [MemberData(nameof(GetTestData))] + [TestCaseSource(nameof(GetTestData))] public void TextCaseConverterWithExplicitType(object? value, TextCaseType textCaseType, object? expectedResult) { var textCaseConverter = new TextCaseConverter @@ -55,7 +50,7 @@ public void TextCaseConverterWithExplicitType(object? value, TextCaseType textCa var result = textCaseConverter.Convert(value, typeof(string), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/VariableMultiValueConverter_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/VariableMultiValueConverter_Tests.cs index ff91f159a..6ae3613b4 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/VariableMultiValueConverter_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/VariableMultiValueConverter_Tests.cs @@ -1,42 +1,41 @@ using System.Globalization; using Xamarin.CommunityToolkit.Converters; using Xamarin.CommunityToolkit.Helpers; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Converters { public class VariableMultiValueConverter_Tests { - [Theory] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.None, false)] - [InlineData(new object[] { true, false, true }, MultiBindingCondition.None, false)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.None, true)] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.All, true)] - [InlineData(new object[] { true, false, true }, MultiBindingCondition.All, false)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.All, false)] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.Any, true)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.Any, false)] - [InlineData(new object[] { false, true, false }, MultiBindingCondition.Any, true)] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.Exact, true, 3)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.Exact, false, 1)] - [InlineData(new object[] { false, true, false }, MultiBindingCondition.Exact, true, 1)] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.GreaterThan, true, 2)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.GreaterThan, false, 1)] - [InlineData(new object[] { false, true, false }, MultiBindingCondition.GreaterThan, true, 0)] - [InlineData(new object[] { true, true, true }, MultiBindingCondition.LessThan, false, 2)] - [InlineData(new object[] { false, false, false }, MultiBindingCondition.LessThan, true, 1)] - [InlineData(new object[] { false, true, false }, MultiBindingCondition.LessThan, true, 2)] - [InlineData(null, MultiBindingCondition.All, false)] - [InlineData(null, MultiBindingCondition.Any, false)] - [InlineData(null, MultiBindingCondition.Exact, false)] - [InlineData(null, MultiBindingCondition.GreaterThan, false)] - [InlineData(null, MultiBindingCondition.LessThan, false)] - [InlineData(null, MultiBindingCondition.None, false)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.None, false)] + [TestCase(new object[] { true, false, true }, MultiBindingCondition.None, false)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.None, true)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.All, true)] + [TestCase(new object[] { true, false, true }, MultiBindingCondition.All, false)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.All, false)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.Any, true)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.Any, false)] + [TestCase(new object[] { false, true, false }, MultiBindingCondition.Any, true)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.Exact, true, 3)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.Exact, false, 1)] + [TestCase(new object[] { false, true, false }, MultiBindingCondition.Exact, true, 1)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.GreaterThan, true, 2)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.GreaterThan, false, 1)] + [TestCase(new object[] { false, true, false }, MultiBindingCondition.GreaterThan, true, 0)] + [TestCase(new object[] { true, true, true }, MultiBindingCondition.LessThan, false, 2)] + [TestCase(new object[] { false, false, false }, MultiBindingCondition.LessThan, true, 1)] + [TestCase(new object[] { false, true, false }, MultiBindingCondition.LessThan, true, 2)] + [TestCase(null, MultiBindingCondition.All, false)] + [TestCase(null, MultiBindingCondition.Any, false)] + [TestCase(null, MultiBindingCondition.Exact, false)] + [TestCase(null, MultiBindingCondition.GreaterThan, false)] + [TestCase(null, MultiBindingCondition.LessThan, false)] + [TestCase(null, MultiBindingCondition.None, false)] public void VariableMultiConverter(object[] value, MultiBindingCondition type, object expectedResult, int count = 0) { var variableMultiConverter = new VariableMultiValueConverter() { ConditionType = type, Count = count }; var result = variableMultiConverter.Convert(value, typeof(bool), null, CultureInfo.CurrentCulture); - Assert.Equal(result, expectedResult); + Assert.AreEqual(result, expectedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizationResourceManagerTests/LocalizationResourceManagerTests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizationResourceManagerTests/LocalizationResourceManagerTests.cs index 950c5330d..c49020b27 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizationResourceManagerTests/LocalizationResourceManagerTests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizationResourceManagerTests/LocalizationResourceManagerTests.cs @@ -2,26 +2,34 @@ using System.Resources; using Xamarin.CommunityToolkit.Helpers; using Xamarin.CommunityToolkit.UnitTests.Mocks; -using Xunit; +using NUnit.Framework; +using System; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.LocalizationResourceManagerTests { - [Collection(nameof(LocalizationResourceManager))] + [NonParallelizable] public class LocalizationResourceManagerTests { - public LocalizationResourceManagerTests() + ResourceManager? resourceManager; + CultureInfo? initialCulture; + LocalizationResourceManager? localizationManager; + + [SetUp] + public void Setup() { resourceManager = new MockResourceManager(); + initialCulture = CultureInfo.InvariantCulture; + localizationManager = LocalizationResourceManager.Current; + localizationManager.Init(resourceManager, initialCulture); } - readonly LocalizationResourceManager localizationManager = LocalizationResourceManager.Current; - readonly CultureInfo initialCulture = CultureInfo.InvariantCulture; - readonly ResourceManager resourceManager; - - [Fact] + [Test] public void LocalizationResourceManager_GetCulture_Equal_Indexer() { + _ = localizationManager ?? throw new NullReferenceException(); + _ = resourceManager ?? throw new NullReferenceException(); + // Arrange var testString = "test"; var culture2 = new CultureInfo("en"); @@ -30,33 +38,38 @@ public void LocalizationResourceManager_GetCulture_Equal_Indexer() var responceIndexerCulture1 = localizationManager[testString]; var responceGetValueCulture1 = localizationManager.GetValue(testString); var responceResourceManagerCulture1 = resourceManager.GetString(testString, initialCulture); + localizationManager.CurrentCulture = culture2; var responceIndexerCulture2 = localizationManager[testString]; var responceGetValueCulture2 = localizationManager.GetValue(testString); var responceResourceManagerCulture2 = resourceManager.GetString(testString, culture2); // Assert - Assert.Equal(responceResourceManagerCulture1, responceIndexerCulture1); - Assert.Equal(responceResourceManagerCulture1, responceGetValueCulture1); - Assert.Equal(responceResourceManagerCulture2, responceIndexerCulture2); - Assert.Equal(responceResourceManagerCulture2, responceGetValueCulture2); + Assert.AreEqual(responceResourceManagerCulture1, responceIndexerCulture1); + Assert.AreEqual(responceResourceManagerCulture1, responceGetValueCulture1); + Assert.AreEqual(responceResourceManagerCulture2, responceIndexerCulture2); + Assert.AreEqual(responceResourceManagerCulture2, responceGetValueCulture2); } - [Fact] + [Test] public void LocalizationResourceManager_PropertyChanged_Triggered() { + _ = initialCulture ?? throw new NullReferenceException(); + _ = resourceManager ?? throw new NullReferenceException(); + _ = localizationManager ?? throw new NullReferenceException(); + // Arrange var culture2 = new CultureInfo("en"); - localizationManager.CurrentCulture = culture2; CultureInfo? changedCulture = null; + localizationManager.CurrentCulture = culture2; localizationManager.PropertyChanged += (s, e) => changedCulture = localizationManager.CurrentCulture; // Act, Assert localizationManager.Init(resourceManager, initialCulture); - Assert.Equal(initialCulture, changedCulture); + Assert.AreEqual(initialCulture, changedCulture); localizationManager.CurrentCulture = culture2; - Assert.Equal(culture2, changedCulture); + Assert.AreEqual(culture2, changedCulture); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizedStringTests/LocalizedStringTests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizedStringTests/LocalizedStringTests.cs index c97fa460b..fd6038010 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizedStringTests/LocalizedStringTests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizedStringTests/LocalizedStringTests.cs @@ -3,28 +3,36 @@ using System.Resources; using Xamarin.CommunityToolkit.Helpers; using Xamarin.CommunityToolkit.UnitTests.Mocks; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.LocalizedStringTests { - [Collection(nameof(LocalizationResourceManager))] + [NonParallelizable] public class LocalizedStringTests { - public LocalizedStringTests() + CultureInfo? initialCulture; + ResourceManager? resourceManager; + LocalizationResourceManager? localizationManager; + + LocalizedString? localizedString; + + [SetUp] + public void Setup() { resourceManager = new MockResourceManager(); + initialCulture = CultureInfo.InvariantCulture; + localizationManager = LocalizationResourceManager.Current; + localizationManager.Init(resourceManager, initialCulture); } - readonly LocalizationResourceManager localizationManager = LocalizationResourceManager.Current; - readonly CultureInfo initialCulture = CultureInfo.InvariantCulture; - readonly ResourceManager resourceManager; - - LocalizedString? localizedString; - - [Fact] + [Test] public void LocalizedStringTests_Localized_ValidImplementation() { + _ = initialCulture ?? throw new NullReferenceException(); + _ = resourceManager ?? throw new NullReferenceException(); + _ = localizationManager ?? throw new NullReferenceException(); + // Arrange var testString = "test"; var culture2 = new CultureInfo("en"); @@ -41,12 +49,12 @@ public void LocalizedStringTests_Localized_ValidImplementation() var responceResourceManagerCulture2 = resourceManager.GetString(testString, culture2); // Assert - Assert.Equal(responceResourceManagerCulture1, responceCulture1); - Assert.Equal(responceResourceManagerCulture2, responceOnCultureChanged); - Assert.Equal(responceResourceManagerCulture2, responceResourceManagerCulture2); + Assert.AreEqual(responceResourceManagerCulture1, responceCulture1); + Assert.AreEqual(responceResourceManagerCulture2, responceOnCultureChanged); + Assert.AreEqual(responceResourceManagerCulture2, responceResourceManagerCulture2); } - [Fact] + [Test] public void LocalizedStringTests_ImplicitConversion_ValidImplementation() { // Arrange @@ -57,12 +65,14 @@ public void LocalizedStringTests_ImplicitConversion_ValidImplementation() localizedString = generator; // Assert - Assert.NotNull(localizedString); + Assert.IsNotNull(localizedString); } - [Fact] + [Test] public void LocalizedStringTests_WeekSubscribe_ValidImplementation() { + _ = localizationManager ?? throw new NullReferenceException(); + // Arrange var isTrigered = false; var culture2 = new CultureInfo("en"); @@ -74,15 +84,19 @@ public void LocalizedStringTests_WeekSubscribe_ValidImplementation() localizationManager.CurrentCulture = culture2; // Assert - Assert.True(isTrigered); + Assert.IsTrue(isTrigered); } #if NET461 #warning Test fails on mono x64 Running on macOS #else - [Fact] + [Test] public void LocalizedStringTests_Disposed_IfNoReferences() { + _ = initialCulture ?? throw new NullReferenceException(); + _ = resourceManager ?? throw new NullReferenceException(); + _ = localizationManager ?? throw new NullReferenceException(); + // Arrange var testString = "test"; SetLocalizedString(); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Action_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Action_Tests.cs index fe5b217df..6763b2271 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Action_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Action_Tests.cs @@ -1,7 +1,7 @@ using System; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.Helpers; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.WeakEventManagerTests { @@ -15,7 +15,7 @@ public class DelegateWeakEventManager_Action_Tests : BaseWeakEventManagerTests remove => actionEventManager.RemoveEventHandler(value); } - [Fact] + [Test] public void WeakEventManagerAction_HandleEvent_ValidImplementation() { // Arrange @@ -32,10 +32,10 @@ void HandleDelegateTest() actionEventManager.RaiseEvent(nameof(ActionEvent)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerAction_HandleEvent_InvalidHandleEventEventName() { // Arrange @@ -52,7 +52,7 @@ public void WeakEventManagerAction_HandleEvent_InvalidHandleEventEventName() ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerAction_UnassignedEvent() { // Arrange @@ -69,7 +69,7 @@ public void WeakEventManagerAction_UnassignedEvent() Assert.False(didEventFire); } - [Fact] + [Test] public void WeakEventManagerAction_UnassignedEventManager() { // Arrange @@ -87,7 +87,7 @@ public void WeakEventManagerAction_UnassignedEventManager() ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerAction_HandleEvent_InvalidHandleEvent() { // Arrange @@ -104,7 +104,7 @@ public void WeakEventManagerAction_HandleEvent_InvalidHandleEvent() ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerAction_AddEventHandler_NullHandler() { // Arrange @@ -117,7 +117,7 @@ public void WeakEventManagerAction_AddEventHandler_NullHandler() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_AddEventHandler_NullEventName() { // Arrange @@ -130,7 +130,7 @@ public void WeakEventManagerAction_AddEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_AddEventHandler_EmptyEventName() { // Arrange @@ -143,7 +143,7 @@ public void WeakEventManagerAction_AddEventHandler_EmptyEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_AddEventHandler_WhitespaceEventName() { // Arrange @@ -156,7 +156,7 @@ public void WeakEventManagerAction_AddEventHandler_WhitespaceEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_RemoveEventHandler_NullHandler() { // Arrange @@ -169,7 +169,7 @@ public void WeakEventManagerAction_RemoveEventHandler_NullHandler() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_RemoveEventHandler_NullEventName() { // Arrange @@ -182,7 +182,7 @@ public void WeakEventManagerAction_RemoveEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_RemoveEventHandler_EmptyEventName() { // Arrange @@ -195,7 +195,7 @@ public void WeakEventManagerAction_RemoveEventHandler_EmptyEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerAction_RemoveEventHandler_WhiteSpaceEventName() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Delegate_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Delegate_Tests.cs index 13a41b9d2..4645db3ee 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Delegate_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_Delegate_Tests.cs @@ -2,7 +2,7 @@ using System.ComponentModel; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.Helpers; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.WeakEventManagerTests { @@ -16,7 +16,7 @@ public class WeakEventManager_Delegate_Tests : BaseWeakEventManagerTests, INotif remove => propertyChangedWeakEventManager.RemoveEventHandler(value); } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_ValidImplementation() { // Arrange @@ -25,10 +25,10 @@ public void WeakEventManagerDelegate_HandleEvent_ValidImplementation() void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) { - Assert.NotNull(sender); - Assert.Equal(GetType(), sender?.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender?.GetType()); - Assert.NotNull(e); + Assert.IsNotNull(e); didEventFire = true; PropertyChanged -= HandleDelegateTest; @@ -38,10 +38,10 @@ void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) propertyChangedWeakEventManager.RaiseEvent(this, new PropertyChangedEventArgs("Test"), nameof(PropertyChanged)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_NullSender() { // Arrange @@ -51,7 +51,7 @@ public void WeakEventManagerDelegate_HandleEvent_NullSender() void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) { Assert.Null(sender); - Assert.NotNull(e); + Assert.IsNotNull(e); didEventFire = true; PropertyChanged -= HandleDelegateTest; @@ -63,10 +63,10 @@ void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_InvalidEventArgs() { // Arrange @@ -83,7 +83,7 @@ public void WeakEventManagerDelegate_HandleEvent_InvalidEventArgs() PropertyChanged -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_NullEventArgs() { // Arrange @@ -92,8 +92,8 @@ public void WeakEventManagerDelegate_HandleEvent_NullEventArgs() void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) { - Assert.NotNull(sender); - Assert.Equal(GetType(), sender?.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender?.GetType()); Assert.Null(e); @@ -107,10 +107,10 @@ void HandleDelegateTest(object? sender, PropertyChangedEventArgs e) #pragma warning restore CS8625 //Cannot convert null literal to non-nullable reference type // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_InvalidHandleEventEventName() { // Arrange @@ -127,7 +127,7 @@ public void WeakEventManagerDelegate_HandleEvent_InvalidHandleEventEventName() PropertyChanged -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_DynamicMethod_ValidImplementation() { // Arrange @@ -145,7 +145,7 @@ public void WeakEventManagerDelegate_HandleEvent_DynamicMethod_ValidImplementati PropertyChanged -= handler; } - [Fact] + [Test] public void WeakEventManagerDelegate_UnassignedEvent() { // Arrange @@ -164,7 +164,7 @@ public void WeakEventManagerDelegate_UnassignedEvent() Assert.False(didEventFire); } - [Fact] + [Test] public void WeakEventManagerDelegate_UnassignedEventManager() { // Arrange @@ -184,7 +184,7 @@ public void WeakEventManagerDelegate_UnassignedEventManager() PropertyChanged -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerDelegate_HandleEvent_InvalidHandleEvent() { // Arrange @@ -201,7 +201,7 @@ public void WeakEventManagerDelegate_HandleEvent_InvalidHandleEvent() PropertyChanged -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerDelegate_AddEventHandler_NullHandler() { // Arrange @@ -212,7 +212,7 @@ public void WeakEventManagerDelegate_AddEventHandler_NullHandler() Assert.Throws(() => propertyChangedWeakEventManager.AddEventHandler(null)); } - [Fact] + [Test] public void WeakEventManagerDelegate_AddEventHandler_NullEventName() { // Arrange @@ -225,7 +225,7 @@ public void WeakEventManagerDelegate_AddEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerDelegate_AddEventHandler_EmptyEventName() { // Arrange @@ -236,7 +236,7 @@ public void WeakEventManagerDelegate_AddEventHandler_EmptyEventName() Assert.Throws(() => propertyChangedWeakEventManager.AddEventHandler(null, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerDelegate_AddEventHandler_WhitespaceEventName() { // Arrange @@ -247,7 +247,7 @@ public void WeakEventManagerDelegate_AddEventHandler_WhitespaceEventName() Assert.Throws(() => propertyChangedWeakEventManager.AddEventHandler(null, " ")); } - [Fact] + [Test] public void WeakEventManagerDelegate_RemoveEventHandler_NullHandler() { // Arrange @@ -258,7 +258,7 @@ public void WeakEventManagerDelegate_RemoveEventHandler_NullHandler() Assert.Throws(() => propertyChangedWeakEventManager.RemoveEventHandler(null)); } - [Fact] + [Test] public void WeakEventManagerDelegate_RemoveEventHandler_NullEventName() { // Arrange @@ -271,7 +271,7 @@ public void WeakEventManagerDelegate_RemoveEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManagerDelegate_RemoveEventHandler_EmptyEventName() { // Arrange @@ -282,7 +282,7 @@ public void WeakEventManagerDelegate_RemoveEventHandler_EmptyEventName() Assert.Throws(() => propertyChangedWeakEventManager.RemoveEventHandler(null, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerDelegate_RemoveEventHandler_WhiteSpaceEventName() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_EventHandler_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_EventHandler_Tests.cs index 41197a627..f99448db1 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_EventHandler_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/DelegateWeakEventManager_EventHandler_Tests.cs @@ -1,13 +1,13 @@ using System; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.Helpers; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.WeakEventManagerTests { public class DelegateWeakEventManager_EventHandler_Tests : BaseWeakEventManagerTests { - [Fact] + [Test] public void WeakEventManager_HandleEvent_ValidImplementation() { // Arrange @@ -19,10 +19,10 @@ void HandleTestEvent(object? sender, EventArgs e) if (sender == null) throw new ArgumentNullException(nameof(sender)); - Assert.NotNull(sender); - Assert.Equal(GetType(), sender.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender.GetType()); - Assert.NotNull(e); + Assert.IsNotNull(e); didEventFire = true; TestEvent -= HandleTestEvent; @@ -32,10 +32,10 @@ void HandleTestEvent(object? sender, EventArgs e) TestWeakEventManager.RaiseEvent(this, new EventArgs(), nameof(TestEvent)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManager_HandleEvent_NullSender() { // Arrange @@ -45,7 +45,7 @@ public void WeakEventManager_HandleEvent_NullSender() void HandleTestEvent(object? sender, EventArgs e) { Assert.Null(sender); - Assert.NotNull(e); + Assert.IsNotNull(e); didEventFire = true; TestEvent -= HandleTestEvent; @@ -57,10 +57,10 @@ void HandleTestEvent(object? sender, EventArgs e) #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManager_HandleEvent_EmptyEventArgs() { // Arrange @@ -72,11 +72,11 @@ void HandleTestEvent(object? sender, EventArgs e) if (sender == null) throw new ArgumentNullException(nameof(sender)); - Assert.NotNull(sender); - Assert.Equal(GetType(), sender.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender.GetType()); - Assert.NotNull(e); - Assert.Equal(EventArgs.Empty, e); + Assert.IsNotNull(e); + Assert.AreEqual(EventArgs.Empty, e); didEventFire = true; TestEvent -= HandleTestEvent; @@ -86,10 +86,10 @@ void HandleTestEvent(object? sender, EventArgs e) TestWeakEventManager.RaiseEvent(this, EventArgs.Empty, nameof(TestEvent)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManager_HandleEvent_NullEventArgs() { // Arrange @@ -101,8 +101,8 @@ void HandleTestEvent(object? sender, EventArgs e) if (sender == null) throw new ArgumentNullException(nameof(sender)); - Assert.NotNull(sender); - Assert.Equal(GetType(), sender.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender.GetType()); Assert.Null(e); @@ -116,10 +116,10 @@ void HandleTestEvent(object? sender, EventArgs e) #pragma warning restore CS8625 // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManager_HandleEvent_InvalidHandleEventName() { // Arrange @@ -136,7 +136,7 @@ public void WeakEventManager_HandleEvent_InvalidHandleEventName() TestEvent -= HandleTestEvent; } - [Fact] + [Test] public void WeakEventManager_UnassignedEvent() { // Arrange @@ -155,7 +155,7 @@ public void WeakEventManager_UnassignedEvent() Assert.False(didEventFire); } - [Fact] + [Test] public void WeakEventManager_UnassignedEventManager() { // Arrange @@ -175,7 +175,7 @@ public void WeakEventManager_UnassignedEventManager() TestEvent -= HandleTestEvent; } - [Fact] + [Test] public void WeakEventManager_AddEventHandler_NullHandler() { // Arrange @@ -188,7 +188,7 @@ public void WeakEventManager_AddEventHandler_NullHandler() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_AddEventHandler_NullEventName() { // Arrange @@ -201,7 +201,7 @@ public void WeakEventManager_AddEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_AddEventHandler_EmptyEventName() { // Arrange @@ -214,7 +214,7 @@ public void WeakEventManager_AddEventHandler_EmptyEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_AddEventHandler_WhitespaceEventName() { // Arrange @@ -227,7 +227,7 @@ public void WeakEventManager_AddEventHandler_WhitespaceEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_RemoveEventHandler_NullHandler() { // Arrange @@ -240,7 +240,7 @@ public void WeakEventManager_RemoveEventHandler_NullHandler() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_RemoveEventHandler_NullEventName() { // Arrange @@ -253,7 +253,7 @@ public void WeakEventManager_RemoveEventHandler_NullEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_RemoveEventHandler_EmptyEventName() { // Arrange @@ -266,7 +266,7 @@ public void WeakEventManager_RemoveEventHandler_EmptyEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_RemoveEventHandler_WhiteSpaceEventName() { // Arrange @@ -279,7 +279,7 @@ public void WeakEventManager_RemoveEventHandler_WhiteSpaceEventName() #pragma warning restore CS8625 } - [Fact] + [Test] public void WeakEventManager_HandleEvent_InvalidHandleEvent() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_ActionT_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_ActionT_Tests.cs index 65fae73ca..16f5e2d7d 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_ActionT_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_ActionT_Tests.cs @@ -1,7 +1,7 @@ using System; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.Helpers; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.WeakEventManagerTests { @@ -15,7 +15,7 @@ public class WeakEventManager_ActionT_Tests : BaseWeakEventManagerTests remove => actionEventManager.RemoveEventHandler(value); } - [Fact] + [Test] public void WeakEventManagerActionT_HandleEvent_ValidImplementation() { // Arrange @@ -24,8 +24,8 @@ public void WeakEventManagerActionT_HandleEvent_ValidImplementation() void HandleDelegateTest(string message) { - Assert.NotNull(message); - Assert.NotEmpty(message); + Assert.IsNotNull(message); + Assert.IsNotEmpty(message); didEventFire = true; ActionEvent -= HandleDelegateTest; @@ -35,10 +35,10 @@ void HandleDelegateTest(string message) actionEventManager.RaiseEvent("Test", nameof(ActionEvent)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerActionT_HandleEvent_InvalidHandleEventEventName() { // Arrange @@ -47,8 +47,8 @@ public void WeakEventManagerActionT_HandleEvent_InvalidHandleEventEventName() void HandleDelegateTest(string message) { - Assert.NotNull(message); - Assert.NotEmpty(message); + Assert.IsNotNull(message); + Assert.IsNotEmpty(message); didEventFire = true; } @@ -61,7 +61,7 @@ void HandleDelegateTest(string message) ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerActionT_UnassignedEvent() { // Arrange @@ -71,8 +71,8 @@ public void WeakEventManagerActionT_UnassignedEvent() ActionEvent -= HandleDelegateTest; void HandleDelegateTest(string message) { - Assert.NotNull(message); - Assert.NotEmpty(message); + Assert.IsNotNull(message); + Assert.IsNotEmpty(message); didEventFire = true; } @@ -84,7 +84,7 @@ void HandleDelegateTest(string message) Assert.False(didEventFire); } - [Fact] + [Test] public void WeakEventManagerActionT_UnassignedEventManager() { // Arrange @@ -94,8 +94,8 @@ public void WeakEventManagerActionT_UnassignedEventManager() ActionEvent += HandleDelegateTest; void HandleDelegateTest(string message) { - Assert.NotNull(message); - Assert.NotEmpty(message); + Assert.IsNotNull(message); + Assert.IsNotEmpty(message); didEventFire = true; } @@ -108,7 +108,7 @@ void HandleDelegateTest(string message) ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerActionT_HandleEvent_InvalidHandleEvent() { // Arrange @@ -117,8 +117,8 @@ public void WeakEventManagerActionT_HandleEvent_InvalidHandleEvent() void HandleDelegateTest(string message) { - Assert.NotNull(message); - Assert.NotEmpty(message); + Assert.IsNotNull(message); + Assert.IsNotEmpty(message); didEventFire = true; } @@ -131,7 +131,7 @@ void HandleDelegateTest(string message) ActionEvent -= HandleDelegateTest; } - [Fact] + [Test] public void WeakEventManagerActionT_AddEventHandler_NullHandler() { // Arrange @@ -146,7 +146,7 @@ public void WeakEventManagerActionT_AddEventHandler_NullHandler() } - [Fact] + [Test] public void WeakEventManagerActionT_AddEventHandler_NullEventName() { // Arrange @@ -159,7 +159,7 @@ public void WeakEventManagerActionT_AddEventHandler_NullEventName() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerActionT_AddEventHandler_EmptyEventName() { // Arrange @@ -173,7 +173,7 @@ public void WeakEventManagerActionT_AddEventHandler_EmptyEventName() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public void WeakEventManagerActionT_AddEventHandler_WhitespaceEventName() { // Arrange @@ -184,7 +184,7 @@ public void WeakEventManagerActionT_AddEventHandler_WhitespaceEventName() Assert.Throws(() => actionEventManager.AddEventHandler(s => { var temp = s; }, " ")); } - [Fact] + [Test] public void WeakEventManagerActionT_RemoveEventHandler_NullHandler() { // Arrange @@ -198,7 +198,7 @@ public void WeakEventManagerActionT_RemoveEventHandler_NullHandler() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public void WeakEventManagerActionT_RemoveEventHandler_NullEventName() { // Arrange @@ -211,7 +211,7 @@ public void WeakEventManagerActionT_RemoveEventHandler_NullEventName() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerActionT_RemoveEventHandler_EmptyEventName() { // Arrange @@ -222,7 +222,7 @@ public void WeakEventManagerActionT_RemoveEventHandler_EmptyEventName() Assert.Throws(() => actionEventManager.RemoveEventHandler(s => { var temp = s; }, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerActionT_RemoveEventHandler_WhiteSpaceEventName() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_EventHandlerT_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_EventHandlerT_Tests.cs index 898746144..8aefbae3b 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_EventHandlerT_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/WeakEventManagerTests/WeakEventManager_EventHandlerT_Tests.cs @@ -2,13 +2,13 @@ using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.Helpers; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Helpers.WeakEventManagerTests { public class WeakEventManager_EventHandlerT_Tests : BaseWeakEventManagerTests { - [Fact] + [Test] public void WeakEventManagerTEventArgs_HandleEvent_ValidImplementation() { // Arrange @@ -22,11 +22,11 @@ void HandleTestEvent(object? sender, string? e) if (sender == null || e == null) throw new ArgumentNullException(nameof(sender)); - Assert.NotNull(sender); - Assert.Equal(GetType(), sender.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender.GetType()); - Assert.NotNull(e); - Assert.Equal(stringEventArg, e); + Assert.IsNotNull(e); + Assert.AreEqual(stringEventArg, e); didEventFire = true; TestStringEvent -= HandleTestEvent; @@ -36,10 +36,10 @@ void HandleTestEvent(object? sender, string? e) TestStringWeakEventManager.RaiseEvent(this, stringEventArg, nameof(TestStringEvent)); // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManageTEventArgs_HandleEvent_NullSender() { // Arrange @@ -53,8 +53,8 @@ void HandleTestEvent(object? sender, string e) { Assert.Null(sender); - Assert.NotNull(e); - Assert.Equal(stringEventArg, e); + Assert.IsNotNull(e); + Assert.AreEqual(stringEventArg, e); didEventFire = true; TestStringEvent -= HandleTestEvent; @@ -66,10 +66,10 @@ void HandleTestEvent(object? sender, string e) #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerTEventArgs_HandleEvent_NullEventArgs() { // Arrange @@ -81,8 +81,8 @@ void HandleTestEvent(object? sender, string e) if (sender == null) throw new ArgumentNullException(nameof(sender)); - Assert.NotNull(sender); - Assert.Equal(GetType(), sender.GetType()); + Assert.IsNotNull(sender); + Assert.AreEqual(GetType(), sender.GetType()); Assert.Null(e); @@ -96,10 +96,10 @@ void HandleTestEvent(object? sender, string e) #pragma warning restore CS8625 // Assert - Assert.True(didEventFire); + Assert.IsTrue(didEventFire); } - [Fact] + [Test] public void WeakEventManagerTEventArgs_HandleEvent_InvalidHandleEvent() { // Arrange @@ -117,7 +117,7 @@ public void WeakEventManagerTEventArgs_HandleEvent_InvalidHandleEvent() TestStringEvent -= HandleTestEvent; } - [Fact] + [Test] public void WeakEventManager_NullEventManager() { // Arrange @@ -131,7 +131,7 @@ public void WeakEventManager_NullEventManager() #pragma warning restore CS8602 } - [Fact] + [Test] public void WeakEventManagerTEventArgs_UnassignedEventManager() { // Arrange @@ -151,7 +151,7 @@ public void WeakEventManagerTEventArgs_UnassignedEventManager() TestStringEvent -= HandleTestEvent; } - [Fact] + [Test] public void WeakEventManagerTEventArgs_UnassignedEvent() { // Arrange @@ -168,7 +168,7 @@ public void WeakEventManagerTEventArgs_UnassignedEvent() Assert.False(didEventFire); } - [Fact] + [Test] public void WeakEventManagerT_AddEventHandler_NullHandler() { // Arrange @@ -181,7 +181,7 @@ public void WeakEventManagerT_AddEventHandler_NullHandler() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerT_AddEventHandler_NullEventName() { // Arrange @@ -194,7 +194,7 @@ public void WeakEventManagerT_AddEventHandler_NullEventName() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerT_AddEventHandler_EmptyEventName() { // Arrange @@ -205,7 +205,7 @@ public void WeakEventManagerT_AddEventHandler_EmptyEventName() Assert.Throws(() => TestStringWeakEventManager.AddEventHandler(s => { var temp = s; }, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerT_AddEventHandler_WhiteSpaceEventName() { // Arrange @@ -216,7 +216,7 @@ public void WeakEventManagerT_AddEventHandler_WhiteSpaceEventName() Assert.Throws(() => TestStringWeakEventManager.AddEventHandler(s => { var temp = s; }, " ")); } - [Fact] + [Test] public void WeakEventManagerT_RemoveEventHandler_NullHandler() { // Arrange @@ -229,7 +229,7 @@ public void WeakEventManagerT_RemoveEventHandler_NullHandler() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerT_RemoveEventHandler_NullEventName() { // Arrange @@ -242,7 +242,7 @@ public void WeakEventManagerT_RemoveEventHandler_NullEventName() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void WeakEventManagerT_RemoveEventHandler_EmptyEventName() { // Arrange @@ -253,7 +253,7 @@ public void WeakEventManagerT_RemoveEventHandler_EmptyEventName() Assert.Throws(() => TestStringWeakEventManager.AddEventHandler(s => { var temp = s; }, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerT_RemoveEventHandler_WhiteSpaceEventName() { // Arrange @@ -264,7 +264,7 @@ public void WeakEventManagerT_RemoveEventHandler_WhiteSpaceEventName() Assert.Throws(() => TestStringWeakEventManager.AddEventHandler(s => { var temp = s; }, string.Empty)); } - [Fact] + [Test] public void WeakEventManagerT_HandleEvent_InvalidHandleEvent() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Namespace_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Namespace_Tests.cs index 116ab361a..a0c2845f0 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Namespace_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Namespace_Tests.cs @@ -1,75 +1,75 @@ using System; using System.Linq; using System.Reflection; +using NUnit.Framework; using Xamarin.CommunityToolkit.Behaviors.Internals; using Xamarin.CommunityToolkit.Converters; using Xamarin.CommunityToolkit.Effects; using Xamarin.CommunityToolkit.Extensions; using Xamarin.CommunityToolkit.UI.Views; using Xamarin.Forms; -using Xunit; namespace Xamarin.CommunityToolkit.UnitTests { public class Namespace_Tests { - [Fact] + [Test] public void MakeSureConvertersAreInTheRightNamespace() { var allTheTypes = Assembly.GetAssembly(typeof(InvertedBoolConverter))?.GetTypes() ?? throw new NullReferenceException(); foreach (var type in allTheTypes.Where(t => t.Name.EndsWith("Converter") && t.GetInterface(nameof(IValueConverter)) != null)) { - Assert.True(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Converters"), + Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Converters"), $"{type?.FullName} not in Xamarin.CommunityToolkit.Converters namespace"); } } - [Fact] + [Test] public void MakeSureEffectsAreInTheRightNamespace() { var allTheTypes = Assembly.GetAssembly(typeof(SafeAreaEffect))?.GetTypes() ?? throw new NullReferenceException(); foreach (var type in allTheTypes.Where(t => t.Name.EndsWith("Effect") && t.IsClass && t.IsSealed && t.IsAbstract)) { - Assert.True(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Effects"), + Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Effects"), $"{type?.FullName} not in Xamarin.CommunityToolkit.Effects namespace"); } } - [Fact] + [Test] public void MakeSureMarkupExtensionsAreInTheRightNamespace() { var allTheTypes = Assembly.GetAssembly(typeof(TranslateExtension))?.GetTypes() ?? throw new NullReferenceException(); foreach (var type in allTheTypes.Where(t => t.Name.EndsWith("Extension") && t.GetInterface("IMarkupExtension") != null)) { - Assert.True(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Extensions") is true || + Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Extensions") is true || type?.Namespace?.Equals("Xamarin.CommunityToolkit.Extensions.Internals") is true, $"{type?.FullName} not in nameof(Xamarin.CommunityToolkit.Extensions namespace"); } } - [Fact] + [Test] public void MakeSureBehaviorsAreInTheRightNamespace() { var allTheTypes = Assembly.GetAssembly(typeof(BaseBehavior<>))?.GetTypes() ?? throw new NullReferenceException(); foreach (var type in allTheTypes.Where(t => t.Name.EndsWith("Behavior") && t.IsSubclassOf(typeof(BaseBehavior<>)))) { - Assert.True(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Behaviors"), + Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Behaviors"), $"{type?.FullName} not in Xamarin.CommunityToolkit.Behaviors namespace"); } } - [Fact] + [Test] public void MakeSureViewsAreInTheRightNamespace() { var allTheTypes = Assembly.GetAssembly(typeof(AvatarView))?.GetTypes() ?? throw new NullReferenceException(); foreach (var type in allTheTypes.Where(t => t.IsSubclassOf(typeof(View)))) { - Assert.True(type?.Namespace?.Equals("Xamarin.CommunityToolkit.UI.Views") is true || + Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.UI.Views") is true || type?.Namespace?.Equals("Xamarin.CommunityToolkit.UI.Views.Internals") is true, $"{type?.FullName} not in Xamarin.CommunityToolkit.UI.Views namespace"); } diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/Grouping_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/Grouping_Tests.cs index 073f095b5..b7f492032 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/Grouping_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/Grouping_Tests.cs @@ -1,60 +1,57 @@ using System.Linq; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel { public sealed class Grouping_Tests { - readonly Person[] people; - - public Grouping_Tests() + readonly Person[] people = new[] { - people = new[] - { - new Person { FirstName = "Joseph", LastName = "Hill" }, - new Person { FirstName = "James", LastName = "Montemagno" }, - new Person { FirstName = "Pierce", LastName = "Boggan" }, - }; - } + new Person { FirstName = "Joseph", LastName = "Hill" }, + new Person { FirstName = "James", LastName = "Montemagno" }, + new Person { FirstName = "Pierce", LastName = "Boggan" }, + }; - [Fact] + [Test] public void Grouping() { var sorted = from person in people - orderby person.FirstName - group person by person.Group + orderby person.FirstName + group person by person.Group into personGroup - select new Grouping(personGroup.Key, personGroup); + select new Grouping(personGroup.Key, personGroup); + var grouped = new ObservableRangeCollection>(); grouped.AddRange(sorted); - Assert.Equal(2, grouped.Count); - Assert.Equal("J", grouped[0].Key); - Assert.Equal(2, grouped[0].Count); - Assert.Single(grouped[1]); - Assert.Equal(2, grouped[0].Items.Count); - Assert.Single(grouped[1].Items); + Assert.AreEqual(2, grouped.Count); + Assert.AreEqual("J", grouped[0].Key); + Assert.AreEqual(2, grouped[0].Count); + Assert.AreEqual(1, grouped[1].Count); + Assert.AreEqual(2, grouped[0].Items.Count); + Assert.AreEqual(1, grouped[1].Items.Count); } - [Fact] + [Test] public void GroupingSubKey() { var sorted = from person in people - orderby person.FirstName - group person by person.Group + orderby person.FirstName + group person by person.Group into personGroup - select new Grouping(personGroup.Key, personGroup.Key, personGroup); + select new Grouping(personGroup.Key, personGroup.Key, personGroup); + var grouped = new ObservableRangeCollection>(); grouped.AddRange(sorted); - Assert.Equal(2, grouped.Count); - Assert.Equal("J", grouped[0].SubKey); - Assert.Equal("J", grouped[0].Key); - Assert.Equal(2, grouped[0].Count); - Assert.Single(grouped[1]); - Assert.Equal(2, grouped[0].Items.Count); - Assert.Single(grouped[1].Items); + Assert.AreEqual(2, grouped.Count); + Assert.AreEqual("J", grouped[0].SubKey); + Assert.AreEqual("J", grouped[0].Key); + Assert.AreEqual(2, grouped[0].Count); + Assert.AreEqual(1, grouped[1].Count); + Assert.AreEqual(2, grouped[0].Items.Count); + Assert.AreEqual(1, grouped[1].Items.Count); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/AsyncCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/AsyncCommand_Tests.cs index bf6cbfa15..1abf42f5e 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/AsyncCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/AsyncCommand_Tests.cs @@ -2,13 +2,13 @@ using System.Threading; using System.Threading.Tasks; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncCommandTests { public class AsyncCommandTests : BaseAsyncCommandTests { - [Fact] + [Test] public void AsyncCommand_NullExecuteParameter() { // Arrange @@ -23,9 +23,8 @@ public void AsyncCommand_NullExecuteParameter() #pragma warning restore CS8625 } - [Theory] - [InlineData(500)] - [InlineData(0)] + [TestCase(500)] + [TestCase(0)] public async Task AsyncCommand_ExecuteAsync_IntParameter_Test(int parameter) { // Arrange @@ -37,9 +36,8 @@ public async Task AsyncCommand_ExecuteAsync_IntParameter_Test(int parameter) // Assert } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task AsyncCommand_ExecuteAsync_StringParameter_Test(string parameter) { // Arrange @@ -51,7 +49,7 @@ public async Task AsyncCommand_ExecuteAsync_StringParameter_Test(string paramete // Assert } - [Fact] + [Test] public void AsyncCommand_Parameter_CanExecuteTrue_Test() { // Arrange @@ -61,10 +59,10 @@ public void AsyncCommand_Parameter_CanExecuteTrue_Test() // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_Parameter_CanExecuteFalse_Test() { // Arrange @@ -76,7 +74,7 @@ public void AsyncCommand_Parameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_NoParameter_CanExecuteTrue_Test() { // Arrange @@ -85,10 +83,10 @@ public void AsyncCommand_NoParameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_NoParameter_CanExecuteFalse_Test() { // Arrange @@ -100,7 +98,7 @@ public void AsyncCommand_NoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_Parameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -110,10 +108,10 @@ public void AsyncCommand_Parameter_CanExecuteTrue_NoParameter_Test() // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_Parameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -125,7 +123,7 @@ public void AsyncCommand_Parameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_NoParameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -134,10 +132,10 @@ public void AsyncCommand_NoParameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_NoParameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -149,7 +147,7 @@ public void AsyncCommand_NoParameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncCommand_NoParameter_NoCanExecute_Test() { // Arrange @@ -161,10 +159,11 @@ public void AsyncCommand_NoParameter_NoCanExecute_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_MainThreadExecution_Test() { // Arrange @@ -185,7 +184,7 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_MainThr canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -193,8 +192,8 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_MainThr await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -213,7 +212,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public Task AsyncCommand_RaiseCanExecuteChanged_BackgroundThreadCreation_BackgroundThreadExecution_Test() => Task.Run(async () => { // Arrange @@ -239,7 +239,7 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -247,8 +247,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) await handleCanExecuteChangedTCS.Task; // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -267,7 +267,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } }); - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_BackgroundThreadExecution_Test() { // Arrange @@ -288,7 +289,7 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_Backgro canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -301,8 +302,8 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_MainThreadCreation_Backgro await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); }).ConfigureAwait(false); async void handleCanExecuteChanged(object? sender, EventArgs e) @@ -322,7 +323,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_RaiseCanExecuteChanged_BackgroundThreadCreation_MainThreadExecution_Test() { // Arrange @@ -348,7 +350,7 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_BackgroundThreadCreation_M canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); }).ConfigureAwait(true); @@ -360,8 +362,8 @@ public async Task AsyncCommand_RaiseCanExecuteChanged_BackgroundThreadCreation_M await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -380,7 +382,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_ChangeCanExecute_Test() { // Arrange @@ -401,7 +404,7 @@ public async Task AsyncCommand_ChangeCanExecute_Test() canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -409,8 +412,8 @@ public async Task AsyncCommand_ChangeCanExecute_Test() await canExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -429,7 +432,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -438,28 +442,29 @@ public async Task AsyncCommand_CanExecuteChanged_AllowsMultipleExecutions_Test() var command = new AsyncCommand(IntParameterTask); command.CanExecuteChanged += handleCanExecuteChanged; - Assert.True(command.AllowsMultipleExecutions); + Assert.IsTrue(command.AllowsMultipleExecutions); // Act var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.IsExecuting); + Assert.IsTrue(command.CanExecute(null)); // Act await asyncCommandTask.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; void handleCanExecuteChanged(object? sender, EventArgs e) => canExecuteChangedCount++; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -477,7 +482,7 @@ public async Task AsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions_ var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); + Assert.IsTrue(command.IsExecuting); Assert.False(command.CanExecute(null)); // Act @@ -485,9 +490,9 @@ public async Task AsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions_ var canExecuteChangedGreaterThan1Result = await canExecuteChangedGreaterThan1TCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, canExecuteChangedGreaterThan1Result); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, canExecuteChangedGreaterThan1Result); async void handleCanExecuteChanged(object? sender, EventArgs e) { diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/IAsyncCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/IAsyncCommand_Tests.cs index 3b0578e25..668fb11d1 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/IAsyncCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/IAsyncCommand_Tests.cs @@ -3,13 +3,13 @@ using System.Threading.Tasks; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncCommandTests { public class IAsyncCommandTests : BaseAsyncCommandTests { - [Fact] + [Test] public void IAsyncCommand_CanExecute_InvalidReferenceParameter() { // Arrange @@ -21,7 +21,7 @@ public void IAsyncCommand_CanExecute_InvalidReferenceParameter() Assert.Throws(() => command.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_Execute_InvalidValueTypeParameter() { // Arrange @@ -33,7 +33,7 @@ public void IAsyncCommand_Execute_InvalidValueTypeParameter() Assert.Throws(() => command.Execute(true)); } - [Fact] + [Test] public void IAsyncCommand_Execute_InvalidReferenceParameter() { // Arrange @@ -45,7 +45,7 @@ public void IAsyncCommand_Execute_InvalidReferenceParameter() Assert.Throws(() => command.Execute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_CanExecute_InvalidValueTypeParameter() { // Arrange @@ -57,9 +57,8 @@ public void IAsyncCommand_CanExecute_InvalidValueTypeParameter() Assert.Throws(() => command.CanExecute(true)); } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task AsyncCommand_ExecuteAsync_StringParameter_Test(string parameter) { // Arrange @@ -73,7 +72,7 @@ public async Task AsyncCommand_ExecuteAsync_StringParameter_Test(string paramete // Assert } - [Fact] + [Test] public void IAsyncCommand_Parameter_CanExecuteTrue_Test() { // Arrange @@ -83,11 +82,11 @@ public void IAsyncCommand_Parameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command2.CanExecute(true)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command2.CanExecute(true)); } - [Fact] + [Test] public void IAsyncCommand_Parameter_CanExecuteFalse_Test() { // Arrange @@ -101,7 +100,7 @@ public void IAsyncCommand_Parameter_CanExecuteFalse_Test() Assert.False(command2.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_NoParameter_CanExecuteTrue_Test() { // Arrange @@ -110,10 +109,10 @@ public void IAsyncCommand_NoParameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncCommand_NoParameter_CanExecuteFalse_Test() { // Arrange @@ -125,7 +124,7 @@ public void IAsyncCommand_NoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncCommand_Parameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -135,11 +134,11 @@ public void IAsyncCommand_Parameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command2.CanExecute(true)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command2.CanExecute(true)); } - [Fact] + [Test] public void IAsyncCommand_Parameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -153,7 +152,7 @@ public void IAsyncCommand_Parameter_CanExecuteFalse_NoParameter_Test() Assert.False(command2.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_NoParameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -162,10 +161,10 @@ public void IAsyncCommand_NoParameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncCommand_NoParameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -177,7 +176,8 @@ public void IAsyncCommand_NoParameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task IAsyncCommand_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -186,28 +186,29 @@ public async Task IAsyncCommand_CanExecuteChanged_AllowsMultipleExecutions_Test( IAsyncCommand command = new AsyncCommand(IntParameterTask); command.CanExecuteChanged += handleCanExecuteChanged; - Assert.True(command.AllowsMultipleExecutions); + Assert.IsTrue(command.AllowsMultipleExecutions); // Act var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.IsExecuting); + Assert.IsTrue(command.CanExecute(null)); // Act await asyncCommandTask.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; void handleCanExecuteChanged(object? sender, EventArgs e) => canExecuteChangedCount++; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task IAsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -224,7 +225,7 @@ public async Task IAsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); + Assert.IsTrue(command.IsExecuting); Assert.False(command.CanExecute(null)); // Act @@ -232,9 +233,9 @@ public async Task IAsyncCommand_CanExecuteChanged_DoesNotAllowMultipleExecutions var handleCanExecuteChangedREsult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedREsult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedREsult); async void handleCanExecuteChanged(object? sender, EventArgs e) { diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/ICommand_AsyncCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/ICommand_AsyncCommand_Tests.cs index d0b55b33b..bcaa11cbf 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/ICommand_AsyncCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncCommandTests/ICommand_AsyncCommand_Tests.cs @@ -4,15 +4,14 @@ using System.Windows.Input; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncCommandTests { public class ICommand_AsyncCommandTests : BaseAsyncCommandTests { - [Theory] - [InlineData(500)] - [InlineData(0)] + [TestCase(500)] + [TestCase(0)] public async Task ICommand_Execute_IntParameter_Test(int parameter) { // Arrange @@ -25,9 +24,8 @@ public async Task ICommand_Execute_IntParameter_Test(int parameter) // Assert } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task ICommand_Execute_StringParameter_Test(string parameter) { // Arrange @@ -40,7 +38,7 @@ public async Task ICommand_Execute_StringParameter_Test(string parameter) // Assert } - [Fact] + [Test] public void ICommand_ExecuteAsync_InvalidValueTypeParameter_Test() { // Arrange @@ -54,11 +52,11 @@ public void ICommand_ExecuteAsync_InvalidValueTypeParameter_Test() actualInvalidCommandParameterException = Assert.Throws(() => command.Execute(Delay)); // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public void ICommand_ExecuteAsync_InvalidReferenceTypeParameter_Test() { // Arrange @@ -71,11 +69,11 @@ public void ICommand_ExecuteAsync_InvalidReferenceTypeParameter_Test() actualInvalidCommandParameterException = Assert.Throws(() => command.Execute("Hello World")); // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public void ICommand_ExecuteAsync_ValueTypeParameter_Test() { // Arrange @@ -88,11 +86,11 @@ public void ICommand_ExecuteAsync_ValueTypeParameter_Test() actualInvalidCommandParameterException = Assert.Throws(() => command.Execute(null)); // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteTrue_Test() { // Arrange @@ -101,10 +99,10 @@ public void ICommand_Parameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteFalse_Test() { // Arrange @@ -116,7 +114,7 @@ public void ICommand_Parameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_NoParameter_CanExecuteFalse_Test() { // Arrange @@ -128,7 +126,7 @@ public void ICommand_NoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -137,10 +135,10 @@ public void ICommand_Parameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -152,7 +150,7 @@ public void ICommand_Parameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_NoParameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -164,7 +162,7 @@ public void ICommand_NoParameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteDynamic_Test() { // Arrange @@ -173,11 +171,11 @@ public void ICommand_Parameter_CanExecuteDynamic_Test() // Act // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.False(command.CanExecute(false)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteChanged_Test() { // Arrange @@ -186,11 +184,12 @@ public void ICommand_Parameter_CanExecuteChanged_Test() // Act // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.False(command.CanExecute(false)); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_Parameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -205,20 +204,21 @@ public async Task ICommand_Parameter_CanExecuteChanged_AllowsMultipleExecutions_ command.Execute(Delay); // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); // Act await IntParameterTask(Delay).ConfigureAwait(false); await IntParameterTask(Delay).ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_Parameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -240,9 +240,9 @@ public async Task ICommand_Parameter_CanExecuteChanged_DoesNotAllowMultipleExecu var handleCanExecuteChangedTCSResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedTCSResult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedTCSResult); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -263,7 +263,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_NoParameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -278,20 +279,21 @@ public async Task ICommand_NoParameter_CanExecuteChanged_AllowsMultipleExecution command.Execute(null); // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); // Act await IntParameterTask(Delay).ConfigureAwait(false); await IntParameterTask(Delay).ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_NoParameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -330,9 +332,9 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var handleCanExecuteChangedREsult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedREsult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedREsult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/AsyncValueCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/AsyncValueCommand_Tests.cs index 5cb578862..fc8e1b3ef 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/AsyncValueCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/AsyncValueCommand_Tests.cs @@ -2,13 +2,13 @@ using System.Threading; using System.Threading.Tasks; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncValueCommandTests { public class AsyncValueCommandTests : BaseAsyncValueCommandTests { - [Fact] + [Test] public void AsyncValueCommandNullExecuteParameter() { // Arrange @@ -21,7 +21,7 @@ public void AsyncValueCommandNullExecuteParameter() #pragma warning restore CS8625 } - [Fact] + [Test] public void AsyncValueCommandT_NullExecuteParameter() { // Arrange @@ -34,9 +34,8 @@ public void AsyncValueCommandT_NullExecuteParameter() #pragma warning restore CS8625 } - [Theory] - [InlineData(500)] - [InlineData(0)] + [TestCase(500)] + [TestCase(0)] public async Task AsyncValueCommandExecuteAsync_IntParameter_Test(int parameter) { // Arrange @@ -50,9 +49,8 @@ public async Task AsyncValueCommandExecuteAsync_IntParameter_Test(int parameter) // Assert } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task AsyncValueCommandExecuteAsync_StringParameter_Test(string parameter) { // Arrange @@ -66,7 +64,7 @@ public async Task AsyncValueCommandExecuteAsync_StringParameter_Test(string para // Assert } - [Fact] + [Test] public void AsyncValueCommandParameter_CanExecuteTrue_Test() { // Arrange @@ -77,11 +75,11 @@ public void AsyncValueCommandParameter_CanExecuteTrue_Test() // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command2.CanExecute(true)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command2.CanExecute(true)); } - [Fact] + [Test] public void AsyncValueCommandParameter_CanExecuteFalse_Test() { // Arrange @@ -95,7 +93,7 @@ public void AsyncValueCommandParameter_CanExecuteFalse_Test() Assert.False(command2.CanExecute("Hello World")); } - [Fact] + [Test] public void AsyncValueCommandParameter_CanExecuteTrue_NoParameterTest() { // Arrange @@ -106,11 +104,11 @@ public void AsyncValueCommandParameter_CanExecuteTrue_NoParameterTest() // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command2.CanExecute(true)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command2.CanExecute(true)); } - [Fact] + [Test] public void AsyncValueCommandParameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -124,7 +122,7 @@ public void AsyncValueCommandParameter_CanExecuteFalse_NoParameter_Test() Assert.False(command2.CanExecute("Hello World")); } - [Fact] + [Test] public void AsyncValueCommandNoParameter_CanExecuteTrue_Test() { // Arrange @@ -133,10 +131,10 @@ public void AsyncValueCommandNoParameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncValueCommandNoParameter_CanExecuteFalse_Test() { // Arrange @@ -148,7 +146,7 @@ public void AsyncValueCommandNoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncValueCommandNoParameter_CanExecuteTrueNoParameter_Test() { // Arrange @@ -157,10 +155,10 @@ public void AsyncValueCommandNoParameter_CanExecuteTrueNoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncValueCommandNoParameter_CanExecuteFalseNoParameter_Test() { // Arrange @@ -172,7 +170,7 @@ public void AsyncValueCommandNoParameter_CanExecuteFalseNoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void AsyncValueCommandNoParameter_NoCanExecute_Test() { // Arrange @@ -184,10 +182,11 @@ public void AsyncValueCommandNoParameter_NoCanExecute_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_RaiseCanExecuteChanged_Test() { // Arrange @@ -208,7 +207,7 @@ public async Task AsyncValueCommand_RaiseCanExecuteChanged_Test() canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -216,8 +215,8 @@ public async Task AsyncValueCommand_RaiseCanExecuteChanged_Test() await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -236,7 +235,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_ChangeCanExecute_Test() { // Arrange @@ -257,7 +257,7 @@ public async Task AsyncValueCommand_ChangeCanExecute_Test() canCommandExecute = true; // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); Assert.False(didCanExecuteChangeFire); // Act @@ -265,8 +265,8 @@ public async Task AsyncValueCommand_ChangeCanExecute_Test() await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(didCanExecuteChangeFire); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(didCanExecuteChangeFire); + Assert.IsTrue(command.CanExecute(null)); async void handleCanExecuteChanged(object? sender, EventArgs e) { @@ -285,7 +285,8 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) } } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_Parameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -296,26 +297,27 @@ public async Task AsyncValueCommand_Parameter_CanExecuteChanged_AllowsMultipleEx void handleCanExecuteChanged(object? sender, EventArgs e) => canExecuteChangedCount++; - Assert.True(command.AllowsMultipleExecutions); + Assert.IsTrue(command.AllowsMultipleExecutions); // Act var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.IsExecuting); + Assert.IsTrue(command.CanExecute(null)); // Act await asyncCommandTask.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_Parameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -350,7 +352,7 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var asyncCommandTask = command.ExecuteAsync(Delay); // Assert - Assert.True(command.IsExecuting); + Assert.IsTrue(command.IsExecuting); Assert.False(command.CanExecute(null)); // Act @@ -358,12 +360,13 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var handleCanExecuteChangedResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedResult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedResult); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_NoParameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -374,26 +377,27 @@ public async Task AsyncValueCommand_NoParameter_CanExecuteChanged_AllowsMultiple void handleCanExecuteChanged(object? sender, EventArgs e) => canExecuteChangedCount++; - Assert.True(command.AllowsMultipleExecutions); + Assert.IsTrue(command.AllowsMultipleExecutions); // Act var asyncCommandTask = command.ExecuteAsync(); // Assert - Assert.True(command.IsExecuting); - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.IsExecuting); + Assert.IsTrue(command.CanExecute(null)); // Act await asyncCommandTask.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task AsyncValueCommand_NoParameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -428,7 +432,7 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var asyncCommandTask = command.ExecuteAsync(); // Assert - Assert.True(command.IsExecuting); + Assert.IsTrue(command.IsExecuting); Assert.False(command.CanExecute(null)); // Act @@ -436,9 +440,9 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var handleCanExecuteChangedResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedResult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/IAsyncValueCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/IAsyncValueCommand_Tests.cs index c20a31a64..da70c0f94 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/IAsyncValueCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/IAsyncValueCommand_Tests.cs @@ -1,13 +1,13 @@ using System.Threading.Tasks; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncValueCommandTests { public class IAsyncValueCommandTests : BaseAsyncValueCommandTests { - [Fact] + [Test] public void IAsyncCommand_CanExecute_InvalidReferenceParameter() { // Arrange @@ -19,7 +19,7 @@ public void IAsyncCommand_CanExecute_InvalidReferenceParameter() Assert.Throws(() => command.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_Execute_InvalidValueTypeParameter() { // Arrange @@ -31,7 +31,7 @@ public void IAsyncCommand_Execute_InvalidValueTypeParameter() Assert.Throws(() => command.Execute(true)); } - [Fact] + [Test] public void IAsyncCommand_Execute_InvalidReferenceParameter() { // Arrange @@ -43,7 +43,7 @@ public void IAsyncCommand_Execute_InvalidReferenceParameter() Assert.Throws(() => command.Execute("Hello World")); } - [Fact] + [Test] public void IAsyncCommand_CanExecute_InvalidValueTypeParameter() { // Arrange @@ -55,9 +55,8 @@ public void IAsyncCommand_CanExecute_InvalidValueTypeParameter() Assert.Throws(() => command.CanExecute(true)); } - [Theory] - [InlineData(500)] - [InlineData(0)] + [TestCase(500)] + [TestCase(0)] public async Task AsyncValueCommand_ExecuteAsync_IntParameter_Test(int parameter) { // Arrange @@ -71,9 +70,8 @@ public async Task AsyncValueCommand_ExecuteAsync_IntParameter_Test(int parameter // Assert } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task AsyncValueCommand_ExecuteAsync_StringParameter_Test(string parameter) { // Arrange @@ -87,7 +85,7 @@ public async Task AsyncValueCommand_ExecuteAsync_StringParameter_Test(string par // Assert } - [Fact] + [Test] public void IAsyncValueCommand_Parameter_CanExecuteTrue_Test() { // Arrange @@ -97,11 +95,11 @@ public void IAsyncValueCommand_Parameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute("Hello World")); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncValueCommand_Parameter_CanExecuteFalse_Test() { // Arrange @@ -115,7 +113,7 @@ public void IAsyncValueCommand_Parameter_CanExecuteFalse_Test() Assert.False(command2.CanExecute(true)); } - [Fact] + [Test] public void IAsyncValueCommand_Parameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -125,11 +123,11 @@ public void IAsyncValueCommand_Parameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute("Hello World")); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute("Hello World")); } - [Fact] + [Test] public void IAsyncValueCommand_Parameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -143,7 +141,7 @@ public void IAsyncValueCommand_Parameter_CanExecuteFalse_NoParameter_Test() Assert.False(command2.CanExecute(true)); } - [Fact] + [Test] public void IAsyncValueCommand_NoParameter_CanExecuteTrue_Test() { // Arrange @@ -152,10 +150,10 @@ public void IAsyncValueCommand_NoParameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncValueCommand_NoParameter_CanExecuteFalse_Test() { // Arrange @@ -167,7 +165,7 @@ public void IAsyncValueCommand_NoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncValueCommand_NoParameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -176,10 +174,10 @@ public void IAsyncValueCommand_NoParameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void IAsyncValueCommand_NoParameter_CanExecuteFalse_NoParameter_Test() { // Arrange diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/ICommand_AsyncValueCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/ICommand_AsyncValueCommand_Tests.cs index cbe25b61f..43edd576d 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/ICommand_AsyncValueCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/AsyncValueCommandTests/ICommand_AsyncValueCommand_Tests.cs @@ -4,15 +4,14 @@ using System.Windows.Input; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncValueCommandTests { public class ICommand_AsyncValueCommandTests : BaseAsyncValueCommandTests { - [Theory] - [InlineData(500)] - [InlineData(0)] + [TestCase(500)] + [TestCase(0)] public async Task ICommand_Execute_IntParameter_Test(int parameter) { // Arrange @@ -25,9 +24,8 @@ public async Task ICommand_Execute_IntParameter_Test(int parameter) // Assert } - [Theory] - [InlineData("Hello")] - [InlineData(default)] + [TestCase("Hello")] + [TestCase(default)] public async Task ICommand_Execute_StringParameter_Test(string parameter) { // Arrange @@ -40,7 +38,7 @@ public async Task ICommand_Execute_StringParameter_Test(string parameter) // Assert } - [Fact] + [Test] public async Task ICommand_Execute_InvalidValueTypeParameter_Test() { // Arrange @@ -62,11 +60,11 @@ public async Task ICommand_Execute_InvalidValueTypeParameter_Test() } // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public async Task ICommand_Execute_InvalidReferenceTypeParameter_Test() { // Arrange @@ -88,11 +86,11 @@ public async Task ICommand_Execute_InvalidReferenceTypeParameter_Test() } // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public async Task ICommand_Execute_ValueTypeParameter_Test() { // Arrange @@ -114,11 +112,11 @@ public async Task ICommand_Execute_ValueTypeParameter_Test() } // Assert - Assert.NotNull(actualInvalidCommandParameterException); - Assert.Equal(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); + Assert.IsNotNull(actualInvalidCommandParameterException); + Assert.AreEqual(expectedInvalidCommandParameterException.Message, actualInvalidCommandParameterException?.Message); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteTrue_Test() { // Arrange @@ -127,10 +125,10 @@ public void ICommand_Parameter_CanExecuteTrue_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteFalse_Test() { // Arrange @@ -142,7 +140,7 @@ public void ICommand_Parameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_NoParameter_CanExecuteFalse_Test() { // Arrange @@ -154,7 +152,7 @@ public void ICommand_NoParameter_CanExecuteFalse_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteTrue_NoParameter_Test() { // Arrange @@ -163,10 +161,10 @@ public void ICommand_Parameter_CanExecuteTrue_NoParameter_Test() // Act // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -178,7 +176,7 @@ public void ICommand_Parameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_NoParameter_CanExecuteFalse_NoParameter_Test() { // Arrange @@ -190,7 +188,7 @@ public void ICommand_NoParameter_CanExecuteFalse_NoParameter_Test() Assert.False(command.CanExecute(null)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteDynamic_Test() { // Arrange @@ -199,11 +197,11 @@ public void ICommand_Parameter_CanExecuteDynamic_Test() // Act // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.False(command.CanExecute(false)); } - [Fact] + [Test] public void ICommand_Parameter_CanExecuteChanged_Test() { // Arrange @@ -212,11 +210,12 @@ public void ICommand_Parameter_CanExecuteChanged_Test() // Act // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.False(command.CanExecute(false)); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_Parameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -231,19 +230,20 @@ public async Task ICommand_Parameter_CanExecuteChanged_AllowsMultipleExecutions_ command.Execute(Delay); // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); // Act await IntParameterTask(Delay).ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_Parameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -282,12 +282,13 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var handleCanExecuteChangedResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedResult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedResult); } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_NoParameter_CanExecuteChanged_AllowsMultipleExecutions_Test() { // Arrange @@ -302,20 +303,21 @@ public async Task ICommand_NoParameter_CanExecuteChanged_AllowsMultipleExecution command.Execute(null); // Assert - Assert.True(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(null)); // Act await IntParameterTask(Delay).ConfigureAwait(false); await IntParameterTask(Delay).ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(0, canExecuteChangedCount); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(0, canExecuteChangedCount); command.CanExecuteChanged -= handleCanExecuteChanged; } - [Fact(Timeout = ICommandTestTimeout)] + [Test] + [Timeout(ICommandTestTimeout)] public async Task ICommand_NoParameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test() { // Arrange @@ -354,9 +356,9 @@ async void handleCanExecuteChanged(object? sender, EventArgs e) var handleCanExecuteChangedResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false); // Assert - Assert.True(command.CanExecute(null)); - Assert.Equal(2, canExecuteChangedCount); - Assert.Equal(canExecuteChangedCount, handleCanExecuteChangedResult); + Assert.IsTrue(command.CanExecute(null)); + Assert.AreEqual(2, canExecuteChangedCount); + Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedResult); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/BaseCommandTests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/BaseCommandTests.cs index 018e5c89b..2954b876c 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/BaseCommandTests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/BaseCommandTests.cs @@ -2,11 +2,11 @@ using System.Threading.Tasks; using Xamarin.CommunityToolkit.UnitTests.Mocks; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests { - [Collection(nameof(BaseCommandTests))] + [NonParallelizable] public abstract class BaseCommandTests { public const int ICommandTestTimeout = Delay * 6; diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncCommand_Tests.cs index 690f4ef99..c4dbd6316 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncCommand_Tests.cs @@ -3,13 +3,13 @@ using System.Windows.Input; using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.CommandFactoryTests { public class CommandFactoryAsyncCommandTests : BaseCommandTests { - [Fact] + [Test] public void AsyncCommand_NullExecuteParameter() { // Arrange @@ -23,7 +23,7 @@ public void AsyncCommand_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncCommand_NullCanExecuteParameter() { // Arrange @@ -33,15 +33,15 @@ public async Task AsyncCommand_NullCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public async Task AsyncCommand_ObjectCanExecuteParameter() { // Arrange @@ -51,15 +51,15 @@ public async Task AsyncCommand_ObjectCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void AsyncCommand_FuncBool_NullExecuteParameter() { // Arrange @@ -73,7 +73,7 @@ public void AsyncCommand_FuncBool_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncCommand_FuncBool_NullCanExecuteParameter() { // Arrange @@ -86,16 +86,16 @@ public async Task AsyncCommand_FuncBool_NullCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public async Task AsyncCommand_FuncBool_ValidExecuteParameter_ValidCanExecuteParameter() { // Arrange @@ -105,16 +105,16 @@ public async Task AsyncCommand_FuncBool_ValidExecuteParameter_ValidCanExecutePar await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void AsyncCommandT_NullExecuteParameter() { // Arrange @@ -128,7 +128,7 @@ public void AsyncCommandT_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncCommandT_NullCanExecuteParameter() { // Arrange @@ -138,16 +138,16 @@ public async Task AsyncCommandT_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncCommandT_ObjectCanExecuteParameter() { // Arrange @@ -157,16 +157,16 @@ public async Task AsyncCommandT_ObjectCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public void AsyncCommandT_FuncBool_NullExecuteParameter() { // Arrange @@ -180,7 +180,7 @@ public void AsyncCommandT_FuncBool_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncCommandT_FuncBool_NullCanExecuteParameter() { // Arrange @@ -193,16 +193,16 @@ public async Task AsyncCommandT_FuncBool_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncCommandT_FuncBool_ValidExecuteParameter_ValidCanExecuteParameter() { // Arrange @@ -212,16 +212,16 @@ public async Task AsyncCommandT_FuncBool_ValidExecuteParameter_ValidCanExecutePa await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public void AsyncCommandTExecuteTCanExecute_NullExecuteParameter() { // Arrange @@ -235,7 +235,7 @@ public void AsyncCommandTExecuteTCanExecute_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncCommandTExecuteTCanExecute_NullCanExecuteParameter() { // Arrange @@ -247,17 +247,17 @@ public async Task AsyncCommandTExecuteTCanExecute_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.Throws(() => command.CanExecute(0)); Assert.Throws(() => command.CanExecute(string.Empty)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncCommandTExecuteTCanExecute_ObjectCanExecuteParameter() { // Arrange @@ -267,14 +267,14 @@ public async Task AsyncCommandTExecuteTCanExecute_ObjectCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.Throws(() => command.CanExecute(0)); Assert.Throws(() => command.CanExecute(string.Empty)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncValueCommand_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncValueCommand_Tests.cs index 90879ce59..0261a922b 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncValueCommand_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncValueCommand_Tests.cs @@ -4,13 +4,13 @@ using Xamarin.CommunityToolkit.Exceptions; using Xamarin.CommunityToolkit.ObjectModel; using Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncValueCommandTests; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.CommandFactoryTests { public class CommandFactoryAsyncValueCommandTests : BaseAsyncValueCommandTests { - [Fact] + [Test] public void AsyncValueCommand_NullExecuteParameter() { // Arrange @@ -24,7 +24,7 @@ public void AsyncValueCommand_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncValueCommand_NullCanExecuteParameter() { // Arrange @@ -34,15 +34,15 @@ public async Task AsyncValueCommand_NullCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public async Task AsyncValueCommand_ObjectCanExecuteParameter() { // Arrange @@ -52,15 +52,15 @@ public async Task AsyncValueCommand_ObjectCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void AsyncValueCommand_FuncBool_NullExecuteParameter() { // Arrange @@ -74,7 +74,7 @@ public void AsyncValueCommand_FuncBool_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncValueCommand_FuncBool_NullCanExecuteParameter() { // Arrange @@ -87,16 +87,16 @@ public async Task AsyncValueCommand_FuncBool_NullCanExecuteParameter() await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public async Task AsyncValueCommand_FuncBool_ValidExecuteParameter_ValidCanExecuteParameter() { // Arrange @@ -106,16 +106,16 @@ public async Task AsyncValueCommand_FuncBool_ValidExecuteParameter_ValidCanExecu await command.ExecuteAsync(); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void AsyncValueCommandT_NullExecuteParameter() { // Arrange @@ -129,7 +129,7 @@ public void AsyncValueCommandT_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncValueCommandT_NullCanExecuteParameter() { // Arrange @@ -139,16 +139,16 @@ public async Task AsyncValueCommandT_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncValueCommandT_ObjectCanExecuteParameter() { // Arrange @@ -158,16 +158,16 @@ public async Task AsyncValueCommandT_ObjectCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public void AsyncValueCommandT_FuncBool_NullExecuteParameter() { // Arrange @@ -181,7 +181,7 @@ public void AsyncValueCommandT_FuncBool_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncValueCommandT_FuncBool_NullCanExecuteParameter() { // Arrange @@ -194,16 +194,16 @@ public async Task AsyncValueCommandT_FuncBool_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncValueCommandT_FuncBool_ValidExecuteParameter_ValidCanExecuteParameter() { // Arrange @@ -213,16 +213,16 @@ public async Task AsyncValueCommandT_FuncBool_ValidExecuteParameter_ValidCanExec await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public void AsyncValueCommandTExecuteTCanExecute_NullExecuteParameter() { // Arrange @@ -236,7 +236,7 @@ public void AsyncValueCommandTExecuteTCanExecute_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public async Task AsyncValueCommandTExecuteTCanExecute_NullCanExecuteParameter() { // Arrange @@ -246,17 +246,17 @@ public async Task AsyncValueCommandTExecuteTCanExecute_NullCanExecuteParameter() await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.Throws(() => command.CanExecute(0)); Assert.Throws(() => command.CanExecute(string.Empty)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } - [Fact] + [Test] public async Task AsyncValueCommandTExecuteTCanExecute_ObjectCanExecuteParameter() { // Arrange @@ -266,14 +266,14 @@ public async Task AsyncValueCommandTExecuteTCanExecute_ObjectCanExecuteParameter await command.ExecuteAsync(0); // Assert - Assert.True(command.CanExecute(true)); + Assert.IsTrue(command.CanExecute(true)); Assert.Throws(() => command.CanExecute(0)); Assert.Throws(() => command.CanExecute(string.Empty)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); - Assert.IsAssignableFrom>(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf>(command); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_Command_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_Command_Tests.cs index 884935a3b..96dbbcf22 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_Command_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_Command_Tests.cs @@ -1,13 +1,13 @@ using System; using System.Windows.Input; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.CommandFactoryTests { public class CommandFactoryCommandTests : BaseCommandTests { - [Fact] + [Test] public void Action_NullExecuteParameter() { // Arrange @@ -21,7 +21,7 @@ public void Action_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public void Action_ValidExecuteParameter() { // Arrange @@ -31,15 +31,15 @@ public void Action_ValidExecuteParameter() command.Execute(null); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void Action_NullCanExecuteParameter() { // Arrange @@ -52,7 +52,7 @@ public void Action_NullCanExecuteParameter() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void Action_ValidCanExecuteParameter() { // Arrange @@ -62,15 +62,15 @@ public void Action_ValidCanExecuteParameter() command.Execute(null); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void ActionObject_NullExecuteParameter() { // Arrange @@ -84,7 +84,7 @@ public void ActionObject_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public void ActionObject_ValidExecuteParameter() { // Arrange @@ -94,15 +94,15 @@ public void ActionObject_ValidExecuteParameter() command.Execute(null); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void ActionObject_NullCanExecuteParameter() { // Arrange @@ -115,7 +115,7 @@ public void ActionObject_NullCanExecuteParameter() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void ActionObject_ValidCanExecuteParameter() { // Arrange @@ -127,15 +127,15 @@ public void ActionObject_ValidCanExecuteParameter() command.Execute(string.Empty); // Assert - Assert.True(command.CanExecute(null)); - Assert.True(command.CanExecute(string.Empty)); - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(null)); + Assert.IsTrue(command.CanExecute(string.Empty)); + Assert.IsTrue(command.CanExecute(0)); - Assert.IsType(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf(command); + Assert.IsInstanceOf(command); } - [Fact] + [Test] public void ActionInt_NullExecuteParameter() { // Arrange @@ -149,7 +149,7 @@ public void ActionInt_NullExecuteParameter() #pragma warning restore CS8604 // Possible null reference argument. } - [Fact] + [Test] public void ActionInt_NullCanExecuteParameter() { // Arrange @@ -162,7 +162,7 @@ public void ActionInt_NullCanExecuteParameter() #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } - [Fact] + [Test] public void ActionInt_ValidCanExecuteParameter() { // Arrange @@ -171,12 +171,12 @@ public void ActionInt_ValidCanExecuteParameter() // Act // Assert - Assert.True(command.CanExecute(0)); + Assert.IsTrue(command.CanExecute(0)); Assert.False(command.CanExecute(null)); Assert.False(command.CanExecute(string.Empty)); - Assert.IsType>(command); - Assert.IsAssignableFrom(command); + Assert.IsInstanceOf>(command); + Assert.IsInstanceOf(command); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableObject_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableObject_Tests.cs index 060fbf7e5..f3f23f530 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableObject_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableObject_Tests.cs @@ -1,21 +1,21 @@ using System; using System.ComponentModel; using System.Threading.Tasks; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel { public sealed class ObservableObject_Tests { - readonly Person person = new Person - { - FirstName = "James", - LastName = "Montemagno" - }; - - [Fact] + [Test] public void OnPropertyChanged() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + PropertyChangedEventArgs? updated = null; person.PropertyChanged += (sender, args) => { @@ -24,13 +24,19 @@ public void OnPropertyChanged() person.FirstName = "Motz"; - Assert.NotNull(updated); - Assert.Equal(nameof(person.FirstName), updated?.PropertyName); + Assert.IsNotNull(updated); + Assert.AreEqual(nameof(person.FirstName), updated?.PropertyName); } - [Fact] + [Test] public void OnDidntChange() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + PropertyChangedEventArgs? updated = null; person.PropertyChanged += (sender, args) => { @@ -42,9 +48,15 @@ public void OnDidntChange() Assert.Null(updated); } - [Fact] + [Test] public void OnChangedEvent() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + var triggered = false; person.Changed = () => { @@ -53,12 +65,18 @@ public void OnChangedEvent() person.FirstName = "Motz"; - Assert.True(triggered, "OnChanged didn't raise"); + Assert.IsTrue(triggered, "OnChanged didn't raise"); } - [Fact] + [Test] public void OnChangingEvent() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + var triggered = false; person.Changing = () => { @@ -67,12 +85,18 @@ public void OnChangingEvent() person.FirstName = "Motz"; - Assert.True(triggered, "OnChanging didn't raise"); + Assert.IsTrue(triggered, "OnChanging didn't raise"); } - [Fact] + [Test] public void ValidateEvent() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + var contol = "Motz"; var triggered = false; person.Validate = (oldValue, newValue) => @@ -83,13 +107,19 @@ public void ValidateEvent() person.FirstName = contol; - Assert.True(triggered, "ValidateValue didn't raise"); - Assert.Equal(person.FirstName, contol); + Assert.IsTrue(triggered, "ValidateValue didn't raise"); + Assert.AreEqual(person.FirstName, contol); } - [Fact] + [Test] public void NotValidateEvent() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + var contol = person.FirstName; var triggered = false; person.Validate = (oldValue, newValue) => @@ -100,25 +130,31 @@ public void NotValidateEvent() person.FirstName = "Motz"; - Assert.True(triggered, "ValidateValue didn't raise"); - Assert.Equal(person.FirstName, contol); + Assert.IsTrue(triggered, "ValidateValue didn't raise"); + Assert.AreEqual(person.FirstName, contol); } - [Fact] - public async Task ValidateEventException() + [Test] + public void ValidateEventException() { + var person = new Person + { + FirstName = "James", + LastName = "Montemagno" + }; + person.Validate = (oldValue, newValue) => { throw new ArgumentOutOfRangeException(); }; - var result = await Assert.ThrowsAsync(() => + var result = Assert.ThrowsAsync(() => { person.FirstName = "Motz"; return Task.CompletedTask; }); - Assert.NotNull(result); + Assert.IsNotNull(result); } } } \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableRangeCollection_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableRangeCollection_Tests.cs index 83cc4f090..3c5b3bbb1 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableRangeCollection_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/ObjectModel/ObservableRangeCollection_Tests.cs @@ -2,14 +2,14 @@ using System.Collections.Generic; using System.Collections.Specialized; using Xamarin.CommunityToolkit.ObjectModel; -using Xunit; -using Xunit.Sdk; +using NUnit.Framework; +using NUnit.Framework.Internal; namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel { public class ObservableRangeCollection_Tests { - [Fact] + [Test] public void AddRange() { var collection = new ObservableRangeCollection(); @@ -17,14 +17,14 @@ public void AddRange() collection.CollectionChanged += (s, e) => { - Assert.Equal(NotifyCollectionChangedAction.Add, e.Action); + Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action); Assert.Null(e.OldItems); - Assert.Equal(toAdd, e.NewItems); + Assert.AreEqual(toAdd, e.NewItems); }; collection.AddRange(toAdd); } - [Fact] + [Test] public void AddRangeEmpty() { var collection = new ObservableRangeCollection(); @@ -32,12 +32,12 @@ public void AddRangeEmpty() collection.CollectionChanged += (s, e) => { - throw new XunitException("The event is raised."); + throw new NUnitException("The event is raised."); }; collection.AddRange(toAdd); } - [Fact] + [Test] public void ReplaceRange() { var collection = new ObservableRangeCollection(); @@ -46,23 +46,23 @@ public void ReplaceRange() collection.AddRange(toRemove); collection.CollectionChanged += (s, e) => { - Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action); + Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action); Assert.Null(e.OldItems); Assert.Null(e.NewItems); - Assert.Equal(collection.Count, toAdd.Length); + Assert.AreEqual(collection.Count, toAdd.Length); for (var i = 0; i < toAdd.Length; i++) { if (collection[i] != (int)toAdd[i]) - throw new XunitException("Expected and actual items don't match."); + throw new NUnitException("Expected and actual items don't match."); } }; collection.ReplaceRange(toAdd); } - [Fact] + [Test] public void ReplaceRange_on_non_empty_collection_should_always_raise_collection_changes() { var collection = new ObservableRangeCollection(new[] { 1 }); @@ -75,10 +75,10 @@ public void ReplaceRange_on_non_empty_collection_should_always_raise_collection_ }; collection.ReplaceRange(toAdd); - Assert.True(eventRaised, "Collection Reset should be raised."); + Assert.IsTrue(eventRaised, "Collection Reset should be raised."); } - [Fact] + [Test] public void ReplaceRange_on_empty_collection_should_NOT_raise_collection_changes_when_empty() { var collection = new ObservableRangeCollection(); @@ -86,13 +86,13 @@ public void ReplaceRange_on_empty_collection_should_NOT_raise_collection_changes collection.CollectionChanged += (s, e) => { - throw new XunitException("Collection changes should NOT be raised."); + throw new NUnitException("Collection changes should NOT be raised."); }; collection.ReplaceRange(toAdd); } - [Fact] + [Test] public void ReplaceRange_should_NOT_mutate_source() { var sourceData = new List(new[] { 1, 2, 3 }); @@ -100,10 +100,10 @@ public void ReplaceRange_should_NOT_mutate_source() collection.ReplaceRange(sourceData); - Assert.Equal(3, sourceData.Count); + Assert.AreEqual(3, sourceData.Count); } - [Fact] + [Test] public void RemoveRangeRemoveFact() { var collection = new ObservableRangeCollection(); @@ -113,22 +113,25 @@ public void RemoveRangeRemoveFact() collection.CollectionChanged += (s, e) => { if (e.Action != NotifyCollectionChangedAction.Remove) - throw new XunitException("RemoveRange didn't use Remove like requested."); + throw new NUnitException("RemoveRange didn't use Remove like requested."); + if (e.OldItems == null) - throw new XunitException("OldItems should not be null."); + throw new NUnitException("OldItems should not be null."); + var expected = new int[] { 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9 }; if (expected.Length != e.OldItems.Count) - throw new XunitException("Expected and actual OldItems don't match."); + throw new NUnitException("Expected and actual OldItems don't match."); + for (var i = 0; i < expected.Length; i++) { if (expected[i] != (int?)e.OldItems[i]) - throw new XunitException("Expected and actual OldItems don't match."); + throw new NUnitException("Expected and actual OldItems don't match."); } }; collection.RemoveRange(toRemove, NotifyCollectionChangedAction.Remove); } - [Fact] + [Test] public void RemoveRangeEmpty() { var collection = new ObservableRangeCollection(); @@ -137,12 +140,12 @@ public void RemoveRangeEmpty() collection.AddRange(toAdd); collection.CollectionChanged += (s, e) => { - throw new XunitException("The event is raised."); + throw new NUnitException("The event is raised."); }; collection.RemoveRange(toRemove, NotifyCollectionChangedAction.Remove); } - [Fact] + [Test] public void RemoveRange_should_NOT_mutate_source_when_source_data_is_not_present() { var sourceData = new List(new[] { 1, 2, 3 }); @@ -150,10 +153,10 @@ public void RemoveRange_should_NOT_mutate_source_when_source_data_is_not_present collection.RemoveRange(sourceData, NotifyCollectionChangedAction.Remove); - Assert.Equal(3, sourceData.Count); + Assert.AreEqual(3, sourceData.Count); } - [Fact] + [Test] public void RemoveRange_should_NOT_mutate_source_when_source_data_is_present() { var sourceData = new List(new[] { 1, 2, 3 }); @@ -161,10 +164,10 @@ public void RemoveRange_should_NOT_mutate_source_when_source_data_is_present() collection.RemoveRange(sourceData, NotifyCollectionChangedAction.Remove); - Assert.Equal(3, sourceData.Count); + Assert.AreEqual(3, sourceData.Count); } - [Fact] + [Test] public void RemoveRange_should_NOT_mutate_collection_when_source_data_is_not_present() { var sourceData = new List(new[] { 1, 2, 3 }); @@ -173,10 +176,10 @@ public void RemoveRange_should_NOT_mutate_collection_when_source_data_is_not_pre collection.RemoveRange(sourceData, NotifyCollectionChangedAction.Remove); // the collection should not be modified if the source items are not found - Assert.Equal(6, collection.Count); + Assert.AreEqual(6, collection.Count); } - [Fact] + [Test] public void AddCollection() { var toAdd = new[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3 }; @@ -186,10 +189,10 @@ public void AddCollection() Collection = { toAdd } }; - Assert.Equal(toAdd, wrapper.Collection); + Assert.AreEqual(toAdd, wrapper.Collection); } - [Fact] + [Test] public void AddToNullCollection() { var toAdd = new[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3 }; diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/CameraView_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/CameraView_Tests.cs index af353dcae..1a89d6475 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/CameraView_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/CameraView_Tests.cs @@ -1,29 +1,29 @@ using System; using Xamarin.CommunityToolkit.UI.Views; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Views { public class CameraView_Tests { - [Fact] + [Test] public void TestConstructor() { var camera = new CameraView(); Assert.False(camera.IsBusy); Assert.False(camera.IsAvailable); - Assert.Equal(CameraOptions.Default, camera.CameraOptions); + Assert.AreEqual(CameraOptions.Default, camera.CameraOptions); // See TODO on CameraView.SavePhotoToFile // Assert.False(camera.SavePhotoToFile); - Assert.Equal(CameraCaptureMode.Default, camera.CaptureMode); - Assert.Equal(CameraFlashMode.Off, camera.FlashMode); + Assert.AreEqual(CameraCaptureMode.Default, camera.CaptureMode); + Assert.AreEqual(CameraFlashMode.Off, camera.FlashMode); } - [Fact] + [Test] public void TestOnMediaCaptured() { var camera = new CameraView(); @@ -33,10 +33,10 @@ public void TestOnMediaCaptured() camera.MediaCaptured += (_, e) => fired = e == args; camera.RaiseMediaCaptured(args); - Assert.True(fired); + Assert.IsTrue(fired); } - [Fact] + [Test] public void TestOnMediaCapturedFailed() { var camera = new CameraView(); @@ -45,10 +45,10 @@ public void TestOnMediaCapturedFailed() camera.MediaCaptureFailed += (_, e) => fired = e == "123"; camera.RaiseMediaCaptureFailed("123"); - Assert.True(fired); + Assert.IsTrue(fired); } - [Fact] + [Test] public void TestOnShutterClicked() { var camera = new CameraView(); @@ -57,10 +57,10 @@ public void TestOnShutterClicked() camera.ShutterClicked += (sender, e) => fired = true; camera.Shutter(); - Assert.True(fired); + Assert.IsTrue(fired); } - [Fact] + [Test] public void TestShutterCommand() { var camera = new CameraView(); @@ -73,10 +73,10 @@ public void TestShutterCommand() camera.ShutterCommand?.Execute(null); - Assert.True(trigged); + Assert.IsTrue(trigged); } - [Fact] + [Test] public void TestShutterCommandFromVM() { var vm = new CameraViewModel(); @@ -96,7 +96,7 @@ public void TestShutterCommandFromVM() vm.ShutterCommand.Execute(null); - Assert.True(trigged); + Assert.IsTrue(trigged); } class CameraViewModel diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaElement_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaElement_Tests.cs index 186e8ceeb..4ce235a95 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaElement_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaElement_Tests.cs @@ -1,13 +1,13 @@ using System; using Xamarin.CommunityToolkit.Core; using Xamarin.CommunityToolkit.UI.Views; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Views { public class MediaElement_Tests { - [Fact] + [Test] public void TestSource() { var mediaElement = new MediaElement(); @@ -24,11 +24,11 @@ public void TestSource() var source = MediaSource.FromFile("Video.mp4"); mediaElement.Source = source; - Assert.Equal(source, mediaElement.Source); - Assert.True(signaled); + Assert.AreEqual(source, mediaElement.Source); + Assert.IsTrue(signaled); } - [Fact] + [Test] public void TestSourceDoubleSet() { var mediaElement = new MediaElement { Source = MediaSource.FromFile("Video.mp4") }; @@ -45,7 +45,7 @@ public void TestSourceDoubleSet() Assert.False(signaled); } - [Fact] + [Test] public void TestFileMediaSourceChanged() { var source = (FileMediaSource)MediaSource.FromFile("Video.mp4"); @@ -57,32 +57,35 @@ public void TestFileMediaSourceChanged() }; source.File = "Other.mp4"; - Assert.Equal("Other.mp4", source.File); + Assert.AreEqual("Other.mp4", source.File); - Assert.True(signaled); + Assert.IsTrue(signaled); } - [Fact] + [Test] public void TestSourceRoundTrip() { var uri = new Uri("https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"); var media = new MediaElement(); + Assert.Null(media.Source); + media.Source = uri; - Assert.NotNull(media.Source); - Assert.IsType(media.Source); - Assert.Equal(uri, ((UriMediaSource?)media.Source)?.Uri); + + Assert.IsNotNull(media.Source); + Assert.IsInstanceOf(media.Source); + Assert.AreEqual(uri, ((UriMediaSource?)media.Source)?.Uri); } - [Fact] + [Test] public void TestDefaultValueForShowsPlaybackControls() { var media = new MediaElement(); - Assert.True(media.ShowsPlaybackControls); + Assert.IsTrue(media.ShowsPlaybackControls); } - [Fact] + [Test] public void TestShowsPlaybackControlsSet() { var media = new MediaElement { ShowsPlaybackControls = false }; diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaSource_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaSource_Tests.cs index 743de0d8b..c91bf6d80 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaSource_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/MediaSource_Tests.cs @@ -1,124 +1,139 @@ using System; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Views { public class MediaSource_Tests { - [Fact] + [Test] public void TestConstructors() { var filesource = new Core.FileMediaSource { File = "File.mp4" }; - Assert.Equal("File.mp4", filesource.File); + Assert.AreEqual("File.mp4", filesource.File); var urisource = new Core.UriMediaSource { Uri = new Uri("http://xamarin.com/media.mp4") }; - Assert.Equal("http://xamarin.com/media.mp4", urisource.Uri.AbsoluteUri); + Assert.AreEqual("http://xamarin.com/media.mp4", urisource.Uri.AbsoluteUri); } - [Fact] + [Test] public void TestHelpers() { var mediasource = Core.MediaSource.FromFile("File.mp4"); - Assert.IsType(mediasource); - Assert.Equal("File.mp4", ((Core.FileMediaSource)mediasource).File); + Assert.IsInstanceOf(mediasource); + Assert.AreEqual("File.mp4", ((Core.FileMediaSource)mediasource).File); var urisource = Core.MediaSource.FromUri(new Uri("http://xamarin.com/media.mp4")); - Assert.IsType(urisource); - Assert.Equal("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)urisource)?.Uri?.AbsoluteUri); + Assert.IsInstanceOf(urisource); + Assert.AreEqual("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)urisource)?.Uri?.AbsoluteUri); } - [Fact] + [Test] public void TestImplicitFileConversion() { var mediaElement = new UI.Views.MediaElement { Source = "File.mp4" }; - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("File.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("File.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); } - [Fact] + [Test] public void TestImplicitStringConversionWhenNull() { string? s = null; var sut = (Core.MediaSource?)s; - Assert.IsType(sut); + + Assert.IsInstanceOf(sut); Assert.Null(((Core.FileMediaSource?)sut)?.File); } - [Fact] + [Test] public void TestImplicitUriConversion() { var mediaElement = new UI.Views.MediaElement { Source = new Uri("http://xamarin.com/media.mp4") }; - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); } - [Fact] + [Test] public void TestImplicitStringUriConversion() { var mediaElement = new UI.Views.MediaElement { Source = "http://xamarin.com/media.mp4" }; - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); } - [Fact] + [Test] public void TestImplicitUriConversionWhenNull() { Uri? u = null; var sut = (Core.MediaSource?)u; + Assert.Null(sut); } - [Fact] + [Test] public void TestSetStringValue() { var mediaElement = new UI.Views.MediaElement(); mediaElement.SetValue(UI.Views.MediaElement.SourceProperty, "media.mp4"); - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("media.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("media.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); } - [Fact] + [Test] public void TextBindToStringValue() { var mediaElement = new UI.Views.MediaElement(); mediaElement.SetBinding(UI.Views.MediaElement.SourceProperty, "."); + Assert.Null(mediaElement.Source); + mediaElement.BindingContext = "media.mp4"; - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("media.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("media.mp4", ((Core.FileMediaSource?)mediaElement.Source)?.File); } - [Fact] + [Test] public void TextBindToStringUriValue() { var mediaElement = new UI.Views.MediaElement(); mediaElement.SetBinding(UI.Views.MediaElement.SourceProperty, "."); + Assert.Null(mediaElement.Source); + mediaElement.BindingContext = "http://xamarin.com/media.mp4"; - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); } - [Fact] + [Test] public void TextBindToUriValue() { var mediaElement = new UI.Views.MediaElement(); mediaElement.SetBinding(UI.Views.MediaElement.SourceProperty, "."); + Assert.Null(mediaElement.Source); + mediaElement.BindingContext = new Uri("http://xamarin.com/media.mp4"); - Assert.NotNull(mediaElement.Source); - Assert.IsType(mediaElement.Source); - Assert.Equal("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); + + Assert.IsNotNull(mediaElement.Source); + Assert.IsInstanceOf(mediaElement.Source); + Assert.AreEqual("http://xamarin.com/media.mp4", ((Core.UriMediaSource?)mediaElement.Source)?.Uri?.AbsoluteUri); } - [Fact] + [Test] public void TestBindingContextPropagation() { var context = new object(); @@ -128,29 +143,33 @@ public void TestBindingContextPropagation() }; var source = new MockMediaSource(); mediaElement.Source = source; - Assert.Same(context, source.BindingContext); + + Assert.AreSame(context, source.BindingContext); mediaElement = new UI.Views.MediaElement(); source = new MockMediaSource(); mediaElement.Source = source; mediaElement.BindingContext = context; - Assert.Same(context, source.BindingContext); + + Assert.AreSame(context, source.BindingContext); } - [Fact] + [Test] public void ImplicitCastOnAbsolutePathsShouldCreateAFileMediaSource() { var path = "/private/var/mobile/Containers/Data/Application/B1E5AB19-F815-4B4A-AB97-BD4571D53743/Documents/temp/video.mp4"; var mediaElement = new UI.Views.MediaElement { Source = path }; - Assert.IsType(mediaElement.Source); + + Assert.IsInstanceOf(mediaElement.Source); } - [Fact] + [Test] public void ImplicitCastOnWindowsAbsolutePathsShouldCreateAFileMediaSource() { var path = "C:\\Users\\Username\\Videos\\video.mp4"; var mediaElement = new UI.Views.MediaElement { Source = path }; - Assert.IsType(mediaElement.Source); + + Assert.IsInstanceOf(mediaElement.Source); } class MockMediaSource : Core.MediaSource diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/SnackBar_Tests.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/SnackBar_Tests.cs index b9901f0e5..f32be4615 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/SnackBar_Tests.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Views/SnackBar_Tests.cs @@ -1,42 +1,41 @@ using System; using System.Threading.Tasks; -using NSubstitute; using Xamarin.CommunityToolkit.Extensions; using Xamarin.CommunityToolkit.UI.Views.Options; using Xamarin.Forms; -using Xunit; +using NUnit.Framework; namespace Xamarin.CommunityToolkit.UnitTests.Views { public class SnackBar_Tests { #if !NETCOREAPP - [Fact] - public async void PageExtension_DisplaySnackBarAsync_PlatformNotSupportedException() + [Test] + public void PageExtension_DisplaySnackBarAsync_PlatformNotSupportedException() { var page = new ContentPage(); - await Assert.ThrowsAsync(() => page.DisplaySnackBarAsync(Arg.Any(), Arg.Any(), Arg.Any>())); + Assert.ThrowsAsync(() => page.DisplaySnackBarAsync(string.Empty, string.Empty, () => Task.CompletedTask)); } - [Fact] - public async void PageExtension_DisplaySnackBarAsyncWithOptions_PlatformNotSupportedException() + [Test] + public void PageExtension_DisplaySnackBarAsyncWithOptions_PlatformNotSupportedException() { var page = new ContentPage(); - await Assert.ThrowsAsync(() => page.DisplaySnackBarAsync(Arg.Any())); + Assert.ThrowsAsync(() => page.DisplaySnackBarAsync(new SnackBarOptions())); } - [Fact] - public async void PageExtension_DisplayToastAsync_PlatformNotSupportedException() + [Test] + public void PageExtension_DisplayToastAsync_PlatformNotSupportedException() { var page = new ContentPage(); - await Assert.ThrowsAsync(() => page.DisplayToastAsync("message")); + Assert.ThrowsAsync(() => page.DisplayToastAsync("message")); } - [Fact] - public async void PageExtension_DisplayToastAsyncWithOptions_PlatformNotSupportedException() + [Test] + public void PageExtension_DisplayToastAsyncWithOptions_PlatformNotSupportedException() { var page = new ContentPage(); - await Assert.ThrowsAsync(() => page.DisplayToastAsync(Arg.Any())); + Assert.ThrowsAsync(() => page.DisplayToastAsync(new ToastOptions())); } #endif } diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj index 3f9d87442..2614e2f23 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj @@ -1,31 +1,21 @@  - - netcoreapp2.1;netcoreapp3.1 - false - - - + netcoreapp2.1;netcoreapp3.1;net461 false - - - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all + runtime; build; native; contentfiles; analyzers; buildtransitive all - - runtime; build; native; contentfiles; analyzers; buildtransitive - all -