How do you verify a non-public generic method is called?

0 votes
Typemock Version:8.5

VS2015, c#

I am trying to verify that a non-public generic method is being called, but when I make the call to the method, how do I indicate the generic type?  This is an instance method, not static.
asked Jun 9 by jim.little (250 points)
Can you provide a code sample?
[TestMethod]
public void Test_CallPrivateGeneric()
{
	var fakeCalculatorGeneric = Isolate.Fake.Instance<CalculatorGeneric<String>>();
	Isolate.Invoke.Method(fakeCalculatorGeneric, "DoSomethingPrivate");

	Isolate.Verify.NonPublic.WasCalled(fakeCalculatorGeneric, "DoSomethingPrivate");
}

public class CalculatorGeneric<T>
{
	public string DoSomething<T>(bool callMethod)
	{
		if (callMethod)
		{
			return DoSomethingPrivate<T>();
		}
		else
		{
			return "DidNotCalltheMethod";
		}
	}

	private string DoSomethingPrivate<T>()
	{
		return "foo";
	}
}

But when I ran this time, I saw this error:

TypeMock.TypeMockException : 
*** Could not invoke CalculatorGeneric`1.DoSomethingPrivate():
Currently Isolate.Invoke.Method() does not support generic methods
 
When will typemock support invoking generics and verify that generics are called?

 

 

Hi Jim,

You always can invoke method by reflection:

var method = typeof(CalculatorGeneric<string>).GetMethod("DoSomethingPrivate",         System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var genericMethod = method.MakeGenericMethod(typeof(string));
var result = genericMethod.Invoke(fake, new object[] {});
 
Cheers,
Eva

1 Answer

0 votes

Hi Jim,

Typemock is currently does not support invoking generic methods.

I will ask my manager to add it to our roadmap.

 

Cheers,

Daniel

answered Jun 14 by Daniel (1,340 points)
edited Jun 14 by Daniel
...