-1

Anybody can suggest some good guideline or pattern for design asp.net mvc unit test.

I am new to mvc unit test framework design.

I have checked Microsoft fake, Moq, Fakeiteasy. But more preferable is Microsoft fake. Can you please suggest any good book or article from where I can get an idea how to handle cookies, session, controller, security and action filter

Thanks

Furqan Misarwala
  • 1,183
  • 2
  • 18
  • 42
  • There's no difference between unit testing an MVC application and unit testing anything else. You write tests to validate the functionality of each individual, well, unit of code. Introducing mocks to that code for any dependencies that aren't being validated in that particular test. – David Mar 05 '15 at 19:43
  • As @David says, you test MVC controllers like any other code, simply create a new instance of your controller and call the action on it, passing the input parameters ```var controller = new HomeController();```. The returned result can be asserted against using your chosen framework. To mock the HttpContext/Session/User look [here](http://stackoverflow.com/questions/1452418/how-do-i-mock-the-httpcontext-in-asp-net-mvc-using-moq) for ideas – Underscore Apr 02 '15 at 13:28

1 Answers1

0

You could try Xania.AspNet.Mvc which aims to simplify Unit Testing of Mvc Applications, partly by mocking all that is necessary to simulate a Hosting Evironment so that you have less to worry about and secondly by integrating with the ASP.NET MVC so that FilterAttributes, ModelBinders, Validation and other features of the framework would all apply when you execute/invoke your controller action.

for more information refer to this article http://www.codeproject.com/Tips/850277/ASP-NET-MVC-End-to-End-Integration-Testing