So I have some SMTP stuff in my code and I am trying to unit test that method.
So I been trying to Mockup MailMessage but it never seems to work. I think none of the met
In .NET 4.0 you can use the "duck-typing" to pass another class instead of "System.Net.Mail". But in earlier version, I'm afraid there is no another way, than create wrapper around "System.Net.Mail" nad the mock class.
If is another (better) way, I would like to learn it :).
EDIT:
public interface IMailWrapper {
/* members used from System.Net.Mail class */
}
public class MailWrapper {
private System.Net.Mail original;
public MailWrapper( System.Net.Mail original ) {
this.original = original;
}
/* members used from System.Net.Mail class delegated to "original" */
}
public class MockMailWrapper {
/* mocked members used from System.Net.Mail class */
}
void YourMethodUsingMail( IMailWrapper mail ) {
/* do something */
}