예제 #1
0
 public ConsumerMethod(MethodInfo method, Type parentType, RabbitConsumerAttribute consumerAttributes, RabbitPublisherAttribute publisherAttributes)
 {
     this.Method              = method;
     this.ConsumerAttributes  = consumerAttributes;
     this.PublisherAttributes = publisherAttributes;
     this.ParentType          = parentType;
 }
        public void ShouldStartConsumerOnQueueNameFromConfiguration()
        {
            // GIVEN
            var configKey  = "Config:Key:For:QueueName";
            var configVal  = "nameOfQueue";
            var configDict = new Dictionary <string, string>()
            {
                { configKey, configVal }
            };
            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(configDict)
                                .Build();

            Mock <IModel> model  = new Mock <IModel>();
            var           logger = TestLogger.CreateXUnit <RabbitConsumer>(output);

            RabbitConsumerAttribute consumerAttribute = new RabbitConsumerAttribute(
                "{" + configKey + "}",
                acknowledgementType: AcknowledgementType.ManualAck,
                false
                );

            ConsumerMethod method = new ConsumerMethod(
                this.GetType().GetMethods().First(),  // Just use any old method
                this.GetType(),
                consumerAttribute,
                null
                );

            // WHEN
            new RabbitConsumer(method, model.Object, configuration, null, logger);

            // THEN
            model.Verify(m =>
                         m.BasicConsume(
                             It.Is <string>(s => s == configVal),
                             It.Is <bool>(b => b == false),
                             It.IsAny <string>(),
                             It.IsAny <bool>(),
                             It.IsAny <bool>(),
                             It.IsAny <IDictionary <string, object> >(),
                             It.IsAny <EventingBasicConsumer>()
                             )
                         );
            model.VerifyNoOtherCalls();
        }
        public void AckOnInvokeShouldStartConsumerWithoutAutoAck()
        {
            // GIVEN
            var queueName = "queueName";

            Mock <IModel> model  = new Mock <IModel>();
            var           logger = TestLogger.CreateXUnit <RabbitConsumer>(output);

            RabbitConsumerAttribute consumerAttribute = new RabbitConsumerAttribute(
                queueName,
                acknowledgementType: AcknowledgementType.AckOnInvoke,
                false
                );

            ConsumerMethod method = new ConsumerMethod(
                this.GetType().GetMethods().First(),  // Just use any old method
                this.GetType(),
                consumerAttribute,
                null
                );

            // WHEN
            new RabbitConsumer(method, model.Object, null, null, logger);

            // THEN
            model.Verify(m =>
                         m.BasicConsume(
                             It.Is <string>(s => s == queueName),
                             It.Is <bool>(b => b == false),
                             It.IsAny <string>(),
                             It.IsAny <bool>(),
                             It.IsAny <bool>(),
                             It.IsAny <IDictionary <string, object> >(),
                             It.IsAny <EventingBasicConsumer>()
                             )
                         );
            model.VerifyNoOtherCalls();
        }