Ankit Agarwal

Ankit Agarwal

  • 1.8k
  • 379
  • 234.5k

Getting null reference error during Unit Testing withsession

Jul 6 2018 7:25 AM
When i am running my Unit Test project,so its getting error from mvc application"
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Web.HttpContext.Current.get returned null.
I have tried in MVC Application.
Please help me and tell me the whole process of UnitTesting in MVC. With maintenance of System.Web.HttpContext.Currect.Session.
I have tried following code:-
GCopaDimensionsController gCopaDimensionsController = new GCopaDimensionsController();
//gCopaDimensionsController.ControllerContext = context.Object;
ViewResult result = gCopaDimensionsController.Index() as ViewResult;
Assert.AreEqual("Manage Global Copa Dimension", gCopaDimensionsController.Session["Title"]);

Thanks in Advance.

Ankit Agarwal
Software Engineer 

Answers (2)