Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to TUnit #134

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="6.0.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Scriban" Version="5.10.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="TUnit" Version="0.1.1043" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageVersion Include="Verify.Xunit" Version="26.6.0" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Verify.TUnit" Version="27.0.1" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions tests/Immediate.Handlers.FunctionalTests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1822.severity = none # CA1822: Mark members as static
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Xunit;

namespace Immediate.Handlers.FunctionalTests.Behavior;

public sealed class BehaviorTests
Expand All @@ -12,7 +10,7 @@ public override async ValueTask<int> HandleAsync(int request, CancellationToken
}
}

[Fact]
[Test]
public void CannotSetHandlerTwice()
{
var handler = new TestBehavior();
Expand All @@ -21,7 +19,7 @@ public void CannotSetHandlerTwice()
handler.SetInnerHandler(handler));
}

[Fact]
[Test]
public async Task MustSetHandlerBeforeCallingNext()
{
var handler = new TestBehavior();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Immediate.Handlers.FunctionalTests.Behavior.Constraints;

Expand All @@ -20,7 +19,7 @@ private static ValueTask<int> Handle(

public sealed partial class Tests
{
[Fact]
[Test]
public async Task BehaviorShouldConstrain_A()
{
IServiceCollection services = new ServiceCollection();
Expand All @@ -33,6 +32,6 @@ public async Task BehaviorShouldConstrain_A()

var behaviorWalker = serviceProvider.GetRequiredService<BehaviorWalker>();

Assert.Equal(["BehaviorA"], behaviorWalker.BehaviorsRan);
_ = await Assert.That(behaviorWalker.BehaviorsRan).IsEquivalentCollectionTo(["BehaviorA"]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

#pragma warning disable CA1707
namespace Immediate.Handlers.FunctionalTests.Behavior.Constraints;
Expand All @@ -21,7 +20,7 @@ private static ValueTask<int> Handle(

public sealed partial class Tests
{
[Fact]
[Test]
public async Task BehaviorShouldConstrain_B()
{
IServiceCollection services = new ServiceCollection();
Expand All @@ -34,6 +33,8 @@ public async Task BehaviorShouldConstrain_B()

var behaviorWalker = serviceProvider.GetRequiredService<BehaviorWalker>();

Assert.Equal(["BehaviorA", "BehaviorB"], behaviorWalker.BehaviorsRan);
_ = await Assert
.That(behaviorWalker.BehaviorsRan)
.IsEquivalentCollectionTo(["BehaviorA", "BehaviorB"]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

#pragma warning disable CA1707
namespace Immediate.Handlers.FunctionalTests.Behavior.Constraints;
Expand All @@ -21,7 +20,7 @@ private static ValueTask<int> Handle(

public sealed partial class Tests
{
[Fact]
[Test]
public async Task BehaviorShouldConstrain_C()
{
IServiceCollection services = new ServiceCollection();
Expand All @@ -34,6 +33,8 @@ public async Task BehaviorShouldConstrain_C()

var behaviorWalker = serviceProvider.GetRequiredService<BehaviorWalker>();

Assert.Equal(["BehaviorA", "BehaviorC"], behaviorWalker.BehaviorsRan);
_ = await Assert
.That(behaviorWalker.BehaviorsRan)
.IsEquivalentCollectionTo(["BehaviorA", "BehaviorC"]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

#pragma warning disable CA1707
namespace Immediate.Handlers.FunctionalTests.Behavior.Constraints;
Expand All @@ -21,7 +20,7 @@ private static ValueTask<int> Handle(

public sealed partial class Tests
{
[Fact]
[Test]
public async Task BehaviorShouldConstrain_D()
{
IServiceCollection services = new ServiceCollection();
Expand All @@ -34,6 +33,8 @@ public async Task BehaviorShouldConstrain_D()

var behaviorWalker = serviceProvider.GetRequiredService<BehaviorWalker>();

Assert.Equal(["BehaviorA", "BehaviorB", "BehaviorD"], behaviorWalker.BehaviorsRan);
_ = await Assert
.That(behaviorWalker.BehaviorsRan)
.IsEquivalentCollectionTo(["BehaviorA", "BehaviorB", "BehaviorD"]);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Immediate.Handlers.Shared;
using Xunit;
using Immediate.Handlers.Shared;

namespace Immediate.Handlers.FunctionalTests.HandlerAbstraction;

Expand All @@ -18,7 +17,7 @@ private static ValueTask<int> HandleAsync(

public class HandlerAbstractionTests
{
[Fact]
[Test]
public async Task NoBehaviorShouldReturnExpectedResponseForAbstraction()
{
const int Input = 1;
Expand All @@ -29,6 +28,6 @@ public async Task NoBehaviorShouldReturnExpectedResponseForAbstraction()

var result = await handler.HandleAsync(query);

Assert.Equal(Input + 1, result);
_ = await Assert.That(result).IsEqualTo(Input + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="All" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="TUnit" />
<PackageReference Include="Verify.TUnit" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Immediate.Handlers.Shared;
using Xunit;

namespace Immediate.Handlers.FunctionalTests.MultipleBehaviors;

Expand Down Expand Up @@ -54,7 +53,7 @@ private static async ValueTask<int> HandleAsync(Query query, CancellationToken c

public sealed class MultipleBehaviorsTests
{
[Fact]
[Test]
public async Task TestBehaviorOrdering()
{
var query = new MultipleBehaviorHandler.Query();
Expand All @@ -63,16 +62,16 @@ public async Task TestBehaviorOrdering()

_ = await handler.HandleAsync(query);

Assert.Equal(
[
_ = await Assert
.That(query)
.IsEquivalentCollectionTo([
"Behavior1.Enter",
"Behavior2.Enter",
"Behavior1.Enter",
"Query.HandleAsync",
"Behavior1.Exit",
"Behavior2.Exit",
"Behavior1.Exit",
],
query);
]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Immediate.Handlers.FunctionalTests.NoBehaviors;

Expand All @@ -22,7 +21,7 @@ public record AddendProvider(int Addend);

public class ParameterizedTests
{
[Fact]
[Test]
public async Task NoBehaviorShouldReturnExpectedResponse()
{
const int Input = 1;
Expand All @@ -34,6 +33,6 @@ public async Task NoBehaviorShouldReturnExpectedResponse()

var result = await handler.HandleAsync(query);

Assert.Equal(Input + addendProvider.Addend, result);
_ = await Assert.That(result).IsEqualTo(Input + addendProvider.Addend);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Immediate.Handlers.Shared;
using Xunit;

namespace Immediate.Handlers.FunctionalTests.NoBehaviors;

Expand Down Expand Up @@ -31,7 +30,7 @@ Query query

public class ParameterlessTests
{
[Fact]
[Test]
public async Task NoBehaviorShouldReturnExpectedResponse()
{
const int Input = 1;
Expand All @@ -42,10 +41,10 @@ public async Task NoBehaviorShouldReturnExpectedResponse()

var result = await handler.HandleAsync(query);

Assert.Equal(Input + 1, result);
_ = await Assert.That(result).IsEqualTo(Input + 1);
}

[Fact]
[Test]
public async Task NoTokenShouldReturnExpectedResponse()
{
const int Input = 1;
Expand All @@ -56,6 +55,6 @@ public async Task NoTokenShouldReturnExpectedResponse()

var result = await handler.HandleAsync(query);

Assert.Equal(Input + 1, result);
_ = await Assert.That(result).IsEqualTo(Input + 1);
}
}
1 change: 1 addition & 0 deletions tests/Immediate.Handlers.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.cs]

dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1822.severity = none # CA1822: Mark members as static
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.BehaviorAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task BehaviorTypeDoesNotHaveTwoGenericParameters_Alerts() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<BehaviorsAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.BehaviorAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task BehaviorTypeDoesNotInheritFromGenericBehavior_Alerts() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<BehaviorsAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.BehaviorAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task BehaviorTypeDoesNotUseUnboundedReference_Alerts() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<BehaviorsAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.BehaviorAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task BehaviorTypeIsUsedMoreThanOnce_Alerts() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<BehaviorsAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.BehaviorAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task BehaviorTypeIsValid_DoesNotAlert() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<BehaviorsAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodDoesNotExist_AlertDiagnostic() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodDoesNotReturnTask_AlertDiagnostic() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodIsCorrectWithIntReturn_DoesNotAlert() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodIsCorrectWithVoidReturn_DoesNotAlert() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodIsNotPrivate_AlertDiagnostic() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodIsNotStatic_AlertDiagnostic() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Immediate.Handlers.Tests.AnalyzerTests.HandlerClassAnalyzerTests;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
{
[Fact]
[Test]
public async Task HandleMethodIsNotUnique_AlertDiagnostic() =>
await AnalyzerTestHelpers.CreateAnalyzerTest<HandlerClassAnalyzer>(
"""
Expand Down
Loading