예제 #1
0
        public void EnsureWithMultipleMessageTypesInterfaceHandlerIsInvoked()
        {
            var      bus = new Bus();
            Message1 receivedMessage1 = null;

            bus.AddHandler(new ActionConsumer <Message1>(m => receivedMessage1 = m));
            Message2 receivedMessage2 = null;

            bus.AddHandler(new ActionConsumer <Message2>(m => receivedMessage2 = m));
            string text = null;

            bus.AddHandler(new ActionConsumer <IEvent>(_ => { text = "ding"; }));

            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            bus.Handle(message1);
            bus.Handle(new TheEvent());
            Assert.AreSame(message1, receivedMessage1);
            Assert.IsNotNull(receivedMessage1);
            Assert.AreEqual(message1.CorrelationId, receivedMessage1.CorrelationId);
            Assert.AreEqual("ding", text);
        }
        public void DiscoveredBusAsynchronousConsumerSynchronouslyConsumesCorrectly()
        {
            var bus       = new Bus();
            var directory = Path.GetDirectoryName(new Uri(GetType().GetTypeInfo().Assembly.CodeBase).LocalPath);

            bus.AddHandlersAndTranslators(directory, "Tests*.dll", GetType().Namespace);

            var message3 = new Message3 {
                CorrelationId = "1234"
            };

            bus.Handle(message3);

            Assert.NotNull(Message3AsyncConsumer.LastMessageReceived);
            Assert.Equal(message3.CorrelationId, Message3AsyncConsumer.LastMessageReceived.CorrelationId);
        }
예제 #3
0
        public void ManuallyComposedTypeHandlesWithDuplicateHandlerMulticasts()
        {
            var bus = new Bus();

            var message2Consumer = new Message2Consumer();

            bus.AddHandler(message2Consumer);
            bus.AddHandler(message2Consumer);

            var message1 = new Message2 {
                CorrelationId = "1234"
            };

            bus.Handle(message1);
            Assert.AreEqual(2, message2Consumer.MessageReceivedCount);
        }
        public void DiscoveredBusConsumesMessageCorrectly()
        {
            var bus       = new Bus();
            var directory = Path.GetDirectoryName(new Uri(GetType().GetTypeInfo().Assembly.CodeBase).LocalPath);

            bus.AddHandlersAndTranslators(directory, "Tests*.dll", GetType().Namespace);

            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            bus.Handle(message1);

            Assert.Same(message1, Pipe.LastMessageProcessed);
            Assert.NotNull(Message2Consumer.LastMessageReceived);
            Assert.Equal(message1.CorrelationId, Message2Consumer.LastMessageReceived.CorrelationId);
        }
        public void ManuallyComposedTypeHandlesWithRemovedDuplicateHandlerDoesNotMulticasts()
        {
            var bus = new Bus();

            var message2Consumer = new Message2Consumer();
            var token1           = bus.AddHandler(message2Consumer);
            var token2           = bus.AddHandler(message2Consumer);

            bus.RemoveHandler(message2Consumer, token2);

            var message1 = new Message2 {
                CorrelationId = "1234"
            };

            bus.Handle(message1);
            Assert.AreEqual(1, message2Consumer.MessageReceivedCount);
        }
예제 #6
0
        public void BusConsumesMessagesCorrectly()
        {
            var      bus             = new Bus();
            var      directory       = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath);
            Message1 receivedMessage = null;

            bus.AddHandler(new ActionConsumer <Message1>(m => receivedMessage = m));

            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            bus.Handle(message1);

            Assert.AreSame(message1, receivedMessage);
            Assert.IsNotNull(receivedMessage);
            Assert.AreEqual(message1.CorrelationId, receivedMessage.CorrelationId);
        }
예제 #7
0
        public void BusConsumesMessagesCorrectly()
        {
            Message1 receivedMessage;
            Message1 message1;

            using (var bus = new Bus())
            {
                receivedMessage = null;
                bus.AddHandler(new ActionConsumer <Message1>(m => receivedMessage = m));

                message1 = new Message1 {
                    CorrelationId = "1234"
                };
                bus.Handle(message1);
            }

            Assert.AreSame(message1, receivedMessage);
            Assert.IsNotNull(receivedMessage);
            Assert.AreEqual(message1.CorrelationId, receivedMessage.CorrelationId);
        }
예제 #8
0
        public void ManuallyComposedWithTranslatorFirstTypeHandlesMessageProperly()
        {
            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            var bus = new Bus();

            var pipe = new Pipe();

            bus.AddTranslator(pipe);

            var message2Consumer = new Message2Consumer();

            bus.AddHandler(message2Consumer);

            bus.Handle(message1);

            Assert.AreSame(message1, Pipe.LastMessageProcessed);
            Assert.IsNotNull(Message2Consumer.LastMessageReceived);
            Assert.AreEqual(message1.CorrelationId, Message2Consumer.LastMessageReceived.CorrelationId);
        }
        public void ManuallyComposedSyncAsyncTypeSynchronouslyHandlesMessageWithAsyncConsumerProperly()
        {
            var message2 = new Message2 {
                CorrelationId = "1234"
            };

            var bus = new Bus();

            var message3Consumer = new Message3AsyncConsumer();

            bus.AddHandler(message3Consumer);

            var pipe = new Pipe23();

            bus.AddTranslator(pipe);

            bus.Handle(message2);

            Assert.AreSame(message2, Pipe23.LastMessageProcessed);
            Assert.IsNotNull(Message3AsyncConsumer.LastMessageReceived);
            Assert.AreEqual(message2.CorrelationId, Message3AsyncConsumer.LastMessageReceived.CorrelationId);
        }
예제 #10
0
        public void MessageAfterRequestWithErrorEventCancellationDoesNotThrow()
        {
            IBus bus = new Bus();

            bus.AddHandler(new ActionConsumer <Message1>(m =>
            {
                /* do nothing */
            }));

            var cancellationTokenSource = new CancellationTokenSource();
            var requestAsync            = bus.RequestAsync <Message1, TheEvent, TheErrorEvent>(
                new Message1 {
                CorrelationId = "12344321"
            },
                cancellationTokenSource.Token);

            cancellationTokenSource.Cancel();
            //await requestAsync;
            bus.Handle(new TheEvent {
                CorrelationId = "12344321"
            });
        }