Last Updated: February 25, 2016
·
3.149K
· petermorlion

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));