views:

59

answers:

1

i'm using Unity to do AOP, could someone give me some idea how to unit test them?

A: 

Does your "aspect" implementation is a class that implements ICallHandler (or very similar IInterceptionBehavior in Unity 2.0) and is already added to intercepted object's execution pipeline?

If so, you can test it separately quite ordinarily. What you test is Invoke method - call it with mock created for IMethodInvocation, set up to have your object's state before invoking the aspect and with GetNextHandlerDelegate to mock object set up to represent your intercepted object call.

You can then assert:

  • on your delegate target if proper calls are made - i.e. test whether the aspect breks/doesn't break the execution properly, whether the call arguments were properly altered etc.
  • on Invoke's result (IMethodReturn object) - i.e. test whether the return result was properly altered, whether the exception was thrown etc.
A.