Refactor Email to EmailContext across codebase

Replaced the `Email` record with the new `EmailContext` record to introduce additional context and functionality in email handling. Updated property definitions to distinguish between .NET Framework (`set`) and other frameworks (`init`).

Modified `SendingEmailEvent` to use `EmailContext` for the `Mail` property. Updated mappings in `EmailMappingProfile` to map `SendEmailCommand` to `EmailContext`. Adjusted `SendEmailCommandHandler` to use `EmailContext` when mapping requests.

Refactored `EmailSender` to use `EmailContext` in its `Send` method, including updates to method signatures and documentation. Updated all related test classes (`EmailSenderTests`, `EmailSenderUrlOverloadTests`, `SendingEmailPublisherTests`) to validate the behavior of `EmailContext`, ensuring consistency and thorough testing of the transition.

These changes ensure compatibility across frameworks and improve the maintainability of the email handling process.
This commit is contained in:
2026-08-05 14:06:41 +02:00
parent c6e67c0f99
commit 3cd8841e80
8 changed files with 14 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
namespace DigitalData.MessagingService.Abstraction;
public record Email
public record EmailContext
{
#if NETFRAMEWORK
public EmailAccountDto Sender { get; set; } = null!;

View File

@@ -9,9 +9,9 @@ public record SendingEmailEvent
#endif
#if NETFRAMEWORK
public Email Mail { get; set; } = null!;
public EmailContext Mail { get; set; } = null!;
#else
public required Email Mail { get; init; }
public required EmailContext Mail { get; init; }
#endif
#if NETFRAMEWORK

View File

@@ -13,6 +13,6 @@ public class EmailMappingProfile : Profile
{
// SendEmailCommand -> Email
// Sender is resolved via MediatR in the handler and set separately after mapping.
CreateMap<SendEmailCommand, Email>();
CreateMap<SendEmailCommand, EmailContext>();
}
}

View File

@@ -46,7 +46,7 @@ public class SendEmailCommandHandler(ISender Sender, ISendingEmailPublisher Publ
?? throw new NotFoundException(
$"No email account found for the given sender criteria (Id: {request.Sender.Id}, Username: {request.Sender.Username}).");
var email = Mapper.Map<Email>(request) with { Sender = senderAccount };
var email = Mapper.Map<EmailContext>(request) with { Sender = senderAccount };
// Enqueue to RabbitMQ
var sendingEmailEvent = new SendingEmailEvent()