public void TestRespond()
        {
            // arrange
            var mq = new MessageQueueMock();

            mq.Setup();

            using (var scope = Factory.Current.BeginLifetimeScope(b =>
            {
                b.RegisterInstance(mq.Object).As <IMessageQueue>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var listener = new MessageQueueListener();

                    string consumed = null;

                    mq.Request("foo", "\"test\"");
                    mq.Consume += (s, e) =>
                    {
                        consumed = e.Message;
                    };

                    // act
                    listener.Respond <string, string>("foo", null);
                    listener.Stop();

                    // assert
                    consumed.Should().Be("\"test\"");
                }
        }
        public void ShouldSuccessfullyStopWhenNoWorkers()
        {
            // Given
            var target = new MessageQueueListener();

            // When
            TestDelegate action = target.StopListenAll;

            // Then
            Assert.DoesNotThrow(action);
        }
        public void ShouldSuccessfullyStopNotExistsWorker()
        {
            // Given
            var target = new MessageQueueListener();

            // When
            TestDelegate action = () => target.StopListen("queue1");

            // Then
            Assert.DoesNotThrow(action);
        }
        public void ShouldStartSpecifiedWorker()
        {
            // Given
            var worker1 = new Mock <IMessageQueueWorker>();
            var worker2 = new Mock <IMessageQueueWorker>();
            var target  = new MessageQueueListener();

            // When
            target.RegisterWorker("queue1", worker1.Object);
            target.RegisterWorker("queue2", worker2.Object);
            target.StartListen("queue1");

            // Then
            worker1.Verify(m => m.Start(), Times.Once());
            worker1.Verify(m => m.Stop(), Times.Never());
            worker2.Verify(m => m.Start(), Times.Never());
            worker2.Verify(m => m.Stop(), Times.Never());
        }
Exemplo n.º 5
0
        public RabbitMqMessageQueueFactory(RabbitMqSettings settings, ILog log, IRabbitMqMessageQueueConfig config)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            _defaultExchangeConfig = config.DefaultExchangeConfig;
            _defaultQueueConfig    = config.DefaultQueueConfig;
            _commandExecutor       = new RetryCommandExecutor(config.RetryPolicy, config.RetrySchedulePolicy);
            _sessionFactory        = new RabbitMqSessionFactory(settings.Node, settings.Port);
            _queueListener         = new MessageQueueListener();
        }