Ankit Agarwal

Ankit Agarwal

  • NA
  • 379
  • 253.4k

Getting null reference error during Unit Testing withsession

Jul 6 2018 7:25 AM
Hello,
 
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:-
 
//Arrange
GCopaDimensionsController gCopaDimensionsController = new GCopaDimensionsController();
//gCopaDimensionsController.ControllerContext = context.Object;
//Act
ViewResult result = gCopaDimensionsController.Index() as ViewResult;
//Assert
Assert.AreEqual("Manage Global Copa Dimension", gCopaDimensionsController.Session["Title"]);
//Assert.Fail();
 

Thanks in Advance.

Ankit Agarwal
Software Engineer 
 

Answers (2)