Replaced `DigitalData.MessagingService.Client.DependencyInjection` namespace with `DigitalData.MessagingService.Client` across the codebase to simplify and streamline the project structure. Removed unused `Microsoft.Extensions.Logging` and `System` dependencies from `EmailSender.cs`. Updated project references in `DigitalData.MessagingService.Tests.csproj` to reflect the namespace and project restructuring. Adjusted `using` directives in test files to align with the new namespace.
75 lines
2.7 KiB
C#
75 lines
2.7 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 OutgoingEmailEvent
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Recipient = "url-overload-test@example.com",
|
|
Subject = "URL Overload Integration Test",
|
|
Body = "<p>Sent after URL-based connection.</p>",
|
|
IsHtml = true,
|
|
QueuedAt = DateTime.Now
|
|
};
|
|
|
|
// 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);
|
|
}
|
|
}
|