Skip to content

Commit

Permalink
Add test for ServiceBus message properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-pajurek committed Sep 30, 2024
1 parent a1380d0 commit ddf612a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/service-bus.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ If the given feature is not supported, than the method will just ignore any para
| Deferred messages ||
| Dead-letter queues ||
| Duplicate detection ||
| Partitioning ||
| `PeekLock` receive mode ||
| Processors ||
| Queues ||
Expand Down
54 changes: 54 additions & 0 deletions tests/Tests/ServiceBus/ServiceBusReceiverTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Azure.Messaging.ServiceBus;

using FluentAssertions.Execution;

using Microsoft.Extensions.Time.Testing;

using Spotflow.InMemory.Azure.ServiceBus;
Expand Down Expand Up @@ -263,4 +265,56 @@ public async Task Message_Count_On_Topic_Subscription_Should_Be_Reported()
subscription.MessageCount.Should().Be(1);
}


[TestMethod]
public async Task Received_Message_Should_Have_All_Expected_Properties()
{
var timeProvider = new FakeTimeProvider();

var provider = new InMemoryServiceBusProvider(timeProvider);

var queue = provider.AddNamespace().AddQueue("test-queue");

await using var client = InMemoryServiceBusClient.FromNamespace(queue.Namespace);

await using var sender = client.CreateSender("test-queue");
await using var receiver = client.CreateReceiver("test-queue");

var payload = BinaryData.FromString("Test payload.");

var message = new ServiceBusMessage(payload)
{
ApplicationProperties = { { "test-app-property", "test-app-property-value" } },
Subject = "test-subject",
ContentType = "test-content-type",
CorrelationId = "test-correlation-id",
MessageId = "test-message-id",
PartitionKey = "test-partition-key",
ReplyTo = "test-reply-to",
ReplyToSessionId = "test-reply-to-session-id"
};

await sender.SendMessagesAsync([message]);

var receivedMessage = await receiver.ReceiveMessageAsync();

using var assertionScope = new AssertionScope();

receivedMessage.ApplicationProperties.Count.Should().Be(1);
receivedMessage.ApplicationProperties["test-app-property"].Should().Be("test-app-property-value");

//receivedMessage.Subject.Should().Be("test-subject");
receivedMessage.ContentType.Should().Be("test-content-type");
receivedMessage.CorrelationId.Should().Be("test-correlation-id");
receivedMessage.MessageId.Should().Be("test-message-id");
//receivedMessage.PartitionKey.Should().Be("test-partition-key");
//receivedMessage.ReplyTo.Should().Be("test-reply-to");
receivedMessage.ReplyToSessionId.Should().Be("test-reply-to-session-id");

receivedMessage.EnqueuedTime.Should().Be(timeProvider.GetUtcNow());
receivedMessage.SequenceNumber.Should().Be(0);
receivedMessage.SessionId.Should().BeNull();

}

}

0 comments on commit ddf612a

Please sign in to comment.