예제 #1
0
        public void MessageDeliveryRequiresAck_AndConsumerAck_RabbitNotifiedBasicAck()
        {
            var stateSetup  = BrokerTest.SetupBrokerState();
            var brokerSetup = BrokerTest.SetupMessageBroker();

            var exchange    = new MockExchange();
            var msgConsumer = BrokerTest.SetupExclusiveConsumer();
            var domainEvt   = new MockDomainEvent();

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

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

            // Provide a mock consumer that acknowledges the received message,
            brokerSetup.MockMsgModule.Setup(m => m.InvokeDispatcherAsync(
                                                It.IsAny <MessageDispatchInfo>(),
                                                It.IsAny <IMessage>(),
                                                It.IsAny <CancellationToken>()))

            .Returns((MessageDispatchInfo di, IMessage m, CancellationToken t) => {
                m.SetAcknowledged();
                return(Task.FromResult <object>(null));
            });

            // Simulate receiving of a message and verify that the RabbitMq
            // client was called correctly.
            brokerSetup.SimulateMessageReceived(domainEvt);
            stateSetup.MockConnMgr.MockChannel.Verify(m => m.BasicAck(It.IsAny <ulong>(), It.IsAny <bool>()), Times.Once());
        }
        public async Task Should_Insert_And_Get_Async()
        {
            var repository = MockExchange.GetDBTestRepository();
            var result     = await repository.InsertAsync(MockExchange.GetEntityFake());

            Assert.NotNull(result);
            result = await repository.GetAsync(result.Id);

            Assert.NotNull(result);
        }
        public async Task Should_Return_All_Async()
        {
            var repository = MockExchange.GetDBTestRepository();
            await repository.InsertAsync(MockExchange.GetEntityFake());

            await repository.InsertAsync(MockExchange.GetEntityFake());

            var result = await repository.GetAll();

            Assert.Equal(2, result.ToList().Count);
        }
예제 #4
0
        public void ExchangeBrokerNameNotConfigured_Exception()
        {
            var emptySettings = new BrokerSettings();
            var stateSetup    = BrokerTest.SetupBrokerState(emptySettings);
            var brokerSetup   = BrokerTest.SetupMessageBroker();
            var exchange      = new MockExchange();

            exchange.InitializeSettings(emptySettings);
            stateSetup.BrokerState.Exchanges = new[] { exchange };
            stateSetup.BrokerState.BrokerSettings.Connections.Clear();

            Assert.Throws <BrokerException>(() => brokerSetup.Initialize(stateSetup.BrokerState));
        }
        public async Task Should_Delete_Async()
        {
            var repository = MockExchange.GetDBTestRepository();
            var result     = await repository.InsertAsync(MockExchange.GetEntityFake());

            Assert.NotNull(result);
            Assert.True(!result.IsExcluded);
            await repository.DeleteAsync(result);

            result = await repository.GetAsync(result.Id);

            Assert.True(result.IsExcluded);
        }
        public async Task Should_Return_All_Without_Disabled_Async()
        {
            var repository = MockExchange.GetDBTestRepository();
            await repository.InsertAsync(MockExchange.GetEntityFake());

            var disable = await repository.InsertAsync(MockExchange.GetEntityFake());

            disable.IsEnabled = false;
            await repository.UpdateAsync(disable);

            var result = await repository.GetAllWithoutDisable();

            Assert.Single(result.ToList());
        }
예제 #7
0
        public void Event_AssociatedWith_Exchange()
        {
            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 };

            brokerSetup.Initialize(stateSetup.BrokerState);

            var msg = new MockDomainEvent();

            brokerSetup.Instance.IsExchangeMessage(msg).Should().BeTrue();
        }
        public async Task Should_Update_Async()
        {
            var repository = MockExchange.GetDBTestRepository();
            var entity     = MockExchange.GetEntityFake();

            entity.APIUrl = $"TESTE{Guid.NewGuid()}";
            var result = await repository.InsertAsync(entity);

            Assert.NotNull(result);
            result.APIUrl = "Teste Alteração";
            await repository.UpdateAsync(result);

            result = await repository.GetAsync(result.Id);

            Assert.Equal("Teste Alteração", result.APIUrl);
        }
예제 #9
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);
        }
예제 #10
0
        public void ConsumerJoinsNonFanoutQueue_NewBindingCreatedForConsumer()
        {
            var brokerSetup = BrokerTest.SetupMessageBroker();
            var exchange    = new MockExchange();
            var stateSetup  = BrokerTest.SetupBrokerState();
            var msgConsumer = BrokerTest.SetupJoiningConsumer();

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

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

            // Assert call made to the RabbitMq client:
            stateSetup.MockConnMgr.MockChannel.Verify(m => m.QueueBind(
                                                          It.Is <string>(v => v == "MockTestQueueName"),
                                                          It.Is <string>(v => v == "MockDirectExchangeName"),
                                                          It.Is <string>(v => v == ""),
                                                          It.IsAny <IDictionary <string, object> >()), Times.Once());
        }
예제 #11
0
        public void DiscoveredExchange_CreatedByBroker()
        {
            var brokerSetup = BrokerTest.SetupMessageBroker();
            var exchange    = new MockExchange {
                IsDurable = true, IsAutoDelete = true
            };
            var stateSetup = BrokerTest.SetupBrokerState();

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

            // Assert that the RabbitMq client was called with the correct values:
            BrokerTest.AssertDeclaredExchange(stateSetup.MockConnMgr.MockChannel, v => {
                v.ExchangeName.Should().Be("MockDirectExchangeName");
                v.AutoDelete.Should().BeTrue();
                v.Durable.Should().BeTrue();
                v.Type.Should().Be("direct");
            });

            brokerSetup.Initialize(stateSetup.BrokerState);
        }
예제 #12
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());
        }