系统发邮件测试 Dumbster
当我们系统要用Junit 测试批量发邮件功能的时候,
既要测试 这功能是否正常。
但又不能真正意义上的把邮件发出去。
在这里有个不错的类库。帮我们解决 了问题。
http://ndumbster.sourceforge.net/
示例:
SimpleSmtpServer server;
public BatchEmailTest()
{
server = null;
server = SimpleSmtpServer.Start();
}
[Test]
public void TestBatchEmail()
{
ISiteUserService iSiteUser = ServiceFactory.GetInstance().GetService(typeof(ISiteUserService)) as ISiteUserService;
Hashtable hs = new Hashtable();
IList mailList = iSiteUser.GetBatchEmailList(hs);
SmtpMail.SmtpServer = "localhost";
for (int i = 0; i < mailList.Count; i++)
{
//send mail
MailMessage message = new MailMessage();
message.Subject = "Subject";
message.Body = "Send Body..";
message.From = "test@cwave.com";
message.To = mailList[i].ToString();
SmtpMail.Send(message);
}
Assert.AreEqual(mailList.Count, server.ReceivedEmailCount);
for (int j = 0; j < server.ReceivedEmailCount; j++)
{
SmtpMessage email = server.ReceivedEmail[j];
Assert.AreEqual("<test@cwave.com>", email.Headers["From"]);
Assert.AreEqual("<" + mailList[j].ToString() + ">", email.Headers["To"]);
Assert.AreEqual("Subject", email.Headers["Subject"]);
Assert.AreEqual("Send Body..", email.Body);
}
}
[TestFixtureTearDown]
public void TearDown()
{
if (server != null)
server.Stop();
}
}
希望对你有用!
posted on 2006-10-30 13:01 hello csharp 阅读(710) 评论(0) 编辑 收藏 举报