Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 52 additions & 92 deletions src/NServiceBus.Transport.RabbitMQ.Tests/MessageConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,130 +33,61 @@ class TestingBasicProperties : IBasicProperties

public string ProtocolClassName => throw new NotSupportedException();

public void ClearAppId()
{
throw new NotSupportedException();
}
public void ClearAppId() => throw new NotSupportedException();

public void ClearClusterId()
{
throw new NotSupportedException();
}
public void ClearClusterId() => throw new NotSupportedException();

public void ClearContentEncoding()
{
throw new NotSupportedException();
}
public void ClearContentEncoding() => throw new NotSupportedException();

public void ClearContentType()
{
throw new NotSupportedException();
}
public void ClearContentType() => throw new NotSupportedException();

public void ClearCorrelationId()
{
throw new NotSupportedException();
}
public void ClearCorrelationId() => throw new NotSupportedException();

public void ClearDeliveryMode()
{
throw new NotSupportedException();
}
public void ClearDeliveryMode() => throw new NotSupportedException();

public void ClearExpiration()
{
throw new NotSupportedException();
}
public void ClearExpiration() => throw new NotSupportedException();

public void ClearHeaders()
{
throw new NotSupportedException();
}
public void ClearHeaders() => throw new NotSupportedException();

public void ClearMessageId()
{
throw new NotSupportedException();
}
public void ClearMessageId() => throw new NotSupportedException();

public void ClearPriority()
{
throw new NotSupportedException();
}
public void ClearPriority() => throw new NotSupportedException();

public void ClearReplyTo()
{
throw new NotSupportedException();
}
public void ClearReplyTo() => throw new NotSupportedException();

public void ClearTimestamp()
{
throw new NotSupportedException();
}
public void ClearTimestamp() => throw new NotSupportedException();

public void ClearType()
{
throw new NotSupportedException();
}
public void ClearType() => throw new NotSupportedException();

public void ClearUserId()
{
throw new NotSupportedException();
}
public void ClearUserId() => throw new NotSupportedException();

public bool IsAppIdPresent()
{
throw new NotSupportedException();
}
public bool IsAppIdPresent() => throw new NotSupportedException();

public bool IsClusterIdPresent()
{
throw new NotSupportedException();
}
public bool IsClusterIdPresent() => throw new NotSupportedException();

public bool IsContentEncodingPresent()
{
throw new NotSupportedException();
}
public bool IsContentEncodingPresent() => throw new NotSupportedException();

public bool IsContentTypePresent()
{
throw new NotSupportedException();
}
public bool IsContentTypePresent() => ContentType != null;

public bool IsCorrelationIdPresent() => !string.IsNullOrEmpty(CorrelationId);

public bool IsDeliveryModePresent() => DeliveryMode != 0;

public bool IsExpirationPresent()
{
throw new NotSupportedException();
}
public bool IsExpirationPresent() => throw new NotSupportedException();

public bool IsHeadersPresent()
{
throw new NotSupportedException();
}
public bool IsHeadersPresent() => throw new NotSupportedException();

public bool IsMessageIdPresent() => !string.IsNullOrEmpty(MessageId);

public bool IsPriorityPresent()
{
throw new NotSupportedException();
}
public bool IsPriorityPresent() => throw new NotSupportedException();

public bool IsReplyToPresent() => !string.IsNullOrEmpty(ReplyTo);

public bool IsTimestampPresent()
{
throw new NotSupportedException();
}
public bool IsTimestampPresent() => throw new NotSupportedException();

public bool IsTypePresent() => !string.IsNullOrEmpty(Type);

public bool IsUserIdPresent()
{
throw new NotSupportedException();
}
public bool IsUserIdPresent() => throw new NotSupportedException();
}

MessageConverter converter = new MessageConverter(MessageConverter.DefaultMessageIdStrategy);
Expand Down Expand Up @@ -403,5 +334,34 @@ public void TestCanHandleTablesListHeader()
Assert.NotNull(headers);
Assert.AreEqual("key1=value1,key2=value2", Convert.ToString(headers["Foo"]));
}

[Test]
public void Should_handle_content_type()
{
var basicProperties = new TestingBasicProperties
{
MessageId = "Blah",
ContentType = "content_type"
};

var message = new BasicDeliverEventArgs
{
BasicProperties = new TestingBasicProperties
{
MessageId = "Blah",
ContentType = "content_type"
}
};

var headers = converter.RetrieveHeaders(message);
var messageId = converter.RetrieveMessageId(message, headers);

Assert.Multiple(() =>
{
Assert.That(messageId, Is.Not.Null);
Assert.That(headers, Is.Not.Null);
Assert.That(headers[NServiceBus.Headers.ContentType], Is.EqualTo(basicProperties.ContentType));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public Dictionary<string, string> RetrieveHeaders(BasicDeliverEventArgs message)
messageHeaders.Remove(BasicPropertiesExtensions.ConfirmationIdHeader);
}

// Leaving space for ReplyTo, CorrelationId, DeliveryMode, EnclosedMessageTypes conditionally
// Leaving space for ReplyTo, CorrelationId, DeliveryMode, EnclosedMessageTypes, ContentType conditionally
// added below. This is a bit cumbersome and need to be changed when things are conditionally added below
// but it prevents the header dictionary from growing and relocating which creates quite a bit of
// memory allocations and eats up CPU cycles.
const int extraCapacity = 4;
const int extraCapacity = 5;
var deserializedHeaders = DeserializeHeaders(messageHeaders, extraCapacity);

if (properties.IsReplyToPresent())
Expand Down Expand Up @@ -72,6 +72,11 @@ public Dictionary<string, string> RetrieveHeaders(BasicDeliverEventArgs message)
deserializedHeaders[Headers.EnclosedMessageTypes] = properties.Type;
}

if (properties.IsContentTypePresent())
{
deserializedHeaders[Headers.ContentType] = properties.ContentType;
}

//These headers need to be removed so that they won't be copied to an outgoing message if this message gets forwarded
//They can't be removed before deserialization because the value is used by the message pump
deserializedHeaders.Remove("x-delivery-count");
Expand Down