Skip to content

Commit

Permalink
Update to xunit.v3
Browse files Browse the repository at this point in the history
  • Loading branch information
brminnick committed Dec 17, 2024
1 parent 05846be commit 906d00b
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 229 deletions.
8 changes: 4 additions & 4 deletions src/CommunityToolkit.Maui.UnitTests/Alerts/SnackbarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SnackbarTests : BaseTest

public SnackbarTests()
{
Assert.IsAssignableFrom<IAlert>(snackbar);
Assert.IsType<IAlert>(snackbar, exactMatch: false);
}

[Fact]
Expand Down Expand Up @@ -125,7 +125,7 @@ public async Task VisualElement_DisplaySnackbar_ShownEventReceived()
receivedEvents.Add(e);
};
var button = new Button();
await button.DisplaySnackbar("message");
await button.DisplaySnackbar("message", token: CancellationToken.None);
Assert.Single(receivedEvents);
}

Expand Down Expand Up @@ -233,8 +233,8 @@ public async Task SnackbarNullValuesThrowArgumentNullException()
});
Assert.Throws<ArgumentNullException>(() => Snackbar.Make(null));
Assert.Throws<ArgumentNullException>(() => Snackbar.Make(string.Empty, actionButtonText: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => new Button().DisplaySnackbar(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => new Button().DisplaySnackbar(string.Empty, actionButtonText: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => new Button().DisplaySnackbar(null, token: CancellationToken.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => new Button().DisplaySnackbar(string.Empty, actionButtonText: null, token: CancellationToken.None));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}
2 changes: 1 addition & 1 deletion src/CommunityToolkit.Maui.UnitTests/Alerts/ToastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ToastTests : BaseTest

public ToastTests()
{
Assert.IsAssignableFrom<IAlert>(toast);
Assert.IsType<IAlert>(toast, exactMatch: false);
}

[Fact(Timeout = (int)TestDuration.Short)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected BaseBehaviorTest(TBehavior behavior, TView view)
[Fact]
public void EnsureICommunityToolkitBehaviorIsBehavior()
{
Assert.IsAssignableFrom<Behavior>(behavior);
Assert.IsType<Behavior>(behavior, exactMatch: false);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void TestRemoveValidationBindingWithBindingContext()

view.Behaviors.Add(behavior);

Assert.IsAssignableFrom<MockValidationBehavior>(Assert.Single(view.Behaviors));
Assert.IsType<MockValidationBehavior>(Assert.Single(view.Behaviors), exactMatch: false);

view.Behaviors.Remove(behavior);

Expand All @@ -225,7 +225,7 @@ public void TestRemoveValidationBindingWithoutBindingContext()

view.Behaviors.Add(behavior);

Assert.IsAssignableFrom<MockValidationBehavior>(Assert.Single(view.Behaviors));
Assert.IsType<MockValidationBehavior>(Assert.Single(view.Behaviors), exactMatch: false);

view.Behaviors.Remove(behavior);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<OutputType>exe</OutputType>
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
Expand All @@ -12,7 +13,7 @@
<PackageReference Include="FluentAssertions.Analyzers" Version="0.34.1" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.v3" Version="1.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" PrivateAssets="All" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ public class ByteArrayToImageSourceConverterTests : BaseConverterTest<ByteArrayT
{
public static TheoryData<object> NonImageStreamData { get; } =
[
3, // primitive type
DateTime.UtcNow, // Struct

(object)3, // primitive type
(object)DateTime.UtcNow, // Struct
new object()
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class CompareConverterTests : BaseOneWayConverterTest<CompareConverter>

public static TheoryData<object> ThrowArgumentExceptionTestData { get; } =
[
new
(object)new
{
Name = "Not IComparable"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public ImageResourceConverterTests()

public static TheoryData<object> NonStringData { get; } =
[
3, // primitive type
DateTime.UtcNow, // Struct
new() // objects
(object)3, // primitive type
(object)DateTime.UtcNow, // Struct
new object() // objects
];

protected override void Dispose(bool isDisposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MultiConverterTests : BaseTest
{
public static TheoryData<List<MultiConverterParameter>> Data { get; } =
[
new()
new List<MultiConverterParameter>
{
new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CommunityToolkit.Maui.UnitTests.Mocks;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;

namespace CommunityToolkit.Maui.UnitTests.Essentials;

Expand Down Expand Up @@ -62,7 +61,7 @@ public async Task StartStopListenAsyncShouldChangeRecognitionText()
SpeechToText.Default.RecognitionResultUpdated += OnRecognitionTextUpdated;
SpeechToText.Default.RecognitionResultCompleted += OnRecognitionTextCompleted;
await SpeechToText.StartListenAsync(CultureInfo.CurrentCulture, CancellationToken.None);
await Task.Delay(500);
await Task.Delay(500, CancellationToken.None);
await SpeechToText.StopListenAsync(CancellationToken.None);
SpeechToText.Default.RecognitionResultUpdated -= OnRecognitionTextUpdated;
SpeechToText.Default.RecognitionResultCompleted -= OnRecognitionTextCompleted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task BackgroundColorTo_VerifyColorChanged()

Assert.Equal(originalBackgroundColor, element.BackgroundColor);

var isSuccessful = await element.BackgroundColorTo(updatedBackgroundColor);
var isSuccessful = await element.BackgroundColorTo(updatedBackgroundColor, token: CancellationToken.None);

Assert.True(isSuccessful);
Assert.Equal(updatedBackgroundColor, element.BackgroundColor);
Expand Down Expand Up @@ -58,7 +58,7 @@ public async Task BackgroundColorTo_VerifyColorChangedForDefaultBackgroundColor(
VisualElement element = new Label();
element.EnableAnimations();

var isSuccessful = await element.BackgroundColorTo(updatedBackgroundColor);
var isSuccessful = await element.BackgroundColorTo(updatedBackgroundColor, token: CancellationToken.None);

Assert.True(isSuccessful);
Assert.Equal(updatedBackgroundColor, element.BackgroundColor);
Expand All @@ -70,7 +70,7 @@ public async Task BackgroundColorTo_DoesNotAllowNullVisualElement()
VisualElement? element = null;

#pragma warning disable CS8603 // Possible null reference return.
await Assert.ThrowsAsync<NullReferenceException>(() => element?.BackgroundColorTo(Colors.Red));
await Assert.ThrowsAsync<NullReferenceException>(() => element?.BackgroundColorTo(Colors.Red, token: CancellationToken.None));
#pragma warning restore CS8603 // Possible null reference return.
}

Expand All @@ -81,7 +81,7 @@ public async Task BackgroundColorTo_DoesNotAllowNullColor()
element.EnableAnimations();

#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
await Assert.ThrowsAsync<ArgumentNullException>(() => element.BackgroundColorTo(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => element.BackgroundColorTo(null, token: CancellationToken.None));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}
Loading

0 comments on commit 906d00b

Please sign in to comment.