How do I Unit Test Actions without Mocking that use UpdateModel?

后端 未结 3 1724
误落风尘
误落风尘 2020-12-16 04:08

I have been working my way through Scott Guthrie\'s excellent post on ASP.NET MVC Beta 1. In it he shows the improvements made to the UpdateModel method and how they improv

3条回答
  •  情话喂你
    2020-12-16 04:47

    I was having this same issue. After reading tvanfosson's solution, I tried a simple solution not involving a mock framework.

    Add a default ControllerContext to the controller as follows:

    CountryController controller = new CountryController();
    controller.ControllerContext = new ControllerContext();
    

    This removed the error just fine for me while unit testing. I hope this may help someone else out.

提交回复
热议问题