質問

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!

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top