public void Should_extract_body_as_stream_when_configured() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var bytes = Encoding.UTF8.GetBytes("Whatever"); var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); var sr = new StreamReader(brokeredMessage.GetBody <Stream>()); var body = sr.ReadToEnd(); Assert.AreEqual("Whatever", body); }
public void Should_extract_body_as_stream_when_configured() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream); var converter = new DefaultBrokeredMessagesToIncomingMessagesConverter(settings, new FakeMapper(settings, "MyQueue", "MyQueue")); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write("Whatever"); writer.Flush(); stream.Position = 0; var brokeredMessage = new BrokeredMessage(stream); brokeredMessage.Properties[BrokeredMessageHeaders.TransportEncoding] = "application/octect-stream"; var incomingMessage = converter.Convert(brokeredMessage); var body = Encoding.UTF8.GetString(incomingMessage.Body); Assert.AreEqual("Whatever", body); }
public void Should_be_able_to_set_the_brokered_message_body_type() { var settings = new SettingsHolder(); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream); Assert.AreEqual(SupportedBrokeredMessageBodyTypes.Stream, settings.Get <SupportedBrokeredMessageBodyTypes>(WellKnownConfigurationKeys.Serialization.BrokeredMessageBodyType)); }
public void Should_set_transport_encoding_header(SupportedBrokeredMessageBodyTypes bodyType, string expectedHeaderValue) { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(bodyType); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var bytes = Encoding.UTF8.GetBytes("Whatever"); var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.That(brokeredMessage.Properties[BrokeredMessageHeaders.TransportEncoding], Is.EqualTo(expectedHeaderValue)); }