unit testing - asp.net mvc How to test controllers correctly -


I'm having difficulty testing the controller. For the original test, my controller saw something like this:

  Some Manuals CreateSomethingController () {var somethingData = FakeSomethingData.CreateFakeData (); Var fake repository = FakeRepository.Create (); Var Controller = New Constructor (Fake Repository); Return controller; }  

This works fine for the majority of the test until I get a request. ISAJxRuest () part of the code. Then I had a jerk to the HTTCP Contex and the HTTextbase. My code looks back then:

  public class FakeHttpContext: HttpContextBase {bool _isAjaxRequest; Public FakeHttpContext (bool isAjaxRequest = false) {_isAjaxRequest = isAjaxRequest; } Public override HttpRequestBase request {find {string ajaxRequestHeader = ""; If (_isAjaxRequest) ajaxRequestHeader = "XMLHttpRequest"; Var Requests = New Imitation & lt; HttpRequestBase & gt; (); Request .setupgate (x = & gt; x.Headers). Returns (New WebHeaderCollection {{"with X-Requested", ajaxRequestHeader}}); Request.SetupGet (x => x ["X-Requested-With"]). Returns (AJAXRest Header); Return request. Object; }} Private IP user; Public override IPrincipal user {get {if (_user == blank) {_user = new FakePrincipal (); } Return _User; } Set {_user = value; }}} Make some controllers some controllers () {var somethingData = FakeSomethingData.CreateFakeData (); Var fake repository = FakeRepository.Create (); Var Controller = New Constructor (Fake Repository); Controller Contents Controller Consort = New Controller Consort (New FakeHttpContext (isAjaxRequest), New Routadata (), Controller); Controller ControllerContacts = Controlling Consortium; Return controller; }  

Now it has reached the stage in my controller where i am url.route and url is zero. So it seems that I have to start by joking about the routes for my controller and start joking.

Do I think there is no easier way to spend more time on fake / fake items and then test my copying the actual writing test code controller? I have seen TestControllerBuilder from MVCContrib, which helps with some problems, but does not seem to do all this, is there anything else available which will work and focus on writing a test rather than writing?

Thanks

You can use some such libraries that you Remove from some object boxes. For example, ... etc. I personally use - it's great and free I like the most, MQX's linux expression.


Comments