开发者

How to use PostSharp with MOQ?

开发者 https://www.devze.com 2022-12-08 07:01 出处:网络
We are trying to use PostSharp, more specifically the OnMethodInvocationAspect, to intercept the methods of a class.

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

The code runs fine, but when testing it with MOQ, it seems to be messing up with my mocks.

If I remove the aspects, all tests succeed. But, if I turn the aspects back on, the expectations on the MOQ mocks are not met.

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

this.sgtrMock.Setup(r => r.RetrieveCurrentTaxes()).Retur开发者_JS百科ns(new[] {tax1, tax2});
this.service.LoadServiceTaxes();
this.sgtrMock.Verify(r => r.RetrieveCurrentTaxes(), Times.Once());

Any ideas about what can be happening?


There's a catch - Moq objects are not the intercepted objects, they're proxies.

0

精彩评论

暂无评论...
验证码 换一张
取 消