chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,

How can i simulate with Typemock a call for static method ?
let's say i have the following under-test class :
public static class Foo
{
    private static int Multyply(int x1, int x2)
    {
            return x1*x2;
    }
}


Thanks,
James
asked by JamesKing (48.2k points)

1 Answer

0 votes
Hi,

To invoke private methods we use Invoke.Method call.
You can use it on private static like in your case like this :
[TestMethod, Isolated]
public void InvokePrivateStaticMethod()
{
    var result = Isolate.Invoke.Method<Foo>("Multiply", 2, 5);

    Assert.AreEqual(10, result);
}

or for non static:
[TestMethod]
public void InvokePrivateMethod()
{
    var underTest = new ClassUnderTest();

    var result = Isolate.Invoke.Method(underTest, "Sum", 2, 5);

    Assert.AreEqual(7, result);
}
answered by Shai Barak (1.5k points)
...