c# - 如何在 Microsoft Moles 中提供不带参数的用户定义委托(delegate)

标签 c# unit-testing moles

我想绕过内部方法调用,因此模拟了它。模拟方法委托(delegate)如下所示:

public Microsoft.Moles.Framework.MolesDelegates.OutOutFunc<string,string,string,
byte[]> GetlineStringStringOutStringOut { set; }

现在,在我的测试中,当我尝试访问这个模拟方法时:

GetlineStringStringOutStringOut = (a,b,c) => {return bytearray};

发生错误,指出参数 2 和 3 必须使用 out 关键字声明,但是当我使用 out 关键字声明它们时,它根本无法编译。我阅读了其他 SO 问题和答案,但似乎无法完成。

是否可以为此提供用户定义的委托(delegate)?如果是,请举例说明。

编辑:

我试图声明我自己的委托(delegate)与模拟委托(delegate)具有相同的签名

static delegate byte[] MyFunc<String, String, String>
(string a, out string b, out string c);

但我不确定在调用模拟委托(delegate)方法时如何调用它?

最佳答案

在从 lambda 返回之前,您需要为 bc 变量赋值,并明确指定参数类型,如下所示:

GetlineStringStringOutStringOut = (string a, out string b, out string c) => 
{ 
    b = c = string.Empty;

    return new byte[] { };
};

关于c# - 如何在 Microsoft Moles 中提供不带参数的用户定义委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8472863/

相关文章:

c# - 动态对象的 Lambda 表达式

c# - 从 Xamarin Droid 应用程序通过 https 调用 Web 服务时出现 WebException SecureChannelFailure

c# - OO 中的单元测试和访问修饰符

c# - 如何有效测试 SiteCore LinkField

.net - Moles 与其他隔离框架(例如 Moq、RhinoMocks 等)有何不同

unit-testing - Windows服务的Moles VS2010单元测试失败

c# - 从 xml REST POST webResponse 解析 C# 中的 XML

c# - .NET 应用程序将不同的操作系统版本返回到 Windows 10 上的 PowerShell

javascript - 使导入的函数使用新变量

django - 如何编写填充 raw_post_data 和 request.FILES ['myfile' 的测试]