How do I disable PostSharp when running unit tests?
3 answers
You can have a static flag in your aspect to enable / disable it and check the status of the flag in your aspect implementation.
Then, in your unit test setup, disable the static flag.
eg.
public static bool On = true;
...
public override void OnInvoke(MethodInterceptionArgs args)
{
if (!CacheAttribute.On)
{
args.ReturnValue = args.Invoke(args.Arguments);
}
+3
source to share
If you are using Typemock in your unit tests, you can use something like
MyAspect myAspectMock = Isolate.Fake.Instance<MyAspect>(Members.MustSpecifyReturnValues);
Isolate.Swap.AllInstances<MyAspect>().With(myAspectMock);
This allows you to control which tests are used in aspects and which are not, allowing you to test the method itself and with advice.
Presumably there will be a similar mechanism with other mocking frames
0
source to share