如何使用 Rhino Mocks 在 PartialMock 上模拟属性设置器
我想防止在部分类的属性上调用真正的设置器代码。
这个的语法是什么?
我当前的代码用于消除getter(我也想消除setter):
var user = MockRepository.GeneratePartialMock<User>(ctor params...);
user.MyProperty = "blah";
类似这样的东西吗?
user.Stub(u => u.MyProperty).Do(null);
I'd like to prevent the real setter code being invoked on a property on a partial class.
What is the syntax for this?
My current code to stub out the getter (I'd like to also stub out the setter):
var user = MockRepository.GeneratePartialMock<User>(ctor params...);
user.MyProperty = "blah";
Something like this?
user.Stub(u => u.MyProperty).Do(null);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 3.5 示例,可以满足您的需要(我认为您上面的语法是 3.1 或 3.2)。
首先,我有一个用于属性设置器调用的委托:
然后除了“Do”之外,还使用带有“SetPropertyAndIgnoreArgument”的 Expect.Call:
Here's a 3.5 sample that does what you need (I think your syntax above is 3.1 or 3.2).
First, I have a delegate for the property setter call:
Then use the Expect.Call with "SetPropertyAndIgnoreArgument" in addition to the "Do":