我有这样的方法:
public string MyMethod(string a, string b)
{
if(a == "abcd" && b == "xyz")
return "good";
if(a == "xyz" && b == "something")
return "even better";
return "unexpected";
}
public string MainMethod()
{
string s1, s2;
if(some condition)
{
s1= "abcd";
s2 = "xyz";
}
return service.MyMethod(s1, s2);
}
我的模拟对象是这样创建的
AppObj obj = new AppObj();
Mockery mocks = new Mockery();
mockMyService = mocks.NewMock<IMyService>();
Expect.Once.On(mockMyService ).Method("MyMethod").
With("abcd", "xyz").
Will(Return.Value("good"));
obj.MainMethod();
Expect.Once.On(mockMyService ).Method("MyMethod").
With("xyz", "something").
Will(Return.Value("even better"));
obj.MainMethod();
上面代码的问题是,它总是接受第一个模拟方法的参数并返回“好”。我应该怎么做才能使 NMock 为具有不同参数值的同一方法返回不同的值?请帮忙!!