How to use PostSharp with MOQ?

We are trying to use PostSharp, more specifically OnMethodInvocationAspect, to intercept class methods.

The code works fine, but when testing it with MOQ it seems to ruin my layouts.

If I remove the aspects, all tests will succeed. But, if I turn on the aspects again, the expectations regarding MOQ layouts will not be fulfilled.

Here is a snippet taken from one of our unit tests:

this.sgtrMock.Setup(r => r.RetrieveCurrentTaxes()).Returns(new[] {tax1, tax2}); this.service.LoadServiceTaxes(); this.sgtrMock.Verify(r => r.RetrieveCurrentTaxes(), Times.Once()); 

Any ideas on what could happen?

+4
source share
1 answer

There catch - Moq objects are not intercepted objects, they are proxies.

+1
source

All Articles