Exemple #1
0
        public void DiscoveredQueue_CreatedByBroker()
        {
            var brokerSetup = BrokerTest.SetupMessageBroker();
            var exchange    = new MockExchange();
            var stateSetup  = BrokerTest.SetupBrokerState();

            // Setup of test DirectExchange instance that can be asserted.
            exchange.InitializeSettings(stateSetup.BrokerState.BrokerSettings);
            stateSetup.BrokerState.Exchanges = new[] { exchange };

            BrokerTest.AssertDeclaredQueue(stateSetup.MockConnMgr.MockChannel, v =>
            {
                v.QueueName.Should().Be("MockTestQueueName");
                v.AutoDelete.Should().BeFalse();
                v.Exclusive.Should().BeFalse();
                v.Durable.Should().BeTrue();
            });

            brokerSetup.Initialize(stateSetup.BrokerState);
        }
Exemple #2
0
        public void ConsumerAddsQueue_NewQueueCreatedExclusivelyForConsumer()
        {
            var brokerSetup = BrokerTest.SetupMessageBroker();
            var exchange    = new MockExchange();
            var stateSetup  = BrokerTest.SetupBrokerState();
            var msgConsumer = BrokerTest.SetupExclusiveConsumer();

            // Setup of test DirectExchange instance that can be asserted.
            exchange.InitializeSettings(stateSetup.BrokerState.BrokerSettings);
            stateSetup.BrokerState.Exchanges = new[] { exchange };

            // Records all calls made to the RabbitMq client:
            var clientCalls = new List <BrokerTest.DeclarationValues>();

            BrokerTest.AssertDeclaredQueue(stateSetup.MockConnMgr.MockChannel, v =>
            {
                clientCalls.Add(v);
            });

            // Initialize the broker.
            brokerSetup.Initialize(stateSetup.BrokerState, msgConsumer);

            // Assert call made to the RabbitMq client:
            // An exclusive queue is created for the consumer:
            clientCalls.Should().HaveCount(2);
            var addedQueueValuses = clientCalls.FirstOrDefault(c => c.Exclusive);

            addedQueueValuses.Should().NotBeNull();
            addedQueueValuses.QueueName.Should().Be("MockTestQueueName");

            // After creating exclusive queue, the consumer is bound:
            stateSetup.MockConnMgr.MockChannel.Verify(m => m.QueueBind(
                                                          It.Is <string>(v => v == "MockTestQueueName"),
                                                          It.Is <string>(v => v == "MockDirectExchangeName"),
                                                          It.Is <string>(v => v == "MOCKKEY"),
                                                          It.IsAny <IDictionary <string, object> >()), Times.Once());
        }