SmtpMock

Link. September 11, 2006. Comments [0]. Posted in: .NET

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);

}

 



Comments are closed.

About

Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...

tomasrestrepo @ twitter My Flickr photostream My saved links on delicious My Technorati Profile

email: tomas@winterdom.com
msn: tomasr@passport.com

View my profile on LinkedIn

MVP logo

Syndicate

Ads


Links

Categories

Statistics

Total Posts: 1022
This Year: 92
This Month: 11
This Week: 0
Comments: 791

Blogroll

Post Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.1.8139.823

Sign In