Stubbing on a Partial Mock with RhinoMocks
In RhinoMocks, when you use a partial mock, you can stub virtual methods and call AssertWasCalled later. But just stubbing won't do. If you don't give it an implementation as a substitute to the actual implementation, RhinoMocks will still call the actual method.
You can avoid this by passing an empty method to the Do
method:
this.mailSender = MockRepository.GeneratePartialMock<MailSender>();
this.mailSender
.Stub(x => x.SendMail(theMailObject, options))
.Do(new Action<MailObject, MailOptions>((m, o) => { }));
Then you can do:
this.mailSender.AssertWasCalled(x => x.SendMail(theMailObject, options));
Written by Peter Morlion
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tdd
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#