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_set_replyto_address_to_destination_if_multiple_available_with_respect_to_secured_connection_strings_setting(bool shouldSecureConnectionString, string expectedReplyToAddress) { var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); settings.Set(WellKnownConfigurationKeys.Topology.Addressing.UseNamespaceAliasesInsteadOfConnectionStrings, shouldSecureConnectionString); var namespaces = new NamespaceConfigurations(new List <NamespaceInfo> { new NamespaceInfo("alias1", "Endpoint=sb://name-x.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key"), new NamespaceInfo("alias2", "Endpoint=sb://name-y.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key") }); settings.Set(WellKnownConfigurationKeys.Topology.Addressing.Namespaces, namespaces); var headers = new Dictionary <string, string>() { { Headers.ReplyToAddress, "MyQueue" } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions() { DestinationNamespace = new RuntimeNamespaceInfo("alias2", "Endpoint=sb://name-y.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key") }); Assert.That(brokeredMessage.ReplyTo, Is.EqualTo(expectedReplyToAddress)); }
public void Should_apply_time_to_live() { var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var ttl = TimeSpan.FromMinutes(1); var headers = new Dictionary <string, string> { { Headers.TimeToBeReceived, ttl.ToString() } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint> { new DiscardIfNotReceivedBefore(ttl) } }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.IsTrue(brokeredMessage.TimeToLive == ttl); }
public void Should_apply_delivery_at_specific_date() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var now = DateTime.UtcNow; Time.UtcNow = () => now; var delay = new DoNotDeliverBefore(now.AddDays(2)); var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), new byte[0]), DeliveryConstraints = new List <DeliveryConstraint> { delay } }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.IsTrue(brokeredMessage.ScheduledEnqueueTimeUtc == now.AddDays(2)); Time.UtcNow = () => DateTime.UtcNow; }
public void Should_NOT_copy_the_message_id() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.That(brokeredMessage.MessageId, Is.Not.EqualTo("SomeId")); }
public void Should_inject_estimated_message_size_into_headers() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var body = Encoding.UTF8.GetBytes("Whatever"); var headers = new Dictionary <string, string> { { "header", "value" } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, body), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.That(brokeredMessage.Properties[BrokeredMessageHeaders.EstimatedMessageSize], Is.GreaterThan(0)); }
public void Should_set_ViaPartitionKey_if_partition_key_is_available_and_sending_via_option_is_enabled() { var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var routingOptions = new RoutingOptions { SendVia = true, ViaPartitionKey = "partitionkey" }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, routingOptions); Assert.IsTrue(brokeredMessage.ViaPartitionKey == "partitionkey"); }
public void Should_set_replyto_address() { var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var headers = new Dictionary <string, string>() { { Headers.ReplyToAddress, "MyQueue" } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.IsTrue(brokeredMessage.ReplyTo == "MyQueue"); // the mapper should be ignored, need to respect user's setting }
public void Should_inject_body_as_byte_array_by_default() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); 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 body = Encoding.UTF8.GetString(brokeredMessage.GetBody <byte[]>()); Assert.AreEqual(body, "Whatever"); }
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)); }
public void Should_apply_correlationid() { var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var correlationId = "SomeId"; var headers = new Dictionary <string, string> { { Headers.CorrelationId, correlationId } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.IsTrue(brokeredMessage.CorrelationId == correlationId); }
public void Should_copy_the_headers() { // default settings var settings = new DefaultConfigurationValues().Apply(new SettingsHolder()); var converter = new DefaultBatchedOperationsToBrokeredMessagesConverter(settings); var headers = new Dictionary <string, string> { { "MyHeader", "MyValue" } }; var batchedOperation = new BatchedOperation { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptions()); Assert.IsTrue(brokeredMessage.Properties.ContainsKey("MyHeader")); Assert.AreEqual("MyValue", brokeredMessage.Properties["MyHeader"]); }