Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
318 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...