Refactor email handling for improved structure
Refactored `Email` and `SendingEmailEvent` to use `record` types, consolidating email-related data into the `Email` class. Updated `SendEmailCommand` to return a `Guid` and simplified mapping logic in `EmailMappingProfile`. Adjusted `SendEmailCommandHandler` to construct `SendingEmailEvent` manually. Updated `SendingEmailConsumer`, `EmailsController`, and `EmailSender` to reflect the new structure. Removed the old `Email` implementation. Improved logging to reference the `Mail` property. Revised tests to align with the new structure, ensuring immutability and better separation of concerns.
This commit is contained in:
@@ -37,10 +37,14 @@ public sealed class SendingEmailPublisherTests : IAsyncDisposable
|
||||
var email = new SendingEmailEvent
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Recipients = ["test@example.com"],
|
||||
Subject = "Integration Test - EnqueueAsync",
|
||||
Body = "<p>Hello from integration test.</p>",
|
||||
IsHtml = true,
|
||||
Mail = new Email
|
||||
{
|
||||
Sender = new EmailAccountDto { Username = "test@example.com", Password = "password", SmtpServer = "smtp.example.com" },
|
||||
Recipients = ["test@example.com"],
|
||||
Subject = "Integration Test - EnqueueAsync",
|
||||
Body = "<p>Hello from integration test.</p>",
|
||||
IsHtml = true,
|
||||
},
|
||||
QueuedAt = DateTime.Now
|
||||
};
|
||||
|
||||
@@ -62,10 +66,14 @@ public sealed class SendingEmailPublisherTests : IAsyncDisposable
|
||||
var emails = Enumerable.Range(1, 3).Select(i => new SendingEmailEvent
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Recipients = new List<string> { $"recipient{i}@example.com" },
|
||||
Subject = $"Integration Test - Batch #{i}",
|
||||
Body = $"Batch message {i}",
|
||||
IsHtml = false,
|
||||
Mail = new Email
|
||||
{
|
||||
Sender = new EmailAccountDto { Username = "test@example.com", Password = "password", SmtpServer = "smtp.example.com" },
|
||||
Recipients = new List<string> { $"recipient{i}@example.com" },
|
||||
Subject = $"Integration Test - Batch #{i}",
|
||||
Body = $"Batch message {i}",
|
||||
IsHtml = false,
|
||||
},
|
||||
QueuedAt = DateTime.Now
|
||||
}).ToList();
|
||||
|
||||
@@ -85,10 +93,14 @@ public sealed class SendingEmailPublisherTests : IAsyncDisposable
|
||||
var email = new SendingEmailEvent
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Recipients = ["depth-test@example.com"],
|
||||
Subject = "Integration Test - GetQueueDepth",
|
||||
Body = "Queue depth test",
|
||||
IsHtml = false,
|
||||
Mail = new Email
|
||||
{
|
||||
Sender = new EmailAccountDto { Username = "test@example.com", Password = "password", SmtpServer = "smtp.example.com" },
|
||||
Recipients = ["depth-test@example.com"],
|
||||
Subject = "Integration Test - GetQueueDepth",
|
||||
Body = "Queue depth test",
|
||||
IsHtml = false,
|
||||
},
|
||||
QueuedAt = DateTime.Now
|
||||
};
|
||||
|
||||
@@ -108,10 +120,14 @@ public sealed class SendingEmailPublisherTests : IAsyncDisposable
|
||||
var email = new SendingEmailEvent
|
||||
{
|
||||
Id = id,
|
||||
Recipients = new List<string> { "serialize@example.com" },
|
||||
Subject = "Serialization Test",
|
||||
Body = "<strong>Bold</strong>",
|
||||
IsHtml = true,
|
||||
Mail = new Email
|
||||
{
|
||||
Sender = new EmailAccountDto { Username = "test@example.com", Password = "password", SmtpServer = "smtp.example.com" },
|
||||
Recipients = new List<string> { "serialize@example.com" },
|
||||
Subject = "Serialization Test",
|
||||
Body = "<strong>Bold</strong>",
|
||||
IsHtml = true,
|
||||
},
|
||||
QueuedAt = DateTime.Now
|
||||
};
|
||||
|
||||
@@ -123,10 +139,10 @@ public sealed class SendingEmailPublisherTests : IAsyncDisposable
|
||||
|
||||
Assert.NotNull(received);
|
||||
Assert.Equal(id, received.Id);
|
||||
Assert.Equal(["serialize@example.com"], received.Recipients);
|
||||
Assert.Equal("Serialization Test", received.Subject);
|
||||
Assert.Equal("<strong>Bold</strong>", received.Body);
|
||||
Assert.True(received.IsHtml);
|
||||
Assert.Equal(["serialize@example.com"], received.Mail.Recipients);
|
||||
Assert.Equal("Serialization Test", received.Mail.Subject);
|
||||
Assert.Equal("<strong>Bold</strong>", received.Mail.Body);
|
||||
Assert.True(received.Mail.IsHtml);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user