public void ShouldStartAggregatorTimerIfAggregatorTimeoutIsSet() { // Arrange var mockContainer = new Mock<IBusContainer>(); var mockAggregatorPersistor = new Mock<IAggregatorPersistor>(); var mockAggregatorProcessor = new Mock<IAggregatorProcessor>(); var mockConfiguration = new Mock<IConfiguration>(); var handlerRef = new HandlerReference() { HandlerType = typeof(FakeAggregator), MessageType = typeof(FakeMessage1) }; mockContainer.Setup(x => x.GetHandlerTypes()).Returns(new List<HandlerReference> { handlerRef }); var timeout = new TimeSpan(0, 0, 0, 1); mockContainer.Setup(x => x.GetInstance(typeof(FakeAggregator))).Returns(new FakeAggregator { Time = timeout }); mockConfiguration.Setup(x => x.GetAggregatorProcessor(It.IsAny<IAggregatorPersistor>(), mockContainer.Object, typeof(FakeAggregator))).Returns(mockAggregatorProcessor.Object); mockConfiguration.Setup(x => x.GetAggregatorPersistor()).Returns(mockAggregatorPersistor.Object); mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object); mockConfiguration.Setup(x => x.AutoStartConsuming).Returns(true); mockConfiguration.Setup(x => x.TransportSettings).Returns(new TransportSettings()); mockConfiguration.Setup(x => x.GetConsumer()).Returns(new Mock<IConsumer>().Object); // Act new Bus(mockConfiguration.Object); // Assert mockAggregatorProcessor.Verify(x => x.StartTimer<FakeMessage1>(timeout), Times.Once); }
public void ShouldExecuteTheCorrectHandlers() { // Arrange var bus = new MessageBus.Bus(_mockConfiguration.Object); var message1HandlerReference = new HandlerReference { HandlerType = typeof (FakeHandler1), MessageType = typeof (FakeMessage1) }; var handlerReferences = new List<HandlerReference> { message1HandlerReference, new HandlerReference { HandlerType = typeof (FakeHandler2), MessageType = typeof (FakeMessage2) } }; _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(handlerReferences); _mockConsumer.Setup(x => x.StartConsuming(It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<string>(), It.IsAny<string>())); _mockContainer.Setup(x => x.GetHandlerTypes(typeof(IMessageHandler<FakeMessage1>))).Returns(new List<HandlerReference> { message1HandlerReference }); var fakeHandler = new FakeHandler1(); _mockContainer.Setup(x => x.GetInstance(typeof (FakeHandler1))).Returns(fakeHandler); bus.StartConsuming(); // Act var message1 = new FakeMessage1(Guid.NewGuid()) { Username = "******" }; _fakeEventHandler(Encoding.UTF8.GetBytes(_serializer.Serialize(message1))); var message2 = new FakeMessage2(Guid.NewGuid()) { DisplayName = "Tim Watson" }; _fakeEventHandler(Encoding.UTF8.GetBytes(_serializer.Serialize(message2))); // Assert Assert.Equal(message1.CorrelationId, fakeHandler.Command.CorrelationId); Assert.Equal(message1.Username, fakeHandler.Command.Username); _mockContainer.Verify(x => x.GetInstance(typeof (FakeHandler2)), Times.Never); }