public void CanSendMessageWithSentException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => channel.CreateBasicProperties()).Returns(null); A.CallTo(() => channel.BasicPublish( A <string> ._, A <string> ._, A <bool> ._, A <IBasicProperties> ._, A <byte[]> ._)) .Throws <Exception>() .Once(); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Returns(new AmqpMessage(properties, null, null, null)).Twice(); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); Result <AmqpMessage, ExceptionDispatchInfo> result = new Result <AmqpMessage, ExceptionDispatchInfo>( new AmqpMessage(new AmqpProperties(), string.Empty, string.Empty, new byte[0])); Action action = () => sut.Send(result); action.Should().NotThrow("because the AmqpSender should catch all exceptions to prevent from destroying of the DataFlow chain."); }
public void CanCreateEmptyAmqpProperties() { IMessage message = A.Fake <IMessage>(); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromHeaders(message.Headers); properties.Should().NotBeNull(because: "Builder can build empty properties"); }
public void CanCreateEmptyAmqpPropertiesFromBasicProperites() { IBasicProperties basicProperties = A.Fake <IBasicProperties>(); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromProperties(basicProperties); properties.Should().NotBeNull(because: "Builder can build empty properties"); }
public void CanCreateEmptyHeadersFromAmqpProperties() { IAmqpProperties properties = A.Fake <IAmqpProperties>(); var sut = new AmqpPropertyBuilder(); IDictionary <string, string> headers = sut.BuildHeadersFromProperties(properties); headers.Should().NotBeNull(because: "Builder can build empty headers"); }
public AmqpMessage( IAmqpProperties properties, string exchangeName, string routingKey, byte[] payload, TaskCompletionSource <bool> tcs) : this(properties, exchangeName, routingKey, payload) { this.Task = tcs; }
public AmqpMessage( IAmqpProperties properties, string exchangeName, string routingKey, byte[] payload) { this.Properties = properties; this.ExchangeName = exchangeName; this.RoutingKey = routingKey; this.Payload = payload; }
public virtual AmqpMessage Serialize(IMessage message) { IAmqpProperties properties = this.propertyBuilder.BuildPropertiesFromHeaders(message.Headers); string exchangeName = this.router.GetExchange(message); string routingKey = this.router.GetRoutingKey(message); IAmqpSerializer amqpSerializer = this.serializerFactory.CreateSerializer(message); byte[] payload = amqpSerializer.Serialize(message); return(new AmqpMessage(properties, exchangeName, routingKey, payload)); }
public IDictionary <string, string> BuildHeadersFromProperties(IAmqpProperties amqpProperties) { var headers = new Dictionary <string, string>(amqpProperties.Headers); headers.Add(ContentEncoding, amqpProperties.ContentEncoding); headers.Add(ContentType, amqpProperties.ContentType); headers.Add(CorrelationId, amqpProperties.CorrelationId); headers.Add(MessageId, amqpProperties.MessageId); headers.Add(Persistent, amqpProperties.Persistent.ToString()); headers.Add(ReplyTo, amqpProperties.ReplyTo); return(headers); }
public void CanCreateAmqpMessage() { IAmqpProperties properties = A.Fake <IAmqpProperties>(); byte[] payload = new byte[0]; const string ExchangeName = "_exchangeName_"; const string RoutingKey = "_routingKey_"; var sut = new AmqpMessage(properties, ExchangeName, RoutingKey, payload); sut.ExchangeName.Should().Be(ExchangeName, because: "constructor should be set it."); sut.RoutingKey.Should().Be(RoutingKey, because: "constructor should be set it."); sut.Payload.Should().BeEquivalentTo(payload, because: "constructor should be set it."); sut.Properties.Should().Be(properties, because: "constructor should be set it."); }
public void CanCreateHeadersWithContentTypeFromAmqpProperties() { IAmqpProperties properties = A.Fake <IAmqpProperties>(); const string headerValue = "text/plain"; A.CallTo(() => properties.ContentType).Returns(headerValue); var sut = new AmqpPropertyBuilder(); IDictionary <string, string> headers = sut.BuildHeadersFromProperties(properties); headers.Should().Contain(new KeyValuePair <string, string>(AmqpPropertyBuilder.ContentType, headerValue)); headers.Should().NotBeNull(because: "builder can build content type from AmqpProperties"); }
public void CanCreateHeadersWithReplyToFromAmqpProperties() { IAmqpProperties properties = A.Fake <IAmqpProperties>(); const string headerValue = "some address"; A.CallTo(() => properties.ReplyTo).Returns(headerValue); var sut = new AmqpPropertyBuilder(); IDictionary <string, string> headers = sut.BuildHeadersFromProperties(properties); headers.Should().Contain(new KeyValuePair <string, string>(AmqpPropertyBuilder.ReplyTo, headerValue)); headers.Should().NotBeNull(because: "builder can build correlation id from AmqpProperties"); }
public void CanCreateAmqpPropertiesWithReplyToFromBasicProperties() { IBasicProperties basicProperties = A.Fake <IBasicProperties>(); const string headerValue = "some address"; A.CallTo(() => basicProperties.ReplyTo).Returns(headerValue); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromProperties(basicProperties); properties.ReplyTo.Should().Be(headerValue); properties.Should().NotBeNull(because: "builder can build replyto from BasicProperties"); }
public void CanCreateAmqpPropertiesWithPersistentFromBasicProperties() { IBasicProperties basicProperties = A.Fake <IBasicProperties>(); const string headerValue = "true"; A.CallTo(() => basicProperties.Persistent).Returns(bool.Parse(headerValue)); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromProperties(basicProperties); properties.Persistent.Should().Be(bool.Parse(headerValue)); properties.Should().NotBeNull(because: "builder can build persistent from BasicProperties"); }
public void CanCreateAmqpPropertiesWithMessageIdFromBasicProperties() { IBasicProperties basicProperties = A.Fake <IBasicProperties>(); const string headerValue = "100500"; A.CallTo(() => basicProperties.MessageId).Returns(headerValue); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromProperties(basicProperties); properties.MessageId.Should().Be(headerValue); properties.Should().NotBeNull(because: "builder can build message id from BasicProperties"); }
public void CanCreateAmqpPropertiesWithContentTypeFromBasicProperites() { IBasicProperties basicProperties = A.Fake <IBasicProperties>(); const string headerValue = "text/plain"; A.CallTo(() => basicProperties.ContentType).Returns(headerValue); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromProperties(basicProperties); properties.ContentType.Should().Be(headerValue); properties.Should().NotBeNull(because: "builder can build content type from BasicProperties"); }
public void CanCreateAmqpPropertiesWithPersistent() { IMessage message = A.Fake <IMessage>(); const string headerValue = "true"; A.CallTo(() => message.Headers) .Returns(new Dictionary <string, string> { { AmqpPropertyBuilder.Persistent, headerValue } }); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromHeaders(message.Headers); properties.Persistent.Should().Be(bool.Parse(headerValue)); properties.Should().NotBeNull(because: "builder can build persistent from message headers"); }
public void CanCreateAmqpPropertiesWithMessageId() { IMessage message = A.Fake <IMessage>(); const string headerValue = "100500"; A.CallTo(() => message.Headers) .Returns(new Dictionary <string, string> { { AmqpPropertyBuilder.MessageId, headerValue } }); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromHeaders(message.Headers); properties.MessageId.Should().Be(headerValue); properties.Should().NotBeNull(because: "builder can build message id from message headers"); }
public void CanCreateAmqpPropertiesWithContentType() { IMessage message = A.Fake <IMessage>(); const string headerValue = "text/plain"; A.CallTo(() => message.Headers) .Returns(new Dictionary <string, string> { { AmqpPropertyBuilder.ContentType, headerValue } }); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromHeaders(message.Headers); properties.ContentType.Should().Be(headerValue); properties.Should().NotBeNull(because: "builder can build content type from message headers"); }
public void CanCreateAmqpPropertiesWithHeaderNotContainPresetHeaders() { IMessage message = A.Fake <IMessage>(); var customHeaders = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }; var allHeaders = new Dictionary <string, string>(customHeaders); allHeaders.Add(AmqpPropertyBuilder.ReplyTo, "some-address"); allHeaders.Add(AmqpPropertyBuilder.ContentType, "some-address"); A.CallTo(() => message.Headers).Returns(allHeaders); var sut = new AmqpPropertyBuilder(); IAmqpProperties properties = sut.BuildPropertiesFromHeaders(message.Headers); properties.Headers.Should().BeEquivalentTo(customHeaders, because: "preset headers should be set to properties"); }
public void CanSendMessageWithSerializationException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Throws <Exception>() .Once() .Then. Returns(new AmqpMessage(properties, null, null, null)); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); IMessage message = new Message <string>("hello", new Dictionary <string, string>()); Action action = () => sut.Transform(message); action.Should().NotThrow("because the AmqpSender should catch all exception to prevent from destroying the DataFlow chain."); }