Introduce Yavsc.Interfaces.ISmtpClient and a recording test fake
Narrow ISmtpClient to the four operations MailSender actually uses, behind a Yavsc.Interfaces.ISmtpClientFactory. Production wires MailKitSmtpClient (SmtpClientFactory); tests wire a recording fake (RecordingSmtpClientFactory). The fake is pre-registered in WebServerFixture so SMTP calls are short-circuited; the EMailling test now asserts the Connect -> Authenticate -> Send -> Disconnect sequence. Yavsc.Abstract stays free of MailKit/MimeKit.
This commit is contained in:
parent
16508e9fb2
commit
2dec799d71
13 changed files with 264 additions and 10 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Interface;
|
||||
using Yavsc.Interfaces;
|
||||
using Yavsc.Org.Tests.Fakes;
|
||||
|
||||
namespace Yavsc.Org.Tests
|
||||
{
|
||||
|
|
@ -26,6 +28,8 @@ namespace Yavsc.Org.Tests
|
|||
|
||||
using IServiceScope scope = _serverFixture.Services.CreateScope();
|
||||
ITrueEmailSender mailSender = scope.ServiceProvider.GetRequiredService<ITrueEmailSender>();
|
||||
var factory = Assert.IsType<RecordingSmtpClientFactory>(
|
||||
scope.ServiceProvider.GetRequiredService<ISmtpClientFactory>());
|
||||
|
||||
output.WriteLine("SendEMailSynchrone ...");
|
||||
mailSender.SendEmailAsync
|
||||
|
|
@ -35,6 +39,21 @@ namespace Yavsc.Org.Tests
|
|||
$"monthly email",
|
||||
"test boby monthly email").Wait();
|
||||
|
||||
// Assert the SMTP roundtrip was short-circuited by the
|
||||
// recording fake installed in WebServerFixture: exactly
|
||||
// one client was created and it saw the expected sequence
|
||||
// of Connect → Authenticate → Send → Disconnect.
|
||||
var client = Assert.Single(factory.Created);
|
||||
Assert.Equal(
|
||||
new[]
|
||||
{
|
||||
RecordingSmtpCallKind.Connect,
|
||||
RecordingSmtpCallKind.Authenticate,
|
||||
RecordingSmtpCallKind.Send,
|
||||
RecordingSmtpCallKind.Disconnect,
|
||||
},
|
||||
client.Calls.Select(c => c.Kind).ToArray());
|
||||
Assert.Equal(_serverFixture.SiteSettings.Owner.EMail, client.LastSentMessage?.To.Mailboxes.First().Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue