Files
DigitalData.MessagingService/tests/DigitalData.MessagingService.Tests/Integration/EmailSenderUrlOverloadTests.cs
TekH c73d8d8f36 Refactor EmailSender to use new Email abstraction
Introduced a new `Email` record to simplify the representation of outgoing email messages. Updated the `EmailSender.Send` method to accept `Email` instead of `OutgoingEmailEvent`, with a `ToEvent()` method handling the conversion internally.

Refactored test cases to use the `Email` record, removing redundant properties (`Id` and `QueuedAt`) that are now auto-generated. Updated XML documentation to reflect these changes. Adjusted namespaces and added necessary `using` directives for proper referencing.

These changes improve code readability, maintainability, and centralize the mapping logic for outgoing email events.
2026-07-29 14:36:10 +02:00

73 lines
2.6 KiB
C#

using DigitalData.MessagingService.Client;
using DigitalData.MessagingService.Publisher.Abstraction;
namespace DigitalData.MessagingService.Tests.Integration;
/// <summary>
/// Integration tests for the URL-based <see cref="EmailSender.ConnectRabbitMq(string, string, string, OnReconnect)"/>
/// overload. All tests run inside <see cref="EmailSenderCollection"/> so they share the already-established
/// static connection. The URL overload is exercised via <see cref="OnReconnect.Ignore"/> and
/// <see cref="OnReconnect.ThrowException"/> to verify its delegation and guard behavior.
/// </summary>
[Collection(EmailSenderCollection.Name)]
public sealed class EmailSenderUrlOverloadTests
{
private static readonly string ValidUrl = $"amqp://{RabbitMqTestConfig.HostName}:{RabbitMqTestConfig.Port}";
private static readonly string ValidUrlWithVHost = $"amqp://{RabbitMqTestConfig.HostName}:{RabbitMqTestConfig.Port}/myvhost";
[Fact]
public void ConnectRabbitMq_UrlOverload_WhenAlreadyConnected_WithIgnore_DoesNotThrow()
{
var exception = Record.Exception(() =>
EmailSender.ConnectRabbitMq(
ValidUrl,
RabbitMqTestConfig.UserName,
RabbitMqTestConfig.Password,
OnReconnect.Ignore));
Assert.Null(exception);
}
[Fact]
public void ConnectRabbitMq_UrlOverload_WhenAlreadyConnected_WithThrowException_Throws()
{
Assert.Throws<InvalidOperationException>(() =>
EmailSender.ConnectRabbitMq(
ValidUrl,
RabbitMqTestConfig.UserName,
RabbitMqTestConfig.Password,
OnReconnect.ThrowException));
}
[Fact]
public void ConnectRabbitMq_UrlOverload_WithVHostInPath_WithIgnore_DoesNotThrow()
{
var exception = Record.Exception(() =>
EmailSender.ConnectRabbitMq(
ValidUrlWithVHost,
RabbitMqTestConfig.UserName,
RabbitMqTestConfig.Password,
OnReconnect.Ignore));
Assert.Null(exception);
}
[Fact]
public void Send_AfterUrlOverloadConnection_DoesNotThrow()
{
var email = new Email
{
Recipient = "url-overload-test@example.com",
Subject = "URL Overload Integration Test",
Body = "<p>Sent after URL-based connection.</p>",
IsHtml = true
};
// Connection was established via Action<> overload in the fixture;
// Send should work regardless of which overload was used to connect.
var exception = Record.Exception(() => EmailSender.Send(email));
Assert.Null(exception);
}
}