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
Isolate.NonPublic.WhenCalled Should't Call Public Method with the same name:

Here's the production code
public class MyObj
{
   public void Generate()
  {
     try
    {
        Generate("hi");
     }
     catch
     {
     }
  }
  private void Generate(string name)
  {
  }
}


And here's the test code
[Test]
public void TestMyObj()
{
  var myObj = new MyObj();
   Isolate.NonPublic.WhenCalled(myObj , "Generate")
                .WillThrow(new Exception("Dummy error"));
  Assert.DoesNotThrow(()=>myObj.Generate());
 } 


This test should pass because the exception is thrown at private method level, and it is handled by the public Generate method. However, Typemock seems to confuse this and throws an exception when the public Generate method is called, resulting in the test fail.
________
Drug Testing
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon,

Good catch, the reason for it is that Isolate.NonPublic works also on public methods.
This is in order to support refactoring - In cases where you change private method to public your test will still be valid.
This plus the fact that non public API does not supports overloading made the bug you see here.

I think that we can support this case by giving priority to private methods over public methods in case of an overload.

Thanks for reporting the bug!
answered by ohad (35.5k points)
...