Files
DigitalData.MessagingService/tests/DigitalData.MessagingService.Tests/Integration/EmailSenderUrlOverloadTests.cs
TekH 601fd9be5f Refactor: Consolidate Publisher.Abstraction into Abstraction
The `DigitalData.MessagingService.Publisher.Abstraction` project has been removed, and its functionality has been merged into a new project named `DigitalData.MessagingService.Abstraction`.

- Updated namespaces from `Publisher.Abstraction` to `Abstraction` across all relevant files, including DTOs, interfaces, and classes.
- Modified the solution file to remove `Publisher.Abstraction` and add `Abstraction`, updating solution configurations and nested project mappings.
- Replaced project references to `Publisher.Abstraction` with `Abstraction` in all affected project files.
- Updated tests and integration tests to reflect the namespace and project changes.
- Refactored application-level files such as `EmailMappingProfile` and `DependencyInjection.cs` to use the new namespace.

This refactor simplifies the project structure and ensures consistency across the solution.
2026-08-05 13:16:03 +02:00

73 lines
2.6 KiB
C#

using DigitalData.MessagingService.Client;
using DigitalData.MessagingService.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
{
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);
}
}