public async Task ShouldSendAllMessagesToMultipleMessageHandlers() { // Given int numberOfHandlers = 10; int expectedMessageHandlerInvocationCount = 5; int actualMessageHandlerInvocationCount = 0; IMessageHandlerResolver resolver = CreateMultiMessageHandlerResolver(registration => { // Register 10 handlers. for (int i = 0; i < numberOfHandlers; i++) { registration.Register <TestMessage>((message, ct) => { actualMessageHandlerInvocationCount++; return(Task.CompletedTask); }); } }); MessageDelegator messageDelegator = CreateMessageDelegator(resolver); // Instance messages. IEnumerable <TestMessage> messages = Enumerable.Range(0, expectedMessageHandlerInvocationCount).Select(i => new TestMessage()); // When await messageDelegator.SendAllAsync(messages); // Then int totalInvocationCount = numberOfHandlers * expectedMessageHandlerInvocationCount; actualMessageHandlerInvocationCount.Should().Be(totalInvocationCount); }
public async Task ShouldSendAllMessagesToASingleMessageHandler() { // Given int expectedMessageHandlerInvocationCount = 5; int actualMessageHandlerInvocationCount = 0; IMessageHandlerResolver resolver = CreateSingleMessageHandlerResolver(registration => { registration.Register <TestMessage>((message, ct) => { actualMessageHandlerInvocationCount++; return(Task.CompletedTask); }); }); MessageDelegator messageDelegator = CreateMessageDelegator(resolver); // Instance messages. IEnumerable <TestMessage> messages = Enumerable.Range(0, expectedMessageHandlerInvocationCount).Select(i => new TestMessage()); // When await messageDelegator.SendAllAsync(messages); // Then actualMessageHandlerInvocationCount.Should().Be(expectedMessageHandlerInvocationCount); }