How do I write a unit test for a method that use an external service like System.Net.Mail?
Do I just check a return value to see if there were any errors sending the email and assume if there were none that it was sent successfully?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Create a mock object for the mail service.
In short this will mean that you write a class that can replace the behavior of sending a mail. This way you can create different situations for your test very easy: a succeeded mail, a failed one, etc.
A nice and short introduction: http://www.programmersheaven.com/user/pheaven/blog/217-An-Introduction-to-Mock-Objects/
Another one, with code samples: http://blogs.clearscreen.com/ragc/archive/2004/08/31/395.aspx