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 - is it possible to fake static methods AND instance methods for the same class?
asked by xdzgor (3.3k points)

2 Answers

0 votes
Sure.

For example:

class MyClass
{
   static public int StaticMethod() { return 1; }
   public int InstanceMethod() { return 1;}
}

[Test]
public void Test()
{
      Isolate.Fake.StaticMethods<MyClass>();
      Isolate.WhenCalled(() => MyClass.StaticMethod).WillReturn(2);
      var fakedInstance = Isolate.Fake.Instance<MyClass>();
      Isolate.WhenCalled(() => fakedInstance.InstanceMethod).WillReturn(3);

      Assert.That(MyClass.StaticMethod(), Is.EqualTo(2));
      Assert.That(fakedInstance.InstanceMethod(), Is.EqualTo(3));
}
answered by yoel (1.9k points)
0 votes
Yes thanks - that of course works fine. In the classes I was trying to test there were a lot of threads being started up in the background, and there was a WCF layer mixed up in it, which made it hard for me to see the wood for the trees.
answered by xdzgor (3.3k points)
...