Using nDumbster with Nunit

The following example shows a simple NUnit test written in C# which creates a server listening on port 2525 at the start of each test, sends a message to it, then checks the message was sent correctly.

public class SimpleSmtpServerTest
    private SimpleSmtpServer smtpServer;

    public void Setup()
        this.smtpServer = SimpleSmtpServer.Start(2525);

    public void TearDown()

    public void SendMessage_Should_Send_A_Single_Message_To_The_Specified_User
        // Arrange

        // Act
        // Call your own message sending code here.
        sendMessage(2525, "", "Test", "Test Body", "");

        // Assert
        Assert.AreEqual(1, this.smtpServer.ReceivedEmailCount, "1 mails sent");
        SmtpMessage mail= this.smtpServer.ReceivedEmail[0];
        Assert.AreEqual("<>", mail.Headers["To"], "Receiver");
        Assert.AreEqual("<>", mail.Headers["From"], "Sender");
        Assert.AreEqual("Test", mail.Headers["Subject"], "Subject");
        Assert.AreEqual("Test Body", mailUser.Body, "Body");

Last edited Apr 15, 2011 at 5:52 PM by blowdart, version 6


No comments yet.