Nunit DynamicMock C# Presenter 类
我是 Nunit 测试的新手,我希望有人能为我提供一个简短的解释,甚至是一个网站链接,我可以在其中获得使用 DynamicMock.ExpectAndReturn 的很好的解释和示例代码。
我正在尝试 MVP 模式,我的演示者类已设置单元测试,如下所示
mock = new DynamicMock(typeof(I_MyInterface));
View = new MyPresenterClass((I_MyInterface)mock.MockInstance);
view.Initialise();
我有一个字符串属性“名称”,我想确保下面的代码是有效的演示者测试?我尝试了以下代码
mock.ExpectAndReturn("get_Name", "Yoda");
Assert.AreEqual("Yoda", ((I_MyInterface)mock.MockInstance).Name);
我的最后一个问题是,如何测试演示者正确返回值并正确设置属性的方法。例如,
public bool NameIt(int i)
{
if(i<20)
{
view.Name="Yoda";
return true;
}
return false;
}
有人可以告诉我如何通过动态模拟来测试这个方法吗?
先感谢您!
im new to Nunit testing and I was hoping someone could please provide me with a brief explaination or even a link to a site where I can get a nice explaination and example code for using DynamicMock.ExpectAndReturn.
Im trying out the MVP pattern, and my presenter class I have setup unit test as follows
mock = new DynamicMock(typeof(I_MyInterface));
View = new MyPresenterClass((I_MyInterface)mock.MockInstance);
view.Initialise();
I have a string property "Name", I wanted to make sure that the code below is a valid presenter test? I tried the following code
mock.ExpectAndReturn("get_Name", "Yoda");
Assert.AreEqual("Yoda", ((I_MyInterface)mock.MockInstance).Name);
My last question is, how can I test a method form my presenter correctly returned a value and set a property correctly. For example a method
public bool NameIt(int i)
{
if(i<20)
{
view.Name="Yoda";
return true;
}
return false;
}
Could someone please show me how I could test this via the dynamic mocking?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 ExpectAndReutrn。
完整的示例是 http://www.zorched.net /2007/03/10/mocking-net-objects-with-nunit/
You need to use ExpectAndReutrn.
Full example is http://www.zorched.net/2007/03/10/mocking-net-objects-with-nunit/