犀牛制品 - 设置属性,如果一个方法被调用 [英] 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())<STRONG>的SetProperty(callMonitor.InACall = FALSE)。
callMonitor.Expect(x=>x.HangUp()).SetProperty(callMonitor.InACall = false);
挂断方法返回void,我真的不能改变这一点。但我想我的存根知道电话被挂断时挂断被调用。
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.
推荐答案
您可以使用WhenCalled方法来运行自己当存根被称为代码;肯定它应与嘲笑的工作了。根据该文件,WhenCalled是更换/升级回调
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);
在这篇文章的最后一些信息:
的http://grahamnash.blogspot.com/2008/10/rhino-mocks-35.html
这篇关于犀牛制品 - 设置属性,如果一个方法被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!