Esempio n. 1
0
        public void ReadFromQueueFailure()
        {
            var modelMock  = new Mock <IModel>();
            var connection = new Mock <IConnection>(MockBehavior.Strict);

            modelMock.Setup(m => m.QueueDeclare("QueueName", true, false, false, null)).Returns(new RabbitMQ.Client.QueueDeclareOk("QueueName", 0, 1));
            var model            = modelMock.Object;
            var consumer         = new EventingBasicConsumer(model);
            var connectonFactory = new Mock <ConnectionFactory>();

            connection.Setup(c => c.CreateModel()).Returns(model);
            connection.SetupProperty(c => c.AutoClose);
            connectonFactory.Setup(c => c.CreateConnection()).Returns(connection.Object);

            var queueConsumerService = new QueueConsumerService(_loggerFactory, _metricsRepo);

            queueConsumerService.EventingBasicConsumer = consumer;
            Assert.NotNull(queueConsumerService);
            Assert.True(queueConsumerService.Connect(connectonFactory.Object));

            Action <string, QueueConsumerService, ulong, QueueMetric> onDequeue = (string message, QueueConsumerService service, ulong deliveryTag, QueueMetric queueMetric) => {
                throw new Exception("Unexpected exception");
            };
            Action <Exception, QueueConsumerService, ulong, QueueMetric> onError = (Exception error, QueueConsumerService service, ulong deliveryTag, QueueMetric queueMetric) => {
                Assert.NotNull(error); // not expecting error
                Assert.Equal(error.Message, "Unexpected exception");
            };

            queueConsumerService.ReadFromQueue(onDequeue, onError, "ExchangeName", "QueueName", "RoutingKeyName");

            queueConsumerService.EventingBasicConsumer.HandleBasicDeliver("", It.IsAny <ulong>(), false,
                                                                          "ExchangeName", "RoutingKeyName", null, Encoding.ASCII.GetBytes("the message body"));
        }
Esempio n. 2
0
        public void CanConnect()
        {
            var queueConsumerService = new QueueConsumerService(_loggerFactory, _metricsRepo);

            Assert.NotNull(queueConsumerService);
            Assert.True(queueConsumerService.Connect(_connectionFactory));
        }
Esempio n. 3
0
        public QueueManagerTests(ITestOutputHelper output)
        {
            _output = output;
            //Set URL of the WS

            _settings = new Settings()
            {
                QueueUrl = "localhost"
            };
            _options = Options.Create(_settings);
            _queueConsumerService = new QueueConsumerService(_options);
            _queueProducerService = new QueueProducerService(_options);
        }
Esempio n. 4
0
        public void CanCreateInstance()
        {
            var queueConsumerService = new QueueConsumerService(_loggerFactory, _metricsRepo);

            Assert.NotNull(queueConsumerService);
        }
Esempio n. 5
0
        private static QueueConsumerService QueueConsumerService()
        {
            QueueConsumerService queueManager = new QueueConsumerService(_settings);

            return(queueManager);
        }