Example #1
0
        public void ShouldExecuteTheCorrectBaseMessageHandlers()
        {
            // Arrange
            var messageProcessor = new MessageHandlerProcessor(_mockContainer.Object);

            var message1HandlerReference = new HandlerReference
            {
                HandlerType = typeof(FakeBaseMessageHandler1),
                MessageType = typeof(FakeBaseMessage1)
            };

            _mockContainer.Setup(x => x.GetHandlerTypes(typeof(IMessageHandler <FakeBaseMessage1>))).Returns(new List <HandlerReference>
            {
                message1HandlerReference
            });

            var fakeHandler = new FakeBaseMessageHandler1();

            _mockContainer.Setup(x => x.GetInstance(typeof(FakeBaseMessageHandler1))).Returns(fakeHandler);

            // Act
            var message = new FakeDerivedMessage1(Guid.NewGuid())
            {
                Status = "Test"
            };

            messageProcessor.ProcessMessage <FakeDerivedMessage1>(JsonConvert.SerializeObject(message), null);

            // Assert
            Assert.Equal(message.CorrelationId, fakeHandler.Command.CorrelationId);
            Assert.Equal(message.Username, fakeHandler.Command.Username);
            _mockContainer.Verify(x => x.GetInstance(typeof(FakeBaseMessageHandler1)), Times.Once);
        }
        public void ShouldExecuteTheCorrectBaseMessageHandlers()
        {
            // Arrange
            var messageProcessor = new MessageHandlerProcessor(_mockContainer.Object);

            var message1HandlerReference = new HandlerReference
            {
                HandlerType = typeof(FakeBaseMessageHandler1),
                MessageType = typeof(FakeBaseMessage1)
            };

            _mockContainer.Setup(x => x.GetHandlerTypes(typeof(IMessageHandler<FakeBaseMessage1>))).Returns(new List<HandlerReference>
            {
                message1HandlerReference
            });

            var fakeHandler = new FakeBaseMessageHandler1();
            _mockContainer.Setup(x => x.GetInstance(typeof(FakeBaseMessageHandler1))).Returns(fakeHandler);

            // Act
            var message = new FakeDerivedMessage1(Guid.NewGuid())
            {
                Status = "Test"
            };

            messageProcessor.ProcessMessage<FakeDerivedMessage1>(JsonConvert.SerializeObject(message), null);

            // Assert
            Assert.Equal(message.CorrelationId, fakeHandler.Command.CorrelationId);
            Assert.Equal(message.Username, fakeHandler.Command.Username);
            _mockContainer.Verify(x => x.GetInstance(typeof(FakeBaseMessageHandler1)), Times.Once);
        }