Share

nDumbster

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

System.Net.Mail / Unit Test Runner in R#4.1

You are viewing a single message from this topic. View all messages.

  1. 2008-09-27 19:12:25 UTC
    I have seen the same problem and got a workground at least for single emails

    The following test (returning in a second or so)

    [TestMethod]
    public void CanRecieveSingleWebMail()
    {
    System.Web.Mail.SmtpMail.SmtpServer = "localhost";
    System.Web.Mail.SmtpMail.Send("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
    Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
    }

    However the test using System.Net.Mail fails


    [TestMethod]
    public void CanRecieveSingleNetMail()
    {
    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
    client.Send(msg);
    Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
    }

    Take 100 seconds to return, after a bit of debugging I found the problem was the final input.ReadLine(); in HandleSmtpTranslation which we expect to get a null at the end of a message, for Systsem.Web.Mail this returns instantly, but for System.Net.Mail this takes 100 second, but then is fine. But the 100 second delay is a bit of a pain for TDD!

    As a work round I have put in the logic of HandleSmtpTranslation

    string line = null;
    if (smtpState != SmtpState.QUIT)
    {
    line = input.ReadLine();
    }

    if (line == null)
    {
    break;
    }

    Both the above tests now work. However if you send more than one email in a batch (multiple sends) it works for System.Web.Mail but not for System.Net.Mail - the error now appears when the second maiil is sent saying the server is not there. I suspect a thread issue as I think System.Web.Mail was single threaded

    Anyway hope this gets you going
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.