Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks - Set a property if a method is called

Is there a way with Rhino Mocks to set a property of a Stub if a method is called.

Something like this: (Fake Code in bold)

callMonitor.Expect(x=>x.HangUp()).SetProperty(callMonitor.InACall = false);

The HangUp method returns void and I can't really change that. But I want my stub to know that the call was hung up when HangUp is called.

like image 437
Vaccano Avatar asked Aug 28 '09 21:08

Vaccano


2 Answers

You can use the "WhenCalled" method to run your own code when a stub is called; pretty sure it should work with Mocks, too. According to the documentation, WhenCalled is a replacement/upgrade for Callback.

callMonitor.Expect(x => x.HangUp())
.WhenCalled(invocation => callMonitor.InCall = false);

Some info at the end of this post: http://grahamnash.blogspot.com/2008/10/rhino-mocks-35.html

like image 81
Mark Simpson Avatar answered Nov 03 '22 19:11

Mark Simpson


Yes, you can use the Callback method:

 callMonitor.Expect(x => x.HangUp()).Callback(() => callMonitor.InCall = false);
like image 40
Mark Seemann Avatar answered Nov 03 '22 19:11

Mark Seemann