Skip to content

Commit

Permalink
- Added parameterized handler test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sossenbinder committed Jan 7, 2024
1 parent decf327 commit 1516721
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Immediate.Handlers.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Immediate.Handler.FunctionalTests.NoBehaviors;

[Handler]
public static partial class NoBehaviorParameterizedOneAdder
{
public sealed record Query(int Input);

private static Task<int> HandleAsync(
Query query,
AddendProvider addendProvider,
CancellationToken _)
{
return Task.FromResult(query.Input + addendProvider.Addend);
}
}

public class AddendProvider
{
#pragma warning disable CA1822
public int Addend => 1;
#pragma warning restore CA1822
}

public class ParameterizedTests
{
[Fact]
public async Task NoBehaviorShouldReturnExpectedResponse()
{
const int Input = 1;

var serviceProvider = new ServiceCollection()
.AddHandlers()
.AddScoped<AddendProvider>()
.BuildServiceProvider();

var handler = serviceProvider.GetRequiredService<NoBehaviorParameterizedOneAdder.Handler>();

var query = new NoBehaviorParameterizedOneAdder.Query(Input);

var result = await handler.HandleAsync(query);

Assert.Equal(Input + serviceProvider.GetRequiredService<AddendProvider>().Addend, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Immediate.Handler.FunctionalTests;
namespace Immediate.Handler.FunctionalTests.NoBehaviors;

[Handler]
public static partial class OneAdder
public static partial class NoBehaviorParameterlessOneAdder
{
public sealed record Query(int Input);

Expand All @@ -17,21 +17,23 @@ private static Task<int> HandleAsync(
}
}

public class NoBehaviorTests
public class ParameterlessTests
{
[Fact]
public async Task NoBehaviorShouldReturnExpectedResponse()
{
const int Input = 1;

var serviceProvider = new ServiceCollection()
.AddHandlers()
.BuildServiceProvider();

var handler = serviceProvider.GetRequiredService<OneAdder.Handler>();
var handler = serviceProvider.GetRequiredService<NoBehaviorParameterlessOneAdder.Handler>();

var query = new OneAdder.Query(1);
var query = new NoBehaviorParameterlessOneAdder.Query(Input);

var result = await handler.HandleAsync(query);

Assert.Equal(query.Input + 1, result);
Assert.Equal(Input + 1, result);
}
}

0 comments on commit 1516721

Please sign in to comment.