Rhino 模拟存根中私人设置器的问题
错误:
您正在尝试设定一个期望 在定义为使用的属性上 财产行为。而不是写作 代码如下:mockObject.Stub(x => x.SomeProperty).Return(42);可以直接使用该属性来实现 相同的结果: 模拟对象.SomeProperty = 42;
var x = MockRepository.GenerateStub<MyClass>();
x.Stub(s => s.Items).Return(new List<Item>());
public class MyClass
{
public virtual IEnumerable<Item> Items
{
get {return _items;}
private set {_items = value;}
}
}
我做错了什么?
Error:
You are trying to set an expectation
on a property that was defined to use
PropertyBehavior. Instead of writing
code such as this: mockObject.Stub(x
=> x.SomeProperty).Return(42); You can use the property directly to achieve
the same result:
mockObject.SomeProperty = 42;
var x = MockRepository.GenerateStub<MyClass>();
x.Stub(s => s.Items).Return(new List<Item>());
public class MyClass
{
public virtual IEnumerable<Item> Items
{
get {return _items;}
private set {_items = value;}
}
}
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为使用模拟而不是存根可以解决这个问题,但我可能缺少更好的方法。
I think using a Mock rather than a stub gets around the problem, but there may be a better way I'm missing.
比这更干净的方法:
我只是不明白为什么GenerateStub不起作用。
A cleaner way than would be:
I just don't get why GenerateStub doesn't work.
我收到了同样的消息。我的问题是我试图在具体类上存根非虚拟属性。
I received this same message. My issue was that I was trying to stub a non-virtual property on a concrete class.