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

I am currently evaluating whether to get TypeMock for our product or not.
One functionality that is important is the ability to stub and verifycalls on generic methods.

private void MyFunction<T>() where T:SomeBaseClass{...}

When testing I found that this is possible:

myObj.ExpectAndReturn("MyFunction", "monkey");

This will ignore the generic parameter on MyFunction and treat all instances the same way. However, I prefer to use the Arrange Act Assert syntax, rather than setting up expectations and verifying them.

I tried something like this, but it doesn't seem to work. Anyone know what I am doing wrong, or is it not possible?

Isolate.NonPublic.WhenCalled(myObject, "MyFunction").WillReturn("monkey");
Isolate.Verify.NonPublic.WasCalled(myObject, "MyFunction");

Thank you
asked by Kjell (600 points)

1 Answer

0 votes

The AAA API does not have an explicit way to fake or verify generic private members. There's a workaround to use the natural mocks API as you've discovered.

We'll add this feature to our backlog. Meanwhile, let us know if you succeed in coding the test.

Typemock Support
answered by Elisha (12k points)