Ejemplo n.º 1
0
        public void OnlyReceiverShouldReceiveCommands()
        {
            const string receiverGuid = "af486b11-0fad-4f5a-98d3-7308ec925708";
            var          receiverId   = new Guid(receiverGuid);

            using (var serviceBus = ServiceBusFactory.New(bus =>
            {
                bus.ReceiveFrom(Config.CommandPublisherAddress);

                bus.UseRabbitMq();
            }))
                using (var handler1 = new TestCommandHandler(new Uri(Config.CommandHandlerAddress1), receiverId, "TestCommandHandler1", 5))
                    using (var handler2 = new TestCommandHandler(new Uri(Config.CommandHandlerAddress2), "TestCommandHandler2", 1))
                    {
                        serviceBus.SendTo(new TestCommand(), receiverId);
                        serviceBus.SendTo(new TestCommand(), receiverId);
                        serviceBus.SendTo(new TestCommand(), receiverId);
                        serviceBus.SendTo(new TestCommand(), receiverId);
                        serviceBus.SendTo(new TestCommand(), receiverId);

                        handler1.CommandReceived.WaitUntilCompleted(7.Seconds());

                        Assert.IsTrue(handler1.CommandReceived.IsCompleted && !handler2.CommandReceived.IsCompleted);
                    }
        }
Ejemplo n.º 2
0
        public void ShouldReceiveSingleCommand()
        {
            using (var serviceBus = ServiceBusFactory.New(bus =>
            {
                bus.ReceiveFrom(Config.CommandPublisherAddress);
                bus.UseRabbitMq();
            }))
                using (var handler = new TestCommandHandler("TestCommandHandler", 1))
                {
                    serviceBus.Publish(new TestCommand());

                    handler.CommandReceived.WaitUntilCompleted(5.Seconds());
                    Assert.IsTrue(handler.CommandReceived.IsCompleted);
                }
        }
Ejemplo n.º 3
0
        public void AllNonCompetingHandlersShouldReceiveComands()
        {
            using (var serviceBus = ServiceBusFactory.New(bus =>
            {
                bus.ReceiveFrom(Config.CommandPublisherAddress);

                bus.UseRabbitMq();
            }))
                using (var handler1 = new TestCommandHandler(new Uri(Config.CommandHandlerAddress1), "TestCommandHandler1", 1))
                    using (var handler2 = new TestCommandHandler(new Uri(Config.CommandHandlerAddress2), "TestCommandHandler2", 1))
                    {
                        serviceBus.Publish(new TestCommand());

                        handler1.CommandReceived.WaitUntilCompleted(10.Seconds());
                        handler2.CommandReceived.WaitUntilCompleted(10.Seconds());
                        Assert.IsTrue(handler1.CommandReceived.IsCompleted && handler2.CommandReceived.IsCompleted);
                    }
        }