犀牛制品 - 使用Arg.Matches [英] Rhino Mocks - Using Arg.Matches

查看:235
本文介绍了犀牛制品 - 使用Arg.Matches的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,我嘲笑这需要一个参数对象作为参数。我想返回基于在对象中的值的结果。平等是不重写,我不能比较的对象。

I have a function I am mocking which takes an argument object as a parameter. I want to return a result based on the values in the object. I cannot compare the objects as Equals is not overriden.

我有以下的code:

_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 }
                });

这应该返回指定的对象时所提供的参数有2 TourId。

This should return the object specified when the supplied parameter has a TourId of 2.

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

This looks like it should work, but when I run it, I get the following exception:

在使用精氨酸,所有参数都必须使用Arg.Is定义,   Arg.Text,Arg.List,Arg.Ref或Arg.Out。 2个参数   料,1已经定义

When using Arg, all arguments must be defined using Arg.Is, Arg.Text, Arg.List, Arg.Ref or Arg.Out. 2 arguments expected, 1 have been defined.

我需要做的任何想法来解决这个?

Any ideas what I need to do to resolve this?

推荐答案

您需要使用相同的语法为您的第二个空的说法,这些方针的东西(我没有测试过):

You need to use the same syntax for your second null argument, something along these lines (I haven't tested it):

_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 }
            });

这篇关于犀牛制品 - 使用Arg.Matches的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆