示例#1
0
        public async Task NotifyFault()
        {
            var expectedException = new Exception("Unhandled exception");

            var args = new BasicDeliverEventArgs
            {
                DeliveryTag     = 1234L,
                BasicProperties = new BasicProperties()
            };

            var realConsumer = new Mock <Consumer <FakeConsumedMessage> >();
            var message      = new FakeConsumedMessage(args, _ => new Success(_, new ConsumedMessage.ConsumingResult[] { new ConsumingResultStub(_, realConsumer.Object) }));
            var builder      = new Mock <IConsumedMessageBuilder>();

            builder.Setup(_ => _.Build(It.IsAny <BasicDeliverEventArgs>())).Returns(message);

            var configuration = new ConsumingConfiguration(new Mock <IBroker>().Object, default(Queue));

            configuration.Consumes(realConsumer.Object);

            var failingInboundChannel = new FailingInboundChannel(expectedException);

            var consumer = new AtLeastOnceConsumerWrapper(failingInboundChannel, new Mock <IOutboundChannel>().Object, default(Queue), builder.Object, configuration);
            await consumer.CallConsumeInternal(args);

            realConsumer.Verify(_ => _.OnError(expectedException));
        }
示例#2
0
 private static Mock<IModel> BuildModel(UInt64 deliveryTag,
                                        Func<ConsumedMessageBase, AggregateConsumingResult> func)
 {
     var args = new BasicDeliverEventArgs
                    {
                        DeliveryTag = deliveryTag,
                        BasicProperties = new BasicProperties()
                    };
     var configuration = new SubscriptionConfiguration();
     var builder = new Mock<IConsumedMessageBuilder>();
     var message = new FakeConsumedMessage(args, func);
     builder.Setup(_ => _.Build(args)).Returns(message);
     var model = new Mock<IModel>();
     var consumer = new AtLeastOnceConsumerWrapper(model.Object, builder.Object, configuration);
     consumer.CallConsumeInternal(args).Wait();
     return model;
 }
示例#3
0
        private static Mock <IInboundChannel> BuildInboundChannel(UInt64 deliveryTag,
                                                                  Func <ConsumedMessageBase, AggregateConsumingResult> func,
                                                                  ConsumingConfiguration configuration)
        {
            var args = new BasicDeliverEventArgs
            {
                DeliveryTag     = deliveryTag,
                BasicProperties = new BasicProperties()
            };
            var builder = new Mock <IConsumedMessageBuilder>();
            var message = new FakeConsumedMessage(args, func);

            builder.Setup(_ => _.Build(args)).Returns(message);
            var channel  = new Mock <IInboundChannel>();
            var consumer = new AtLeastOnceConsumerWrapper(channel.Object,
                                                          new Mock <IOutboundChannel>().Object,
                                                          default(Queue),
                                                          builder.Object,
                                                          configuration);

            consumer.CallConsumeInternal(args).Wait();
            return(channel);
        }
示例#4
0
 private static Mock<IInboundChannel> BuildInboundChannel(UInt64 deliveryTag,
                                                          Func<ConsumedMessageBase, AggregateConsumingResult> func,
                                                          ConsumingConfiguration configuration)
 {
     var args = new BasicDeliverEventArgs
                    {
                        DeliveryTag = deliveryTag,
                        BasicProperties = new BasicProperties()
                    };
     var builder = new Mock<IConsumedMessageBuilder>();
     var message = new FakeConsumedMessage(args, func);
     builder.Setup(_ => _.Build(args)).Returns(message);
     var channel = new Mock<IInboundChannel>();
     var consumer = new AtLeastOnceConsumerWrapper(channel.Object,
                                                   new Mock<IOutboundChannel>().Object,
                                                   default(Queue),
                                                   builder.Object,
                                                   configuration);
     consumer.CallConsumeInternal(args).Wait();
     return channel;
 }