我有一个正在嘲笑的函数,它接受一个参数对象作为参数。我想根据对象中的值返回结果。我无法比较对象,因为 Equals 未被覆盖。
我有以下代码:
_tourDal.Stub(x => x.GetById(Arg<TourGet>.Matches(y => y.TourId == 2), null)).Return(
new Tour()
{
TourId = 2,
DepartureLocation = new IataInfo() { IataId = 2 },
ArrivalLocation = new IataInfo() { IataId = 3 }
});
当提供的参数的 TourId 为 2 时,这应该返回指定的对象。
这看起来应该可以工作,但是当我运行它时,出现以下异常:
使用 Arg 时,所有参数都必须使用 Arg.Is 定义,
Arg.Text、Arg.List、Arg.Ref 或 Arg.Out。 2 个参数
预计 1 已被定义。
我需要做什么来解决这个问题有什么想法吗?
您需要对第二个空参数使用相同的语法,大致如下(我还没有测试过):
_tourDal.Stub(x => x.GetById(Arg<TourGet>.Matches(y => y.TourId == 2), Arg<TypeName>.Is.Null)).Return(
new Tour()
{
TourId = 2,
DepartureLocation = new IataInfo() { IataId = 2 },
ArrivalLocation = new IataInfo() { IataId = 3 }
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)