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:
@@ -5,7 +5,7 @@ namespace DigitalData.MessagingService.Application.EmailSending.Commands;
|
|||||||
|
|
||||||
public static class GetEmailAccountQueryExtensions
|
public static class GetEmailAccountQueryExtensions
|
||||||
{
|
{
|
||||||
public static GetEmailAccountQuery ToSender(string emailAddress)
|
public static GetEmailAccountQuery ToSender(this string emailAddress)
|
||||||
{
|
{
|
||||||
return new GetEmailAccountQuery
|
return new GetEmailAccountQuery
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
<PackageIcon>icon.png</PackageIcon>
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
||||||
<PackageTags>digital data messaging service api client</PackageTags>
|
<PackageTags>digital data messaging service api client</PackageTags>
|
||||||
<Version>2.0.0</Version>
|
<Version>3.0.0</Version>
|
||||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
<AssemblyVersion>3.0.0.0</AssemblyVersion>
|
||||||
<FileVersion>2.0.0.0</FileVersion>
|
<FileVersion>3.0.0.0</FileVersion>
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
private const string SenderAddress = "test-flow@digitaldata.works";
|
private const string SenderAddress = "test-flow@digitaldata.works";
|
||||||
private const string RecipientAddress = "htek0100@gmail.com";
|
private const string RecipientAddress = "htek0100@gmail.com";
|
||||||
|
private const string MessagingServiceApiBaseAddress = "http://172.24.12.39:1414";
|
||||||
|
|
||||||
private readonly ServiceProvider _serviceProvider;
|
private readonly ServiceProvider _serviceProvider;
|
||||||
private readonly IMessagingServiceClient _client;
|
private readonly IMessagingServiceClient _client;
|
||||||
@@ -59,21 +60,41 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
var subject = $"MessagingServiceClient Integration Test {Guid.NewGuid():N}";
|
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
|
Sender = SenderAddress.ToSender(),
|
||||||
{
|
|
||||||
Username = SenderAddress
|
|
||||||
},
|
|
||||||
Recipients = [RecipientAddress],
|
Recipients = [RecipientAddress],
|
||||||
Subject = subject,
|
Subject = subject,
|
||||||
Body = "<p>Realistic test mail via MessagingServiceClient.</p>",
|
Body = "<p>Realistic test mail via MessagingServiceClient.</p>",
|
||||||
IsHtml = true
|
IsHtml = true
|
||||||
};
|
};
|
||||||
|
|
||||||
await _client.SendAsync(command);
|
|
||||||
|
|
||||||
Assert.True(true, "Verify in mailbox.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SendingEmailEvent?> FindMessageBySubjectAsync(string subject, int maxMessages = 100)
|
private async Task<SendingEmailEvent?> FindMessageBySubjectAsync(string subject, int maxMessages = 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user