public async Task PublishAsync_SampleMessage_IncreaseMessageHandlerShouldNotReceiveMessage() { // Arrange IServiceCollection services = new ServiceCollection(); services.AddSingleton <IMessageBus, InMemoryMessageBus>(); services.AddSingleton <SampleMessageHandler>(); services.AddSingleton <ToLowerSampleMessageHandler>(); services.AddSingleton <IncreaseMessageHandler>(); IServiceProvider provider = services.BuildServiceProvider(); IMessageBus messageBus = provider.GetRequiredService <IMessageBus>(); SampleMessageHandler sampleMessageHandler = provider.GetRequiredService <SampleMessageHandler>(); ToLowerSampleMessageHandler toLowerSampleMessageHandler = provider.GetRequiredService <ToLowerSampleMessageHandler>(); IncreaseMessageHandler increaseMessageHandler = provider.GetRequiredService <IncreaseMessageHandler>(); messageBus.Subscribe <SampleMessageHandler, SampleMessage>(); messageBus.Subscribe <ToLowerSampleMessageHandler, SampleMessage>(); messageBus.Subscribe <IncreaseMessageHandler, IncreaseMessage>(); var sampleMessage = new SampleMessage("Hello Test"); // Act await messageBus.PublishAsync(sampleMessage); // Assert Assert.AreEqual("Hello Test", sampleMessageHandler.MyMessage); Assert.AreEqual("hello test", toLowerSampleMessageHandler.MyMessage); Assert.AreEqual(0, increaseMessageHandler.Value); }
public async Task PublishAsync_SampleMessage_MessageHandlerHasSampleMessageReceived() { // Arrange IServiceCollection services = new ServiceCollection(); services.AddSingleton <IMessageBus, InMemoryMessageBus>(); services.AddSingleton <SampleMessageHandler>(); IServiceProvider provider = services.BuildServiceProvider(); IMessageBus messageBus = provider.GetRequiredService <IMessageBus>(); SampleMessageHandler sampleMessageHandler = provider.GetRequiredService <SampleMessageHandler>(); messageBus.Subscribe <SampleMessageHandler, SampleMessage>(); var sampleMessage = new SampleMessage("Hello Test"); // Act await messageBus.PublishAsync(sampleMessage); // Assert Assert.AreEqual("Hello Test", sampleMessageHandler.MyMessage); }