2757869176
Add contract validation, SMTP delivery results, terminal failure context, neutral development seeding, and local Docker setup. Ref: IT-1033
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
namespace HrynCo.NotificationService.Services.Tests.EmailProcessing;
|
|
|
|
using HrynCo.NotificationService.Worker.Services.EmailProcessing;
|
|
using System.Net.Mail;
|
|
using System.Net.Sockets;
|
|
|
|
public sealed class NotificationDeliveryErrorFormatterTests
|
|
{
|
|
[Fact]
|
|
public void Format_UsesInnermostMessageAndRemovesLineBreaks()
|
|
{
|
|
var exception = new InvalidOperationException(
|
|
"outer",
|
|
new Exception("provider failed\r\nretry rejected"));
|
|
|
|
string result = NotificationDeliveryErrorFormatter.Format(exception);
|
|
|
|
Assert.Equal(
|
|
"Notification delivery failed after all retry attempts (provider failed retry rejected).",
|
|
result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Format_UnresolvedSmtpHost_AddsSafeChannelContext()
|
|
{
|
|
var socketException = new SocketException((int)SocketError.HostNotFound);
|
|
var exception = new SmtpException("Failure sending mail.", socketException);
|
|
|
|
string result = NotificationDeliveryErrorFormatter.Format(exception);
|
|
|
|
Assert.Equal(
|
|
$"SMTP delivery failed after all retry attempts: the configured SMTP server host could not be resolved ({socketException.Message}).",
|
|
result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Format_RefusedSmtpConnection_AddsSafeChannelContext()
|
|
{
|
|
var socketException = new SocketException((int)SocketError.ConnectionRefused);
|
|
var exception = new SmtpException("Failure sending mail.", socketException);
|
|
|
|
string result = NotificationDeliveryErrorFormatter.Format(exception);
|
|
|
|
Assert.Equal(
|
|
$"SMTP delivery failed after all retry attempts: the configured SMTP server refused the connection ({socketException.Message}).",
|
|
result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Format_LongError_IsBoundedToOutboxColumnLength()
|
|
{
|
|
var exception = new Exception(new string('x', 2100));
|
|
|
|
string result = NotificationDeliveryErrorFormatter.Format(exception);
|
|
|
|
Assert.Equal(2000, result.Length);
|
|
}
|
|
}
|