-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
decf327
commit 1516721
Showing
2 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
tests/Immediate.Handler.FunctionalTests/NoBehaviors/ParameterizedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters