Views: 3.5K
Replies: 0
Archived
|
Fake HttpContext not neededHi, thank you for this great product! Here comes my first question:
In the mvc unit test project there is a sample shopcontrollertest, and the test method SearchTest is using a Fake HttpContext setup. I wonder what is the use for the fake Httpcontext? It doesnt really do anything since you can comment away the FakeHttpContext setup and the test will still pass. br/ John // test Product Search Action method. Returns sorted product list. // Note: this creates a Fake HttpContext which is necessary to access an [HttpPost] decorated action method. [TestMethod] public void SearchTest() { // Arrange var controller = CreateShopController(); controller.SetFakeControllerContext(); controller.Request.SetHttpMethodResult("POST"); // Act var result = controller.Search() as ViewResult; // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.IsInstanceOfType(result.ViewData.Model, typeof(SearchModel)); // check products returned var model = result.ViewData.Model as SearchModel; Assert.AreEqual(1, model.Products.List.Count()); } John Pettersson, Jan 10, 2016
|