小编Tri*_*tan的帖子

犀牛嘲笑 - 使用Arg.Matches

我有一个我正在模拟的函数,它将一个参数对象作为参数.我想根据对象中的值返回结果.我无法比较对象,因为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 }
                });
Run Code Online (Sandbox Code Playgroud)

这应该返回当提供的参数的TourId为2时指定的对象.

这看起来应该可以工作,但是当我运行它时,我得到以下异常:

使用Arg时,必须使用Arg.Is,Arg.Text,Arg.List,Arg.Ref或Arg.Out定义所有参数.预期有2个参数,1个已被定义.

我需要做些什么来解决这个问题?

.net c# unit-testing rhino-mocks

20
推荐指数
2
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

rhino-mocks ×1

unit-testing ×1