RhinoMocks 使用属性的默认实现
我有一些与实体框架一起使用的代码,例如
class Person{
pubic Person() {
Address = new Address();
}
public virtual Address Address { get; set; }
}
我将 Address
标记为 virtual
的原因是为了延迟加载。
现在为了测试,我正在对 Person
进行存根处理。但由于它是存根的,Address
getter 只是返回 null
(即使它是在构造函数中设置的)。如果我存根 Address
属性 (person.Stub(x => x.Address).Return(new Address());
) ,一切正常。但我真的不想把财产毁掉!有没有办法告诉RhinoMocks不要重写这个getter,即使它是虚拟的?
I have some code that I use with Entity Framework like
class Person{
pubic Person() {
Address = new Address();
}
public virtual Address Address { get; set; }
}
The reason I'm marking Address
as virtual
is for lazy loading.
Now to test, I'm stubbing the Person
. But since it's stubbed, the Address
getter just returns null
(even though it's set in the constructor). If I stub out the Address
property (person.Stub(x => x.Address).Return(new Address());
) things work fine. But I don't really want to have to stub out the property! Is there any way to tell RhinoMocks not to override this getter even though it's virtual?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然可以,但是你必须使用部分模拟:
Sure, but you have to use a partial mock: