VerificationException when instantiating MVC controller during unit testing

对着背影说爱祢 提交于 2019-12-12 02:36:39

问题


I am doing some unit testing with Microsoft Fakes Framework, and everything works fine until I add System.Web.Mvc fake assembly. From that moment any time I try to initialize a controller in a unit test, a VerificationException is thrown. When I remove the Fake assembly reference everything works fine. However, I need this fake in order to shim an Action method of a UrlHelper object.

I've seen some link's here on SO, but they are mostly about FluentValidation which is of no help to me. Also, an excellent article by Rich Czyzewski, Noninvasive Unit Testing in ASP.NET MVC4 – A Microsoft Fakes Deep Dive, did not help as I have absolutely no idea how he managed to instantiate UrlHelper. I followed the same example that he shows, but UrlHelper constructor throws VerificationException as well.

In addition to Rich's stubs I also added HttpResponseBase, HttpSessionBase, etc. to create a similar scenario that can be found on Scott Hanselman's blog, ASP.NET MVC Session at Mix08, TDD and MvcMockHelpers, but still no luck.

Has anyone managed to get around this problem and how?

Thanks in advance to everyone!


回答1:


This is a limitation in the version of Fakes that shipped with Visual Studio 2012 RTM release. We have fixed it in the upcoming Quarterly Update 2, the CTP will be available for download in a few weeks.



来源:https://stackoverflow.com/questions/13309278/verificationexception-when-instantiating-mvc-controller-during-unit-testing

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