Refactor email handling for multiple recipients
Refactored the `Email` and `OutgoingEmailEvent` classes to replace the `Recipient` property with a `Recipients` collection, enabling support for multiple recipients. Updated all related test cases, including `EmailSenderTests`, `EmailSenderUrlOverloadTests`, and `OutgoingEmailPublisherTests`, to reflect this change. Moved the `EmailAccountDto` class and its references from the `DigitalData.MessagingService.Application.Common.Dtos` namespace to the `DigitalData.MessagingService.Publisher.Abstraction` namespace for better code organization. Updated `using` directives across affected files. Removed unused `using` directives and updated the `Email` class's `ToEvent` method to map the new `Recipients` property. Adjusted test assertions to validate collections instead of single recipient strings.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
using DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|
||||||
namespace DigitalData.MessagingService.Application.Common.Interfaces;
|
namespace DigitalData.MessagingService.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
using DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|
||||||
namespace DigitalData.MessagingService.Application.Common.Options;
|
namespace DigitalData.MessagingService.Application.Common.Options;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
using DigitalData.MessagingService.Application.Common.Options;
|
||||||
using DigitalData.MessagingService.Application.Common.Options;
|
using DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
|
||||||
using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
||||||
using DigitalData.MessagingService.Domain.Exceptions;
|
using DigitalData.MessagingService.Domain.Exceptions;
|
||||||
using DigitalData.MessagingService.Publisher.Abstraction;
|
using DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace DigitalData.MessagingService.Application.Common.Dtos;
|
namespace DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DTO for a single email account configuration.
|
/// DTO for a single email account configuration.
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
namespace DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|
||||||
namespace DigitalData.MessagingService.Publisher.Abstraction;
|
|
||||||
|
|
||||||
public record OutgoingEmailEvent
|
public record OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
|
||||||
using DigitalData.MessagingService.Application.Common.Interfaces;
|
using DigitalData.MessagingService.Application.Common.Interfaces;
|
||||||
using DigitalData.MessagingService.Domain.Exceptions;
|
using DigitalData.MessagingService.Domain.Exceptions;
|
||||||
using Limilabs.Client.SMTP;
|
using Limilabs.Client.SMTP;
|
||||||
using Limilabs.Mail;
|
using Limilabs.Mail;
|
||||||
using Limilabs.Mail.Headers;
|
using Limilabs.Mail.Headers;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using DigitalData.MessagingService.Application.Common.Options;
|
|
||||||
using DigitalData.MessagingService.Infrastructure.Services.Extensions;
|
using DigitalData.MessagingService.Infrastructure.Services.Extensions;
|
||||||
|
using DigitalData.MessagingService.Publisher.Abstraction;
|
||||||
|
|
||||||
namespace DigitalData.MessagingService.Infrastructure.Services;
|
namespace DigitalData.MessagingService.Infrastructure.Services;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using DigitalData.MessagingService.API.Middleware;
|
using DigitalData.MessagingService.API.Middleware;
|
||||||
using DigitalData.MessagingService.Application;
|
using DigitalData.MessagingService.Application;
|
||||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
|
||||||
using DigitalData.MessagingService.Infrastructure;
|
using DigitalData.MessagingService.Infrastructure;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Ui.Core.Extensions;
|
using Serilog.Ui.Core.Extensions;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public record Email
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recipient email address
|
/// Recipient email address
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Recipient { get; set; } = null!;
|
public IEnumerable<string> Recipients { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Email subject
|
/// Email subject
|
||||||
@@ -36,7 +36,7 @@ public record Email
|
|||||||
return new OutgoingEmailEvent
|
return new OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Recipient = Recipient,
|
Recipients = Recipients,
|
||||||
Subject = Subject,
|
Subject = Subject,
|
||||||
Body = Body,
|
Body = Body,
|
||||||
IsHtml = IsHtml,
|
IsHtml = IsHtml,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public sealed class EmailSenderTests
|
|||||||
{
|
{
|
||||||
var email = new Email
|
var email = new Email
|
||||||
{
|
{
|
||||||
Recipient = "hakanttek@gmail.com",
|
Recipients = ["hakanttek@gmail.com"],
|
||||||
Subject = "EmailSender.Send Integration Test",
|
Subject = "EmailSender.Send Integration Test",
|
||||||
Body = "<p>Sent via EmailSender static client.</p>",
|
Body = "<p>Sent via EmailSender static client.</p>",
|
||||||
IsHtml = true,
|
IsHtml = true,
|
||||||
@@ -93,7 +93,7 @@ public sealed class EmailSenderTests
|
|||||||
{
|
{
|
||||||
var email = new Email
|
var email = new Email
|
||||||
{
|
{
|
||||||
Recipient = "hakanttek@gmail.com",
|
Recipients = ["hakanttek@gmail.com"],
|
||||||
Subject = "Plain Text Test",
|
Subject = "Plain Text Test",
|
||||||
Body = "This is a plain text email.",
|
Body = "This is a plain text email.",
|
||||||
IsHtml = false
|
IsHtml = false
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public sealed class EmailSenderUrlOverloadTests
|
|||||||
{
|
{
|
||||||
var email = new Email
|
var email = new Email
|
||||||
{
|
{
|
||||||
Recipient = "url-overload-test@example.com",
|
Recipients = ["url-overload-test@example.com"],
|
||||||
Subject = "URL Overload Integration Test",
|
Subject = "URL Overload Integration Test",
|
||||||
Body = "<p>Sent after URL-based connection.</p>",
|
Body = "<p>Sent after URL-based connection.</p>",
|
||||||
IsHtml = true
|
IsHtml = true
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public sealed class OutgoingEmailPublisherTests : IAsyncDisposable
|
|||||||
var email = new OutgoingEmailEvent
|
var email = new OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Recipient = "test@example.com",
|
Recipients = ["test@example.com"],
|
||||||
Subject = "Integration Test - EnqueueAsync",
|
Subject = "Integration Test - EnqueueAsync",
|
||||||
Body = "<p>Hello from integration test.</p>",
|
Body = "<p>Hello from integration test.</p>",
|
||||||
IsHtml = true,
|
IsHtml = true,
|
||||||
@@ -62,7 +62,7 @@ public sealed class OutgoingEmailPublisherTests : IAsyncDisposable
|
|||||||
var emails = Enumerable.Range(1, 3).Select(i => new OutgoingEmailEvent
|
var emails = Enumerable.Range(1, 3).Select(i => new OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Recipient = $"recipient{i}@example.com",
|
Recipients = new List<string> { $"recipient{i}@example.com" },
|
||||||
Subject = $"Integration Test - Batch #{i}",
|
Subject = $"Integration Test - Batch #{i}",
|
||||||
Body = $"Batch message {i}",
|
Body = $"Batch message {i}",
|
||||||
IsHtml = false,
|
IsHtml = false,
|
||||||
@@ -85,7 +85,7 @@ public sealed class OutgoingEmailPublisherTests : IAsyncDisposable
|
|||||||
var email = new OutgoingEmailEvent
|
var email = new OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Recipient = "depth-test@example.com",
|
Recipients = ["depth-test@example.com"],
|
||||||
Subject = "Integration Test - GetQueueDepth",
|
Subject = "Integration Test - GetQueueDepth",
|
||||||
Body = "Queue depth test",
|
Body = "Queue depth test",
|
||||||
IsHtml = false,
|
IsHtml = false,
|
||||||
@@ -108,7 +108,7 @@ public sealed class OutgoingEmailPublisherTests : IAsyncDisposable
|
|||||||
var email = new OutgoingEmailEvent
|
var email = new OutgoingEmailEvent
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Recipient = "serialize@example.com",
|
Recipients = new List<string> { "serialize@example.com" },
|
||||||
Subject = "Serialization Test",
|
Subject = "Serialization Test",
|
||||||
Body = "<strong>Bold</strong>",
|
Body = "<strong>Bold</strong>",
|
||||||
IsHtml = true,
|
IsHtml = true,
|
||||||
@@ -123,7 +123,7 @@ public sealed class OutgoingEmailPublisherTests : IAsyncDisposable
|
|||||||
|
|
||||||
Assert.NotNull(received);
|
Assert.NotNull(received);
|
||||||
Assert.Equal(id, received.Id);
|
Assert.Equal(id, received.Id);
|
||||||
Assert.Equal("serialize@example.com", received.Recipient);
|
Assert.Equal(["serialize@example.com"], received.Recipients);
|
||||||
Assert.Equal("Serialization Test", received.Subject);
|
Assert.Equal("Serialization Test", received.Subject);
|
||||||
Assert.Equal("<strong>Bold</strong>", received.Body);
|
Assert.Equal("<strong>Bold</strong>", received.Body);
|
||||||
Assert.True(received.IsHtml);
|
Assert.True(received.IsHtml);
|
||||||
|
|||||||
Reference in New Issue
Block a user