Configure settings using Microsoft Fakes

So, I'm trying to use Microsoft Fakes, and I like it, but I have a static method with an out parameter, and I can't figure out how to use it:

Static fake method:

public static class Foo
{
    public static bool TryBar(string str, out string stuff)
    {
        stuff = str;

        return true;
    }
}

Test:

[TestFixture]
public class MyTestTests
{
    [Test]
    public void MyTest()
    {
        using (ShimsContext.Create())
        {
            string output;
            ShimFoo.TryBarStringStringOut = (input, out output) =>
            {
                output = "Yada yada yada";

                return false;
            };
        }
    }
}

Now I get an error in my test, claiming that my output parameter is incorrect ("Cannot resolve character output"). I tried to get documentation on how to handle parameters, but I can not find anything. Has anyone had experience?

+4
source share
2 answers

As soon as you ask you to figure it out. For everyone who has this problem, I solved it as follows:

[TestFixture]
public class MyTestTests
{
    [Test]
    public void MyTest()
    {
        using (ShimsContext.Create())
        {
            ShimFoo.TryBarStringStringOut = (string input, out string output) =>
            {
                output = "Yada yada yada";

                return false;
            };
        }
    }
}
+6
source

, , -, shimmed .

, .

ShimFoo.TryBarStringStringOut = (input, out output) => { ... };

...

ShimFoo.TryBarStringStringOut = (input, out string output) => { ... };

( ) ...

ShimFoo.TryBarStringStringOut = (string input, out string output) => { ... };

+4

All Articles