Refactor and enhance MessagingService client tests

Updated `ToSender` to an extension method for improved usability.
Bumped project version to 3.0.0, reflecting major changes.
Added `MessagingServiceApiBaseAddress` constant for maintainability.
Introduced new test for HTTP client dependency injection.
Refactored command creation into a reusable `CreateCommand` method.
Removed redundant code and improved test structure for clarity.
This commit is contained in:
2026-11-05 10:04:41 +01:00
parent 3e86d4cfe2
commit 05d16bb32c
3 changed files with 34 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
{
private const string SenderAddress = "test-flow@digitaldata.works";
private const string RecipientAddress = "htek0100@gmail.com";
private const string MessagingServiceApiBaseAddress = "http://172.24.12.39:1414";
private readonly ServiceProvider _serviceProvider;
private readonly IMessagingServiceClient _client;
@@ -59,21 +60,41 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
{
var subject = $"MessagingServiceClient Integration Test {Guid.NewGuid():N}";
var command = new PublishEmailViaSmtpCommand
var command = CreateCommand(subject);
await _client.SendAsync(command);
Assert.True(true, "Verify in mailbox.");
}
[Fact]
public async Task SendAsync_WithHttpClientDependencyInjection_PublishesExpectedMessage()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddMessagingServiceHttpClient(client => client.BaseAddress = new Uri(MessagingServiceApiBaseAddress));
await using var serviceProvider = services.BuildServiceProvider();
var client = serviceProvider.GetRequiredService<IMessagingServiceClient>();
var subject = $"MessagingServiceHttpClient Integration Test {Guid.NewGuid():N}";
var command = CreateCommand(subject);
await Record.ExceptionAsync(() => client.SendAsync(command));
Assert.True(true, "Verify in mailbox.");
}
private static PublishEmailViaSmtpCommand CreateCommand(string subject)
{
return new PublishEmailViaSmtpCommand
{
Sender = new GetEmailAccountQuery
{
Username = SenderAddress
},
Sender = SenderAddress.ToSender(),
Recipients = [RecipientAddress],
Subject = subject,
Body = "<p>Realistic test mail via MessagingServiceClient.</p>",
IsHtml = true
};
await _client.SendAsync(command);
Assert.True(true, "Verify in mailbox.");
}
private async Task<SendingEmailEvent?> FindMessageBySubjectAsync(string subject, int maxMessages = 100)