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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -