Ejemplo n.º 1
0
        public void ProcessMessageWithReplyToTest()
        {
            var basicPropertiesMock = new Mock <IBasicProperties>();

            basicPropertiesMock.SetupGet(p => p.ReplyTo).Returns("replyQueue");
            var eventArgs = new BasicDeliverEventArgs("cTag", 1, false, "", "queue",
                                                      basicPropertiesMock.Object, Encoding.UTF8.GetBytes("{\"userId\": \"123\"}"));

            builderMock.Setup(b => b.BuildMessage(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new Mock <IMessage>().Object);


            processorMock.Setup(p => p.ProcessMessage(It.IsAny <IMessage>(), It.IsAny <IPublisher>()));


            var consumer = new ProtectedConsumer(channelMock.Object, publisherMock.Object,
                                                 builderMock.Object, managerMock.Object);

            consumer.Start(processorMock.Object, queueName);
            consumer.ProtectedOnMessageReceived(processorMock.Object, "queue", eventArgs);
            consumer.Stop();

            channelMock.Verify(c => c.BasicAck(1, false));
            channelMock.Verify(c => c.BasicNack(1, false, true), Times.Never);
        }
Ejemplo n.º 2
0
        private void ConsumeMessage()
        {
            var consumer = new ProtectedConsumer(_channelMock.Object, _publisherMock.Object, _builderMock.Object, _managerMock.Object, _messageProcessorMock.Object);

            consumer.Start(_processorMock.Object, QueueName);
            consumer.ProtectedOnMessageReceived(_processorMock.Object, QueueName, _basicDeliverEventArgs);
            consumer.Stop();
        }
Ejemplo n.º 3
0
        public void ConsumeSimpleMessageTest()
        {
            var eventArgs = new BasicDeliverEventArgs("cTag", 1, false, "", "queue",
                                                      new Mock <IBasicProperties>().Object, Encoding.UTF8.GetBytes("{\"userId\": \"123\"}"));

            var consumer = new ProtectedConsumer(channelMock.Object, publisherMock.Object,
                                                 builderMock.Object, managerMock.Object);

            consumer.Start(processorMock.Object, queueName);
            consumer.ProtectedOnMessageReceived(processorMock.Object, "queue", eventArgs);
            consumer.Stop();

            channelMock.Verify(c => c.BasicAck(1, false));
            channelMock.Verify(c => c.BasicNack(1, false, true), Times.Never);
        }
Ejemplo n.º 4
0
        public void ErrorProcessingMessageHandlingExceptionTest()
        {
            var eventArgs = new BasicDeliverEventArgs("cTag", 1, false, "", "queue",
                                                      new Mock <IBasicProperties>().Object, Encoding.UTF8.GetBytes("{\"userId\": \"123\"}"));

            processorMock.Setup(p => p.ProcessMessage(It.IsAny <IMessage>(), It.IsAny <IPublisher>()))
            .Throws <Exception>();
            processorMock.Setup(p => p.HandleProcessError(It.IsAny <IMessage>(), It.IsAny <IPublisher>(),
                                                          It.IsAny <Exception>())).Throws <Exception>();


            var consumer = new ProtectedConsumer(channelMock.Object, publisherMock.Object,
                                                 builderMock.Object, managerMock.Object);

            consumer.Start(processorMock.Object, queueName);
            consumer.ProtectedOnMessageReceived(processorMock.Object, "queue", eventArgs);
            consumer.Stop();

            channelMock.Verify(c => c.BasicAck(1, false), Times.Never);
            channelMock.Verify(c => c.BasicNack(1, false, true));
        }