Back to list
Views:   3.5K
Replies:  0

Fake HttpContext not needed

Hi, thank you for this great product! Here comes my first question:
  • Product: .Net Design Pattern Framework 4.5 c# Edition
  • MVC unitttest
  • MoqHelpers

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.
       public void SearchTest()
           // Arrange
           var controller = CreateShopController();
           // 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

Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.3.0