public void SendAndReceiveWithTopicsCorrectly()
        {
            //Arrange
            IEventMessage  receivedMessage = null;
            AutoResetEvent flag            = new AutoResetEvent(false);

            var sender   = _context.CreateMessageSender();
            var receiver = _context.CreateMessageReceiver("TestQueue", new List <string>()
            {
                "test"
            });

            receiver.DeclareQueue();

            var message = new EventMessage("test", "TestMessage");

            //Act
            sender.SendMessage(message);

            receiver.StartReceivingMessages(eventMessage =>
            {
                receivedMessage = eventMessage;
                flag.Set();
            });

            flag.WaitOne();

            //Assert
            Assert.IsNotNull(receivedMessage);
            Assert.AreEqual("TestMessage", receivedMessage.Message);
        }
예제 #2
0
        public void CreateMessageReceiver_ReturnsMessageReceiverWithCorrectProperties()
        {
            // Arrange
            var channelMock    = new Mock <IModel>(MockBehavior.Strict);
            var connectionMock = new Mock <IConnection>(MockBehavior.Strict);

            connectionMock.Setup(c => c.CreateModel())
            .Returns(channelMock.Object);

            var context          = new RabbitMQBusContext(connectionMock.Object, "TestExchange4");
            var topicExpressions = new List <string> {
                "topic.expression.a", "routing.key.b"
            };

            // Act
            RabbitMQMessageReceiver receiver = (RabbitMQMessageReceiver)context.CreateMessageReceiver("TestQueue", topicExpressions);

            // Assert
            Assert.AreEqual("TestExchange4", receiver.ExchangeName);
            Assert.AreEqual("TestQueue", receiver.QueueName);
            Assert.AreEqual(topicExpressions, receiver.TopicExpressions);
            IModel channel = TestHelper.GetPrivateProperty <IModel>(receiver, "Channel");

            Assert.AreEqual(channelMock.Object, channel);
        }
예제 #3
0
        public void CreateMessageReceiver_WithBusContextDisposed_ThrowsObjectDisposedException()
        {
            // Arrange
            var connectionMock = new Mock <IConnection>();

            var context = new RabbitMQBusContext(connectionMock.Object, "TestExchange3");

            context.Dispose();

            // Act & Assert
            Assert.ThrowsException <ObjectDisposedException>(() =>
            {
                context.CreateMessageReceiver("TestQueue", new List <string> {
                    "topic.expression.a", "routing.key.b"
                });
            });
        }
        public void CreateMessageReceiverCreatesRabbitMQMessageReceiver()
        {
            Mock <IModel>      channelMock    = new Mock <IModel>();
            Mock <IConnection> connectionMock = new Mock <IConnection>(MockBehavior.Strict);

            connectionMock.Setup(conn => conn.CreateModel()).Returns(channelMock.Object);

            var target = new RabbitMQBusContext(connectionMock.Object, "My.Test.ExchangeName");

            // Act
            string queueName = "My.Test.ListenQueue";

            string[] topicFilters = new string[] { "My.Test.Topic", "My.Test.OtherTopic" };
            var      receiver     = target.CreateMessageReceiver(queueName, topicFilters);

            // Assert
            Assert.IsInstanceOfType(receiver, typeof(RabbitMQMessageReceiver));
            connectionMock.Verify(conn => conn.CreateModel());
            Assert.AreEqual("My.Test.ListenQueue", receiver.QueueName);
            CollectionAssert.AreEquivalent(topicFilters, receiver.TopicFilters.ToList());
        }