public void When_called_should_execute_methods_on_message_handler()
        {
            // Arrange
            var waitHandler = new AutoResetEvent(false);
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For<IMessageHandler>();
            msgHandler.When(x => x.HandleMessage(Arg.Any<IBasicConsumer>(), Arg.Any<BasicDeliverEventArgs>()))
                      .Do(callInfo => waitHandler.Set());
            var consumer = new BurrowConsumerForTest(model, msgHandler,
                                                     Substitute.For<IRabbitWatcher>(), true, 3);

            // Action
            consumer.Queue.Enqueue(new BasicDeliverEventArgs
            {
                BasicProperties = Substitute.For<IBasicProperties>()
            });
            waitHandler.WaitOne();


            // Assert
            msgHandler.Received().BeforeHandlingMessage(consumer, Arg.Any<BasicDeliverEventArgs>());
            msgHandler.DidNotReceive().HandleError(Arg.Any<IBasicConsumer>(), Arg.Any<BasicDeliverEventArgs>(), Arg.Any<Exception>());
            consumer.Dispose();
        }
Beispiel #2
0
        public void Should_do_nothing_if_not_connected()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            var msgHandler = Substitute.For<IMessageHandler>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, Substitute.For<IRabbitWatcher>(), true, 3) { ConsumerTag = "ConsumerTag" };

            // Action
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);


            // Assert
            model.DidNotReceive().BasicAck(Arg.Any<ulong>(), Arg.Any<bool>());
            consumer.Dispose();
        }
Beispiel #3
0
        public void Should_do_nothing_if_not_connected()
        {
            // Arrange
            var model      = Substitute.For <IModel>();
            var msgHandler = Substitute.For <IMessageHandler>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler,
                                                       Substitute.For <IRabbitWatcher>(), true, 3);

            // Action
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);


            // Assert
            model.DidNotReceive().BasicAck(Arg.Any <ulong>(), Arg.Any <bool>());
            consumer.Dispose();
        }
        public void Should_be_executed_when_the_message_was_not_handled()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For<IMessageHandler>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, Substitute.For<IRabbitWatcher>(), false, 3);


            // Action
            msgHandler.MessageWasNotHandled += Raise.Event<MessageWasNotHandledEvent>(Substitute.For<BasicDeliverEventArgs>());
            consumer.WaitHandler.WaitOne();

            // Assert
            model.Received().BasicAck(Arg.Any<ulong>(), false);
            consumer.Dispose();
        }
        public void Should_log_error_if_arrived_message_is_null()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            var msgHandler = Substitute.For<IMessageHandler>();
            var watcher = Substitute.For<IRabbitWatcher>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, watcher, true, 1) { ConsumerTag = "ConsumerTag" };
            

            // Action
            consumer.Queue.Enqueue(null);
            System.Threading.Thread.Sleep(500);

            // Assert
            watcher.Received(1).ErrorFormat("Message arrived but it's null for some reason, properly a serious BUG :D, contact author asap, release semaphore for other messages");
            consumer.Dispose();
        }
        public void Should_be_executed_when_the_message_handler_complete_message()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For<IMessageHandler>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, Substitute.For<IRabbitWatcher>(), true, 3) {ConsumerTag = "ConsumerTag"};


            // Action
            msgHandler.HandlingComplete += Raise.Event<MessageHandlingEvent>(BurrowConsumerForTest.ADeliverEventArgs);
            Assert.IsTrue(consumer.WaitHandler.WaitOne(5000), "Test wait timeout");

            // Assert
            model.Received().BasicAck(Arg.Any<ulong>(), false);
            consumer.Dispose();
        }
        public void Should_be_executed_when_the_channel_is_shutdown()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For<IMessageHandler>();
            var consumer = new BurrowConsumerForTest(model, msgHandler,
                                                     Substitute.For<IRabbitWatcher>(), true, 3);

            // Action
            model.ModelShutdown += Raise.Event<ModelShutdownEventHandler>(model, new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Shutdown"));
            

            // Assert
            consumer.WaitHandler.WaitOne();
            consumer.Dispose();
        }
Beispiel #8
0
        public void Should_log_error_if_arrived_is_null()
        {
            // Arrange
            var model      = Substitute.For <IModel>();
            var msgHandler = Substitute.For <IMessageHandler>();
            var watcher    = Substitute.For <IRabbitWatcher>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler, watcher, true, 1);

            consumer.Queue.Enqueue(null);

            // Action
            consumer.WaitAndHandleMessageDelivery();


            // Assert
            watcher.Received(1).ErrorFormat("Message arrived but it's null for some reason, properly a serious BUG :D, contact author asap, release semaphore for other messages");
        }
        public void Should_log_error_if_arrived_is_null()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            var msgHandler = Substitute.For<IMessageHandler>();
            var watcher = Substitute.For<IRabbitWatcher>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, watcher, true, 1);
            consumer.Queue.Enqueue(null);

            // Action
            consumer.WaitAndHandleMessageDelivery();


            // Assert
            watcher.Received(1).ErrorFormat("Message arrived but it's null for some reason, properly a serious BUG :D, contact author asap, release semaphore for other messages");

        }
Beispiel #10
0
        public void Should_do_nothing_if_already_disposed()
        {
            // Arrange
            var waitHandler = new ManualResetEvent(false);
            var model = Substitute.For<IModel>();
            var consumer = new BurrowConsumerForTest(model, Substitute.For<IMessageHandler>(), Substitute.For<IRabbitWatcher>(), true, 3) { ConsumerTag = "ConsumerTag" };
            var queue = Substitute.For<IInMemoryPriorityQueue<GenericPriorityMessage<BasicDeliverEventArgs>>>();
            queue.When(x => x.Dequeue()).Do(callInfo => waitHandler.WaitOne());
           

            // Action
            consumer.Dispose();
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);

            // Assert
            model.DidNotReceive().BasicAck(Arg.Any<ulong>(), Arg.Any<bool>());
            waitHandler.Set();
        }
Beispiel #11
0
        public void Should_be_executed_when_the_channel_is_shutdown()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For <IMessageHandler>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler,
                                                       Substitute.For <IRabbitWatcher>(), true, 3);

            // Action
            model.ModelShutdown += Raise.Event <ModelShutdownEventHandler>(model, new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Shutdown"));


            // Assert
            consumer.WaitHandler.WaitOne();
            consumer.Dispose();
        }
        public void Should_be_executed_when_the_message_handler_complete_message()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For <IMessageHandler>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler, Substitute.For <IRabbitWatcher>(), true, 3);


            // Action
            msgHandler.HandlingComplete += Raise.Event <MessageHandlingEvent>(Substitute.For <BasicDeliverEventArgs>());
            consumer.WaitHandler.WaitOne();

            // Assert
            model.Received().BasicAck(Arg.Any <ulong>(), false);
            consumer.Dispose();
        }
Beispiel #13
0
        public void Should_do_nothing_if_already_disposed()
        {
            // Arrange
            var waitHandler = new ManualResetEvent(false);
            var model       = Substitute.For <IModel>();
            var consumer    = new BurrowConsumerForTest(model, Substitute.For <IMessageHandler>(), Substitute.For <IRabbitWatcher>(), true, 3);
            var queue       = Substitute.For <IInMemoryPriorityQueue <GenericPriorityMessage <BasicDeliverEventArgs> > >();

            queue.When(x => x.Dequeue()).Do(callInfo => waitHandler.WaitOne());


            // Action
            consumer.Dispose();
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);

            // Assert
            model.DidNotReceive().BasicAck(Arg.Any <ulong>(), Arg.Any <bool>());
            waitHandler.Set();
        }
Beispiel #14
0
        public void Should_catch_AlreadyClosedException()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            model.When(x => x.BasicAck(Arg.Any<ulong>(), Arg.Any<bool>()))
                 .Do(callInfo => { throw new AlreadyClosedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Shutdown")); });

            var msgHandler = Substitute.For<IMessageHandler>();
            var watcher = Substitute.For<IRabbitWatcher>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, watcher, true, 3) { ConsumerTag = "ConsumerTag" };

            // Action
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);


            // Assert
            watcher.Received().WarnFormat(Arg.Any<string>(), Arg.Any<object[]>());
            consumer.Dispose();
        }
        public void Should_log_error_if_arrived_message_is_null()
        {
            // Arrange
            var model      = Substitute.For <IModel>();
            var msgHandler = Substitute.For <IMessageHandler>();
            var watcher    = Substitute.For <IRabbitWatcher>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler, watcher, true, 1)
            {
                ConsumerTag = "ConsumerTag"
            };


            // Action
            consumer.Queue.Enqueue(null);
            System.Threading.Thread.Sleep(500);

            // Assert
            watcher.Received(1).ErrorFormat("Message arrived but it's null for some reason, properly a serious BUG :D, contact author asap, release semaphore for other messages");
            consumer.Dispose();
        }
Beispiel #16
0
        public void Should_catch_IOException()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.IsOpen.Returns(true);
            model.When(x => x.BasicAck(Arg.Any <ulong>(), Arg.Any <bool>()))
            .Do(callInfo => { throw new IOException(); });

            var msgHandler = Substitute.For <IMessageHandler>();
            var watcher    = Substitute.For <IRabbitWatcher>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler, watcher, true, 3);

            // Action
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);


            // Assert
            watcher.Received().WarnFormat(Arg.Any <string>(), Arg.Any <object[]>());
            consumer.Dispose();
        }
        public void Should_be_executed_when_the_message_was_not_handled()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.IsOpen.Returns(true);
            var msgHandler = Substitute.For <IMessageHandler>();
            var consumer   = new BurrowConsumerForTest(model, msgHandler, Substitute.For <IRabbitWatcher>(), false, 3)
            {
                ConsumerTag = "ConsumerTag"
            };


            // Action
            msgHandler.MessageWasNotHandled += Raise.Event <MessageWasNotHandledEvent>(BurrowConsumerForTest.ADeliverEventArgs);
            Assert.IsTrue(consumer.WaitHandler.WaitOne(5000), "Test wait timeout");

            // Assert
            model.Received().BasicAck(Arg.Any <ulong>(), false);
            consumer.Dispose();
        }
Beispiel #18
0
        public void Should_throw_other_Exceptions()
        {
            // Arrange
            var model = Substitute.For<IModel>();
            model.IsOpen.Returns(true);
            model.When(x => x.BasicAck(Arg.Any<ulong>(), Arg.Any<bool>()))
                 .Do(callInfo => { throw new Exception(); });

            var msgHandler = Substitute.For<IMessageHandler>();
            var watcher = Substitute.For<IRabbitWatcher>();
            var consumer = new BurrowConsumerForTest(model, msgHandler, watcher, true, 3);

            // Action
            consumer.DoAckForTest(new BasicDeliverEventArgs(), consumer);


            // Assert
            watcher.DidNotReceive().WarnFormat(Arg.Any<string>(), Arg.Any<object[]>());
            consumer.Dispose();
        }