Beispiel #1
0
        public void WhenPublishMessageWithoutHeaders_ThenCreatesNewHeaders()
        {
            var message = new FooMessage {
                Id = 5
            };
            var handler = new Mock <IMessageHandler <BaseMessage> >();

            var bus = new MessageBus <Message>(new[] { handler.Object });

            bus.Publish(message);

            handler.Verify(x => x.Handle(message, It.Is <IDictionary <string, object> >(d => d != null && d.Count == 0)));
        }
Beispiel #2
0
        public void WhenHandlerRegisteredForSpecificType_ThenInvokesHandler()
        {
            var message = new FooMessage {
                Id = 5
            };
            var handler = new Mock <IMessageHandler <FooMessage> >();

            var bus = new MessageBus <Message>(new[] { handler.Object });

            bus.Publish(message);

            handler.Verify(x => x.Handle(It.IsAny <FooMessage>(), It.IsAny <IDictionary <string, object> >()));
        }
Beispiel #3
0
        public void WhenAsyncHandlerRegisteredForSpecificType_ThenCanUseDefaultAsynRunner()
        {
            var message = new FooMessage {
                Id = 5
            };
            var handler = new Mock <IMessageHandler <FooMessage> >();

            handler.Setup(x => x.IsAsync).Returns(true);

            var bus = new MessageBus <Message>(new[] { handler.Object });

            bus.Publish(message);

            handler.Verify(x => x.Handle(It.IsAny <FooMessage>(), It.IsAny <IDictionary <string, object> >()), Times.Never());
        }
Beispiel #4
0
        public void WhenAsyncHandlerRegisteredForSpecificType_ThenInvokesAsyncRunner()
        {
            var message = new FooMessage {
                Id = 5
            };
            var handler = new Mock <IMessageHandler <FooMessage> >();

            handler.Setup(x => x.IsAsync).Returns(true);
            var             asyncCalled = false;
            Action <Action> asyncRunner = action => asyncCalled = true;

            var bus = new MessageBus <Message>(new[] { handler.Object }, asyncRunner);

            bus.Publish(message);

            handler.Verify(x => x.Handle(It.IsAny <FooMessage>(), It.IsAny <IDictionary <string, object> >()), Times.Never());
            Assert.True(asyncCalled);
        }