回调方法中的模拟参数

| 因此,我有一个带有此签名的方法:
IList<Mail> FindFilteredPaged(
   QueryFilter filter, 
   int pageIndex, 
   int pageSize, 
   out int totalRecords);
我想设置期望值,以便检查
filter
参数是否为空。问题出在最后的
out
解释器中。我当前的期望设置是这样的:
Expect
   .Call(registryMailService.FindFilteredPaged(
      Arg<QueryFilter<IncomingMail>>.Is.Anything,
      Arg<Int32>.Is.Anything,
      Arg<Int32>.Is.Anything,
      out Arg<Int32>.Out(20).Dummy))                         
   .Callback<QueryFilter<IncomingMail>, Int32, Int32>((p1, p2, p3) => 
   {
       filterWasNotSpecified = p1 == null;
   });
但是,没有运气。安装程序崩溃,并显示saying4ѭ。关于如何做到这一点的任何建议?有没有办法只使用第一个参数并跳过其余的参数? 谢谢。     
已邀请:
        您可能会遇到以下情况: \“ lambda表达式无法直接从封闭方法中捕获ref或out参数。\” http://msdn.microsoft.com/en-us/library/bb397687.aspx 编辑:您可以创建/使用自定义委托...例如声明...
public delegate void SomeAction<T1, T2, T3>( out T1 a, ref T2 b, T3 c );
然后在您的测试中...
SomeAction<int, string, string> fakeDoSomething  = ( out int outParam, ref string refParam, string param ) =>
            {
                outParam = 123;
                refParam = \"123\";
            };

        using ( m_Mocks.Record() )
        {
            Expect.Call( () => m_MockService.DoSomething( out outInt, ref refString, someString ) ).Do( fakeDoSomething );
        }
    
        使用C#中可用的可选参数     

要回复问题请先登录注册