September
11th,
2006
Last week I needed a way to unit-test some code I was about to write that sent notification emails, and ran into SmtpMock. Nifty little bugger. Here's some sample code using it:
[Test]
public void CanSendMailSuccessfully()
{
// set up mocks for config, windsor
MockRepository mocks = CreateMocks();
mocks.ReplayAll();
// start mock SMTPServer
SmtpMock smtpServer = new SmtpMock();
smtpServer.Start();
// call sender
IMailSender sender = new MailSender();
sender.SendReport(new Exception("ExceptionTest"));
// check mock server
mocks.VerifyAll();
smtpServer.Stop();
Assert.AreEqual(1, smtpServer.Sessions.Length);
}