如何使用Rhino Mock 模拟未实现的方法?
我有这个简化的实现和单元测试如下:
public class Parent
{
public virtual int GetSomeValue()
{
throw new NotImplementedException();
}
}
public class Child
{
public Parent MyParent { get; set; }
public virtual Parent GetParent()
{
return MyParent;
}
public virtual int GetParentsValue()
{
var parent = GetParent();
return parent.GetSomeValue();
}
}
How can I test the GetParentsValue() method with Rhino Mock without Implement the Parent's GetSomeValue() method?
谢谢!
I have this simplified implementation and the unit test below:
public class Parent
{
public virtual int GetSomeValue()
{
throw new NotImplementedException();
}
}
public class Child
{
public Parent MyParent { get; set; }
public virtual Parent GetParent()
{
return MyParent;
}
public virtual int GetParentsValue()
{
var parent = GetParent();
return parent.GetSomeValue();
}
}
How can I test the GetParentsValue() method with Rhino Mock without implement the parent's GetSomeValue() method?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:
You can do this:
您可以使用以下代码:
如果您想测试 GetParentsValue() 方法的一些内部原理,您应该使用以下代码模拟
Parent.GetSomeValue()
:You can use this code:
If you want to test some internals of the GetParentsValue() method you should mock
Parent.GetSomeValue()
with: