forked from MassTransit/MassTransit
-
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.
Added test to ensure the test harness observes messages published via…
… the bus
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace MassTransit.Tests.Testing | ||
{ | ||
using System.Threading.Tasks; | ||
using MassTransit.Testing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
|
||
[TestFixture] | ||
public class BusPublish_Specs | ||
{ | ||
[Test] | ||
public async Task Should_observe_published_event() | ||
{ | ||
//Arrange | ||
var provider = new ServiceCollection() | ||
.AddScoped<IMyApplicationService, MyApplicationService>() | ||
.AddMassTransitTestHarness() | ||
.BuildServiceProvider(true); | ||
|
||
var harness = provider.GetTestHarness(); | ||
|
||
await harness.Start(); | ||
|
||
var service = harness.Scope.ServiceProvider.GetRequiredService<IMyApplicationService>(); | ||
|
||
await service.Register(); | ||
|
||
Assert.That(await harness.Published.Any<MyMessage>()); | ||
} | ||
|
||
|
||
public class MyMessage | ||
{ | ||
} | ||
|
||
|
||
public interface IMyApplicationService | ||
{ | ||
Task Register(); | ||
} | ||
|
||
|
||
class MyApplicationService : | ||
IMyApplicationService | ||
{ | ||
readonly IBus _bus; | ||
|
||
public MyApplicationService(IBus bus) | ||
{ | ||
_bus = bus; | ||
} | ||
|
||
public async Task Register() | ||
{ | ||
await _bus.Publish(new MyMessage()); | ||
} | ||
} | ||
} | ||
} |