Files
DigitalData.MessagingService/tests/DigitalData.MessagingService.Tests/Integration/EmailSenderUrlOverloadTests.cs
TekH b2857c558f Refactor: Replace EmailAccountDto with EmailAccount
Replaced the `EmailAccountDto` class with the `EmailAccount` class across the codebase to consolidate the `EmailAccount` entity into the domain layer. Updated namespaces, method signatures, property types, and test cases to reflect this change.

Moved `EmailAccount` from `DigitalData.MessagingService.Application.Common.Dto` to `DigitalData.MessagingService.Domain.Entities`. Updated XML documentation and removed redundant project file entries. Adjusted namespaces for related queries, validators, and commands to align with the new structure.

These changes improve separation of concerns and align with domain-driven design principles.
2026-08-12 15:26:15 +02:00

75 lines
2.8 KiB
C#

using DigitalData.MessagingService.Application.Common.Dto;
using DigitalData.MessagingService.Client;
using DigitalData.MessagingService.Domain.Entities;
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 EmailContext
{
Sender = new EmailAccount { Username = "test@example.com", Password = "password", SmtpServer = "smtp.example.com" },
Recipients = ["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);
}
}