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
+1 vote


I want to fake a generic method like below:

public void foo<T>(Object params) where T : SomeType {}

I want to be able to check the actual type for T in my faked method. Is this possible?

asked by Ash (1.6k points)

Hi Ash,

I didn't quite understand what is it that you want to test, but if you want to verify that the method was called you can try:

Isolate.Verify.WasCalledWithAnyArguments(() =><SomeType>());

If that's not what you meant, please send a simple code sample.

1 Answer

+1 vote

You can try the following and assert against it:

var c = new SomeClassA();
bool wasCalledWithType = false;
Isolate.WhenCalled(() =><SomeClassB>(null)).DoInstead(context =>
      if (context.Method.GetGenericArguments() is SomeClassB)
           wasCalledWithType = true;




answered by Raphy (4k points)