我是Moq的新手并且正在学习.
我需要测试一个方法返回预期的值.我已经整理了一个例子来解释我的问题.这失败了:
"ArgumentException:Expression不是方法调用:c =>(c.DoSomething("Jo","Blog",1)="OK")"
你能纠正我做错的事吗?
[TestFixtureAttribute, CategoryAttribute("Customer")]
public class Can_test_a_customer
{
[TestAttribute]
public void Can_do_something()
{
var customerMock = new Mock<ICustomer>();
customerMock.Setup(c => c.DoSomething("Jo", "Blog", 1)).Returns("OK");
customerMock.Verify(c => c.DoSomething("Jo", "Blog", 1)=="OK");
}
}
public interface ICustomer
{
string DoSomething(string name, string surname, int age);
}
public class Customer : ICustomer
{
public string DoSomething(string name, string surname, int age)
{
return "OK";
}
}
Run Code Online (Sandbox Code Playgroud)
简而言之:如果我想测试一个像上面那样的方法,并且我知道我期待回到"OK",我将如何使用Moq编写它?
谢谢你的任何建议.
moq ×1