I'm trying to test an implementation of IInterceptionBehavior:
public class LoggingInterceptorBehavior : IInterceptionBehavior
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var methodBase = input.MethodBase;
/* ... */
return getNext()(input, getNext);
}
public IEnumerable<Type> GetRequiredInterfaces() { /* ... */ }
public bool WillExecute { get { return true; } }
}
How can I create a fake MethodBase?
The trick seems to be to, rather convolutely, get the MethodHandle using reflection and then pass this into a static method off the MethodBase class:
var methodHandle = dummyClass.GetType().GetMethod("dummyMethod").MethodHandle;
var methodBase = MethodBase.GetMethodFromHandle(methodHandle);
This seems to be wrong to me. What you seem to need here, is a rather integration test, where you test the whole thing by using it and then checking if it has logged something in the log (or whatever the purpose of the interceptor is). You could create a container, register a dummy test class, execute a method on it, have the method intercepted by the interceptor, etc. you get the gesture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With