feat(client)!: unify client API around IMessagingServiceClient
MessagingServiceClient now implements IMessagingServiceClient and takes a PublishEmailViaSmtpCommand instead of the removed Email record. Add MessagingServiceHttpClient, which posts the same command to the API via IHttpClientFactory. Replace DependencyInjectionExtensions with a single DependencyInjection entry point that registers exactly one client implementation and throws when a second one is added. It exposes AddMessagingServiceClient for RabbitMQ and AddMessagingServiceHttpClient for the HTTP API, both with an optional license key. Bump the package to 2.0.0 because the SendAsync signatures and the removed Email type are breaking changes, add Microsoft.Extensions.Http, and update the integration test to exercise the new contract.
This commit is contained in:
@@ -2,9 +2,11 @@ using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using DigitalData.MessagingService.Application.Common.Dto;
|
||||
using DigitalData.MessagingService.Application.Common.Interfaces;
|
||||
using DigitalData.MessagingService.Application.Common.Interfaces.Repositories;
|
||||
using DigitalData.MessagingService.Application.EmailAccounts.Queries;
|
||||
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
||||
using DigitalData.MessagingService.Client;
|
||||
using DigitalData.MessagingService.Client.DependencyInjection;
|
||||
using DigitalData.MessagingService.Domain.Entities;
|
||||
using DigitalData.MessagingService.Publisher;
|
||||
using DigitalData.MessagingService.RabbitMQ;
|
||||
@@ -18,7 +20,7 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
||||
private const string RecipientAddress = "htek0100@gmail.com";
|
||||
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly MessagingServiceClient _client;
|
||||
private readonly IMessagingServiceClient _client;
|
||||
private readonly RabbitMqConnectionFactory _factory;
|
||||
|
||||
public MessagingServiceClientTests()
|
||||
@@ -26,7 +28,7 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
|
||||
services.AddMessagingServiceClient(LoadLuckyPennySoftLicenseKey(), RabbitMqTestConfig.Apply);
|
||||
services.AddMessagingServiceClient(RabbitMqTestConfig.Apply, LoadLuckyPennySoftLicenseKey());
|
||||
services.AddSingleton<IRepository<EmailAccount>>(
|
||||
new InMemoryEmailAccountRepository(
|
||||
[
|
||||
@@ -43,12 +45,12 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
||||
]));
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
_client = _serviceProvider.GetRequiredService<MessagingServiceClient>();
|
||||
_client = _serviceProvider.GetRequiredService<IMessagingServiceClient>();
|
||||
_factory = _serviceProvider.GetRequiredService<RabbitMqConnectionFactory>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an email through <see cref="MessagingServiceClient"/> using the real RabbitMQ setup.
|
||||
/// Sends an email through <see cref="IMessagingServiceClient"/> using the real RabbitMQ setup.
|
||||
/// This test intentionally uses manual mailbox verification because the shared queue can be
|
||||
/// consumed by other services during test execution.
|
||||
/// </summary>
|
||||
@@ -57,16 +59,19 @@ public sealed class MessagingServiceClientTests : IAsyncDisposable
|
||||
{
|
||||
var subject = $"MessagingServiceClient Integration Test {Guid.NewGuid():N}";
|
||||
|
||||
var email = new Email
|
||||
var command = new PublishEmailViaSmtpCommand
|
||||
{
|
||||
From = SenderAddress,
|
||||
To = [RecipientAddress],
|
||||
Sender = new GetEmailAccountQuery
|
||||
{
|
||||
Username = SenderAddress
|
||||
},
|
||||
Recipients = [RecipientAddress],
|
||||
Subject = subject,
|
||||
Body = "<p>Realistic test mail via MessagingServiceClient.</p>",
|
||||
IsHtml = true
|
||||
};
|
||||
|
||||
await _client.SendAsync(email);
|
||||
await _client.SendAsync(command);
|
||||
|
||||
Assert.True(true, "Verify in mailbox.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user