使用Microsoft Fakes来使用ref参数来填充方法

时间:2012-08-24 18:42:08

标签: unit-testing microsoft-fakes

我的遗留(untestable)dll中有一个带参数参数的静态方法。我正在尝试为调用此方法的类编写单元测试。

public static class Branding
{
    ...
    ...

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

    ...
    ...
}

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

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

谢谢!

1 个答案:

答案 0 :(得分:16)

using (ShimsContext.Create())
{
    ShimBranding.GetBrandingInt32Int32StringStringRef =
        (int providerId, int employerId, string brandingElement, ref string brandingValue) =>
        {
            brandingValue = "Blah";
            return true;
        };
}