Search code examples
unit-testingmicrosoft-fakes

Using Microsoft Fakes to Shim a method with ref parameters


I have a static method with ref parameters in my legacy (untestable) dll. I am trying to write unit tests for a class that calls into this method.

public static class Branding
{
    ...
    ...

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

    ...
    ...
}

I need help writing a shim statement for this call

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

Thanks!


Solution

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