执行单元测试时,我在模拟一个方法时出错了。我试图根据要输入的参数返回不同的结果,否则返回一个默认的答案。问题是,我总是收到默认的答案。
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.WithAnyArguments().WillReturn(-1);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("",false,null))
.With("BAG1", true, FamilyFaresType.Optima).WillReturn(0);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.With("BAG2", true, FamilyFaresType.Optima).WillReturn(87);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.With("BAG3", true, FamilyFaresType.Optima).WillReturn(139);
发布于 2014-08-07 08:53:51
错误在于行的顺序。行返回默认的"WithAnyArguments“必须在带有参数" with”的定义之后。
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("",false,null))
.With("BAG1", true, FamilyFaresType.Optima).WillReturn(0);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.With("BAG2", true, FamilyFaresType.Optima).WillReturn(87);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.With("BAG3", true, FamilyFaresType.Optima).WillReturn(139);
_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
.WithAnyArguments().WillReturn(-1);
https://stackoverflow.com/questions/25178163
复制相似问题