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
0 votes
Hi Guys,
I do have a component that executes WebServices using reflection. The method has three parameters, the Web Service name and the Soap Action and the method arguments,
then using reflection, it loads and execute the soap action using MethodInfo class and the Invoke method.

I would like to mock the Invoke routine to return a SOAP envelop, note that the imput parameters are dinamyc. It means that the parameter arguments are not static it depents on the WebMethod.

How can I mock the Invoke method from System.Reflection.MethodBase.Invoke?
asked by michael.hidalgo (600 points)

1 Answer

0 votes
Hi,
Isolator has some limitations with faking mscorlib.dll types :(
While Isolator can fake types like DateTime and Stream from mscorlib.dll it can not fake System.Reflection types.

The solution in this case is to create a wrapper around the method you want to fake and than fake it.

Example:
//our wrapper class
public class Wrapper
{
    public static object Invoke(MethodInfo methodInfo, object instance, object [] parameters)
    {
        return methodInfo.Invoke(instance, parameters);
    }
}


//Test Code
Isolate.Fake.StaticMethods<Wrapper>();
Isolate.WhenCalled(() => Wrapper.Invoke(null, null, null)).WillReturn(1);


Hope it helps.
answered by ohad (35.4k points)
...