Пример #1
0
        public void SendMessage_CallsBasicPublish_WithCorrectExchangeName()
        {
            // Arrange
            var propsMock = new Mock <IBasicProperties>();

            var channelMock = new Mock <IModel>(MockBehavior.Strict);

            channelMock.Setup(c => c.BasicPublish(It.Is <string>(k => k == "Testexchange1"),
                                                  "MyRoutingKey",
                                                  false,
                                                  propsMock.Object,
                                                  It.Is <byte[]>(b => Encoding.UTF8.GetString(b) == "MyMessage")))
            .Verifiable();

            channelMock.Setup(c => c.CreateBasicProperties())
            .Returns(propsMock.Object)
            .Verifiable();

            var connectionMock = new Mock <IConnection>(MockBehavior.Strict);

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

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

            var sender = new RabbitMQMessageSender(context);

            // Act
            sender.SendMessage(new EventMessage("MyRoutingKey", "MyMessage"));

            // Assert
            channelMock.VerifyAll();
        }
Пример #2
0
        public void SendMessage_CallsBasicPublish_WithCorrectCorrelationIdInBasicProperties()
        {
            // Arrange
            IBasicProperties props = new BasicProperties();

            var channelMock = new Mock <IModel>(MockBehavior.Strict);

            channelMock.Setup(c => c.CreateBasicProperties())
            .Returns(props)
            .Verifiable();

            channelMock.Setup(c => c.BasicPublish("Testxchange1",
                                                  "MyRoutingKey",
                                                  false,
                                                  It.Is <IBasicProperties>(p => p.CorrelationId == "correlationID"),
                                                  It.IsAny <Byte[]>()))
            .Verifiable();

            var connectionMock = new Mock <IConnection>(MockBehavior.Strict);

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

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

            var sender = new RabbitMQMessageSender(context);

            // Act
            sender.SendMessage(new EventMessage("MyRoutingKey", "MyMessage", "Test", 9, "correlationID"));

            // Assert
            channelMock.VerifyAll();
        }
Пример #3
0
        public void SendMessage_WithSenderDisposed_ThrowsObjectDisposedException()
        {
            // Arrange
            var channelMock = new Mock <IModel>();

            var connectionMock = new Mock <IConnection>();

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

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

            var sender = new RabbitMQMessageSender(context);

            sender.Dispose();

            // Act & Assert
            Assert.ThrowsException <ObjectDisposedException>(() =>
            {
                sender.SendMessage(new EventMessage("MyRoutingKey", "MyMessage"));
            });
        }