I have in my controller action (I removet try/catch block for more clear code):
[HttpPost]
public ActionResult SendMessage(ContactViewModel model)
{
if (ModelState.IsValid)
{
MailMessage message = new MailMessage();
var administrator = new MailAddress("xxxx@gmail.com");
var customer = new MailAddress(model.Email, model.Name);
message.Bcc.Add(customer);
message.Bcc.Add(administrator);
message.Subject = "Message Subject";
message.Body = model.Message;
SmtpClient client = new SmtpClient();
client.Send(message);
}
return PartialView("_ContactPartial", model);
}
The action works correctly, the info about host are in web.config.
I want create unit test's for this action. I created in my project with test web.config:
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\MailTest\"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
And there is basic unit test:
[TestMethod]
public void ContactControllerTest_SendMessage_PartialView()
{
//Arrange
var controller = new ContactController();
//Act
var result = controller.SendMessage(contactViewModel) as PartialViewResult;
//Asset
Assert.AreEqual("_ContactPartial", result.ViewName");
}
In the line
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
I have exception: The SMTP host was not specified. Why it need it if in my web.config I selected SpecifiedPickupDirectory as delivery method?
Aucun commentaire:
Enregistrer un commentaire