예제 #1
0
        public void ManuallyComposedTypeWithMultipleTranslatorsHandlesMessageProperly()
        {
            var message3 = new Message3 {
                CorrelationId = "1234"
            };

            var      bus              = new Bus();
            Message4 message4         = null;
            var      message2Consumer = new MyConsumer();

            bus.AddHandler(message2Consumer);
            bus.AddHandler(new ActionConsumer <Message4>(m => message4 = m));
            var pipe = new Pipe();

            bus.AddTranslator(pipe);
            bus.AddTranslator(new ActionPipe <Message3, Message4>(m => new Message4 {
                CorrelationId = m.CorrelationId
            }));

            bus.Handle(message3);

            Assert.IsNotNull(message4);
            Assert.AreEqual(message3.CorrelationId, message4.CorrelationId);
            Assert.IsNotNull(Pipe.LastMessageProcessed);
            Assert.AreEqual(message3.CorrelationId, message4.CorrelationId);
        }
        public void ManuallyComposedWithTwoTranslatorsFirstTypeHandlesMessageProperly()
        {
            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            var bus = new Bus();

            var pipe1 = new Pipe();

            bus.AddTranslator(pipe1);
            var pipe2 = new Pipe();

            bus.AddTranslator(pipe1);

            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 CompareCapacity()
        {
            var message1 = new Message1 {
                CorrelationId = "1234"
            };

            var bus = new Bus();

            bus.AddHandler(new Message2Consumer());
            bus.AddTranslator(new Pipe());
            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < 53000000; ++i)
            {
                bus.Handle(message1);
            }
            Console.WriteLine(stopwatch.Elapsed.ToEnglishString());

            var bus1      = new Bus();
            var directory = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath);

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

            stopwatch = Stopwatch.StartNew();
            for (var i = 0; i < 53000000; ++i)
            {
                bus1.Handle(message1);
            }
            Console.WriteLine(stopwatch.Elapsed.ToEnglishString());
        }
        public async Task ManuallyComposedSyncAsyncTypeAsynchronouslyHandlesMessageProperly()
        {
            var message2 = new Message2 {
                CorrelationId = "1234"
            };

            var bus = new Bus();

            var message3AsyncConsumer = new Message3AsyncConsumer();

            bus.AddHandler(message3AsyncConsumer);

            var pipe = new Pipe23();

            bus.AddTranslator(pipe);

            await bus.HandleAsync(message2);

            Assert.AreSame(message2, Pipe23.LastMessageProcessed);
            Assert.IsNotNull(Message3AsyncConsumer.LastMessageReceived);
            Assert.AreEqual(message2.CorrelationId, Message3AsyncConsumer.LastMessageReceived.CorrelationId);
        }