Moq DbSet NotImplementedException

狂风中的少年 提交于 2019-12-01 18:48:21

Chances are that you have been using version 4.7.58 of Moq. That particular version was affected by a regression that would have triggered such a NotImplementedException. That regression has been fixed in version 4.7.63, so I suggest you update your Moq package reference to version 4.7.63 or newer to resolve this issue.

The fact that your code would have worked in Moq versions before 4.7.58 was due to a "feature" which unfortunately caused a lot more problems than it solved. For this reason, that feature was reverted.

Moq has been brought back to its original behaviour, where, in this particular scenario, you need to set up the various interface members via mock.As<TInterface> before the call to mock.Object. (Usually, in Moq, it's perfectly fine to perform more set ups even after retrieving the mock object; this scenario is a notable exception. Hopefully this can be fixed in a future version of Moq.)

Rolling back Castle.Core to 4.0.0 and Moq to the latest version supporting 4.0.0 solved the issue. I'm still wondering if there is something I've missed that would fix this problem in the new version.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!