Skip to content

Commit

Permalink
Added test to ensure the test harness observes messages published via…
Browse files Browse the repository at this point in the history
… the bus
  • Loading branch information
phatboyg committed May 22, 2023
1 parent 9fa293c commit 5be3652
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/MassTransit.Tests/Testing/BusPublish_Specs.cs
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());
}
}
}
}

0 comments on commit 5be3652

Please sign in to comment.