Exemplo n.º 1
0
        public void Produce_WhenSettingsSupplied_ThenSettingsUsedForPublish()
        {
            // Arrange
            Dependencies dependencies = GetDependencies();

            TestType data = new TestType();

            byte[] byteData = new byte[0];

            Settings            settings = new Settings(exchange: "exchange", routingKey: "routingkey");
            IMessage <TestType> message  = new TestMessage <TestType>
            {
                Data = data
            };

            dependencies.MockConnection
            .Setup(mockConnection => mockConnection.CreateModel())
            .Returns(dependencies.MockChannel.Object);
            dependencies.MockConnectionFactory
            .Setup(mockConnectionFactory => mockConnectionFactory.CreateConnection())
            .Returns(dependencies.MockConnection.Object);

            dependencies.MockTypeConverter
            .Setup(mockTypeConverter => mockTypeConverter.ToByteArray(data))
            .Returns(byteData);

            MessageProducer messageProducer = new MessageProducer(
                dependencies.MockConnectionFactory.Object,
                dependencies.MockTypeConverter.Object);

            // Act
            messageProducer.Produce(settings, message);

            // Assert
            dependencies.MockChannel.Verify(mockChannel => mockChannel.BasicPublish(
                                                settings.Exchange,
                                                settings.RoutingKey,
                                                It.IsAny <bool>(),
                                                It.IsAny <IBasicProperties>(),
                                                It.IsAny <byte[]>()), Times.Once);
        }
Exemplo n.º 2
0
 protected virtual void Publish(int partition, string data)
 {
     MessageProducer.Produce(partition, data);
 }