tdd - Mocking MailController with ActionMailer.net using Moq -
i'm trying mock mailcontroller
_mockmailcontroller = new mock<imailcontroller>(); _mockmailcontroller.setup(x => x.forgotpassword("test@email.com"));
my controller takes imailcontroller
dependancy, when call
mailcontroller.forgotpassword("test@email.com").deliver();
i nullreferenceexception (because forgotpassword
doesn't return anything, guess)
ideally, we'd stub emailresult
?
i created pull request actionmailer.net intoduces iemailresult interface makes mocking easy. have @ this:
https://bitbucket.org/swaj/actionmailer.net/pull-request/4/iemailresult-interface-for-better/
until pull request merged use custom build frok of project.
https://bitbucket.org/hydr/xv-actionmailer.net
mocking get's easy writing (with fakeiteasy, moq might similar):
//setup _mymailer = a.fake<imymailer>(); //later on in assert a.callto(() => _mymailer.mytestemail()).musthavehappened(repeated.exactly.once);
when mailer defined like:
public class mailcontroller : mailerbase, imymailer { public iemailresult mytestemail() { to.add("recipient@sdf.com"); = "sender@sdf.com"; subject = "subject"; return email(); } }
Comments
Post a Comment