【问题标题】:Using Microsoft Fakes to Shim a method with ref parameters使用 Microsoft Fakes 填充带有 ref 参数的方法
【发布时间】:2012-10-13 08:12:06
【问题描述】:

我的旧版(不可测试)dll 中有一个带有 ref 参数的静态方法。我正在尝试为调用此方法的类编写单元测试。

public static class Branding
{
    ...
    ...

    static public bool GetBranding(Int32 providerId,
        Int32 employerId,
        string brandingElement,
        ref string brandingValue)

    ...
    ...
}

我需要帮助为此调用编写 shim 语句

ShimBranding.GetBrandingInt32Int32StringStringRef = 
    ( providerId, employerId, element, { ====> WHAT GOES HERE <===== } )
    => 
    true;

谢谢!

【问题讨论】:

    标签: unit-testing microsoft-fakes


    【解决方案1】:
    using (ShimsContext.Create())
    {
        ShimBranding.GetBrandingInt32Int32StringStringRef =
            (int providerId, int employerId, string brandingElement, ref string brandingValue) =>
            {
                brandingValue = "Blah";
                return true;
            };
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多