public void MessageDeliveryRequiresAck_AndConsumerNoAck_RabbitNotifiedBasicReject() { 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 rejects the received message, brokerSetup.MockMsgModule.Setup(m => m.InvokeDispatcherAsync( It.IsAny <MessageDispatchInfo>(), It.IsAny <IMessage>(), It.IsAny <CancellationToken>())) .Returns((MessageDispatchInfo di, IMessage m) => { m.SetRejected(); 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.BasicReject(It.IsAny <ulong>(), It.IsAny <bool>()), Times.Once()); }
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 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 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); }
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()); }
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); }
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()); }