Rah*_*hul 4 c# unit-testing moles
我想绕过一个内部方法调用,因此嘲笑它.模拟的方法委托看起来像:
public Microsoft.Moles.Framework.MolesDelegates.OutOutFunc<string,string,string,
byte[]> GetlineStringStringOutStringOut { set; }
Run Code Online (Sandbox Code Playgroud)
现在,在我的测试中,当我尝试访问这个模拟的方法时:
GetlineStringStringOutStringOut = (a,b,c) => {return bytearray};
Run Code Online (Sandbox Code Playgroud)
发生错误,说参数2和3必须用out关键字声明,但是当我用out关键字声明它们时,它根本不会编译.我读了其他SO问题和答案,似乎无法完成.
是否可以为此提供用户定义的委托?如果是,请举个例子.
编辑:
我试图将自己的同一签名代表声明为模拟委托
static delegate byte[] MyFunc<String, String, String>
(string a, out string b, out string c);
Run Code Online (Sandbox Code Playgroud)
但我不确定在调用模拟的委托方法时如何调用它?
您需要在从lambda返回之前为其分配值b和c变量,并明确指定参数类型,如下所示:
GetlineStringStringOutStringOut = (string a, out string b, out string c) =>
{
b = c = string.Empty;
return new byte[] { };
};
Run Code Online (Sandbox Code Playgroud)