Mock HttpContext.Current in Test Init Method

I’m trying to add unit testing to an ASP.NET MVC application I have built. In my unit tests I use the following code: [TestMethod] public void IndexAction_Should_Return_View() { var controller = new MembershipController(); controller.SetFakeControllerContext(“TestUser”); … } With the following helpers to mock the controller context: public static class FakeControllerContext { public static HttpContextBase FakeHttpContext(string username) … Read more

Setting HttpContext.Current.Session in a unit test

I have a web service I am trying to unit test. In the service it pulls several values from the HttpContext like so: m_password = (string)HttpContext.Current.Session[“CustomerId”]; m_userID = (string)HttpContext.Current.Session[“CustomerUrl”]; in the unit test I am creating the context using a simple worker request, like so: SimpleWorkerRequest request = new SimpleWorkerRequest(“”, “”, “”, null, new StringWriter()); … Read more