-
Notifications
You must be signed in to change notification settings - Fork 0
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
0e94449
commit ccb7e0f
Showing
8 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
29 changes: 29 additions & 0 deletions
29
tests/Mediator.DependencyInjection.Tests/DefaultHandler/NotificationDefaultHandlerTest.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,29 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NSubstitute; | ||
using Xunit; | ||
using Zapto.Mediator; | ||
|
||
namespace Mediator.DependencyInjection.Tests.DefaultHandler; | ||
|
||
public class NotificationDefaultHandlerTest | ||
{ | ||
[Fact] | ||
public async Task TestNotification() | ||
{ | ||
var handler = Substitute.For<IDefaultNotificationHandler>(); | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddMediator(b => b.AddDefaultNotificationHandler(handler)) | ||
.BuildServiceProvider(); | ||
|
||
var mediator = serviceProvider.GetRequiredService<IMediator>(); | ||
|
||
await mediator.Publish(new Notification()); | ||
|
||
_ = handler.Received() | ||
.Handle(Arg.Any<IServiceProvider>(), Arg.Any<Notification>(), Arg.Any<CancellationToken>()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Mediator.DependencyInjection.Tests/DefaultHandler/RequestDefaultHandlerTest.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,29 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NSubstitute; | ||
using Xunit; | ||
using Zapto.Mediator; | ||
|
||
namespace Mediator.DependencyInjection.Tests.DefaultHandler; | ||
|
||
public class RequestDefaultHandlerTest | ||
{ | ||
[Fact] | ||
public async Task TestRequest() | ||
{ | ||
var handler = Substitute.For<IDefaultRequestHandler>(); | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddMediator(b => b.AddDefaultRequestHandler(handler)) | ||
.BuildServiceProvider(); | ||
|
||
var mediator = serviceProvider.GetRequiredService<IMediator>(); | ||
|
||
await mediator.Send<Request, int>(new Request()); | ||
|
||
_ = handler.Received() | ||
.Handle<Request, int>(Arg.Any<IServiceProvider>(), Arg.Any<Request>(), Arg.Any<CancellationToken>()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Mediator.DependencyInjection.Tests/DefaultHandler/StreamRequestDefaultHandlerTest.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,35 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NSubstitute; | ||
using Xunit; | ||
using Zapto.Mediator; | ||
|
||
namespace Mediator.DependencyInjection.Tests.DefaultHandler; | ||
|
||
public class StreamRequestDefaultHandlerTest | ||
{ | ||
[Fact] | ||
public async Task TestStream() | ||
{ | ||
var handler = Substitute.For<IDefaultStreamRequestHandler>(); | ||
|
||
handler.Handle<StreamRequest, int>(Arg.Any<IServiceProvider>(), Arg.Any<StreamRequest>(), Arg.Any<CancellationToken>()) | ||
.Returns(Array.Empty<int>().ToAsyncEnumerable()); | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddMediator(b => b.AddDefaultStreamRequestHandler(handler)) | ||
.BuildServiceProvider(); | ||
|
||
var mediator = serviceProvider.GetRequiredService<IMediator>(); | ||
|
||
await mediator | ||
.CreateStream<StreamRequest, int>(new StreamRequest()) | ||
.ToListAsync(); | ||
|
||
_ = handler.Received() | ||
.Handle<StreamRequest, int>(Arg.Any<IServiceProvider>(), Arg.Any<StreamRequest>(), Arg.Any<CancellationToken>()); | ||
} | ||
} |
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
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