开发者

How to use PostSharp with MOQ?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜