コード例 #1
0
        public void StopMessageConsumer_WhenCalledWithConsumerTag_CallsLoggerTrace()
        {
            var dateTimeProvider = new Mock <IDateTimeProvider>();
            var logger           = new Mock <ILogger>();

            logger.Setup(x => x.Trace(It.IsAny <string>()));
            var configurationManager = new Mock <IConfigurationManager>();

            configurationManager.Setup(x => x.Get <string>("QueueUri")).Returns("amqp://*****:*****@localhost:5672");

            var model      = new Mock <IModel>();
            var connection = new Mock <IConnection>();

            connection.Setup(x => x.CreateModel()).Returns(model.Object);
            var connectionManager = new Mock <IRabbitMqConnectionManager>();

            connectionManager.Setup(x => x.Connection).Returns(connection.Object);

            var rabbitMqWrapper = new RabbitMqWrapper(dateTimeProvider.Object, logger.Object, configurationManager.Object, connectionManager.Object, _metrics);

            rabbitMqWrapper.Start();
            rabbitMqWrapper.StopMessageConsumer("TestConsumerTag");

            logger.Verify(x => x.Trace(It.Is <string>(s => s == "RabbitMqWrapper.StopMessageConsumer"),
                                       It.Is <LogItem>(li => li.Key == "Event" && li.Value() == "Message handler unsubscribed from queue"),
                                       It.Is <LogItem>(li => li.Key == "QueueName"),
                                       It.Is <LogItem>(li => li.Key == "ConsumerTag" && li.Value() == "TestConsumerTag")), Times.Once);
        }
コード例 #2
0
        public void StopMessageConsumer_WhenCalledWithNoConsumerTag_DoesNotCallLoggerTrace()
        {
            var dateTimeProvider     = new Mock <IDateTimeProvider>();
            var logger               = new Mock <ILogger>();
            var configurationManager = new Mock <IConfigurationManager>();

            configurationManager.Setup(x => x.Get <string>("QueueUri")).Returns("amqp://*****:*****@localhost:5672");

            var model      = new Mock <IModel>();
            var connection = new Mock <IConnection>();

            connection.Setup(x => x.CreateModel()).Returns(model.Object);
            var connectionManager = new Mock <IRabbitMqConnectionManager>();

            connectionManager.Setup(x => x.Connection).Returns(connection.Object);

            var rabbitMqWrapper = new RabbitMqWrapper(dateTimeProvider.Object, logger.Object, configurationManager.Object, connectionManager.Object, _metrics);

            rabbitMqWrapper.Start();
            rabbitMqWrapper.StopMessageConsumer(null);

            logger.Verify(x => x.Trace(It.IsAny <string>()), Times.Never);
        }
コード例 #3
0
        public void StopMessageConsumer_WhenCalledWithoutStart_CallsLoggerWarn()
        {
            var dateTimeProvider     = new Mock <IDateTimeProvider>();
            var logger               = new Mock <ILogger>();
            var configurationManager = new Mock <IConfigurationManager>();

            configurationManager.Setup(x => x.Get <string>("QueueUri")).Returns("amqp://*****:*****@localhost:5672");

            var model      = new Mock <IModel>();
            var connection = new Mock <IConnection>();

            connection.Setup(x => x.CreateModel()).Returns(model.Object);
            var connectionManager = new Mock <IRabbitMqConnectionManager>();

            connectionManager.Setup(x => x.Connection).Returns(connection.Object);

            var rabbitMqWrapper = new RabbitMqWrapper(dateTimeProvider.Object, logger.Object, configurationManager.Object, connectionManager.Object, _metrics);

            rabbitMqWrapper.StopMessageConsumer("TestConsumerTag");

            logger.Verify(x =>
                          x.Warn(It.Is <string>(s =>
                                                s == "RabbitMqWrapper.Start must be run before calling StopMessageConsumer")));
        }