I got below Error.
" An exception of type 'System.NullReferenceException' occurred in Effort Estimation.dll but was not handled in user code Additional information: Object reference not set to an instance of an object. "
In controller I have a method that name Login. In that method we use session. So how to write unit testing? While run the unit test code, It goes to main csharp code and enter into the method and stopped in session declarations. Any one if know the solution solve it soon as possible.
My unit test Code, What I have tried is, LoginModel
class have 2 variables I have assigned there.
[TestMethod]
public void Login1() //Bug
{
LoginController log = new LoginController();
LoginModel logModel = new LoginModel ();
logModel.UserName = "20079199";
logModel.Password = "123456";
var result = log.Login(logModel) as ViewResult;
Assert.AreEqual("HomePage", result);
}
[HttpPost]
public ActionResult Login(LoginModel lVM)
{
LoginViewModel model = UM.Authentication(lVM);
if (model.UserId > 0)
{
Session["LoginMessage"] = model.UserName;
Session["UserID"] = model.UserId;
IDataHelper ex = new DataHelper();
return RedirectToAction("HomePage", "Newcontroller");
}
else
{
Session["LoginMessage"] = "Invalid UserName and Password";
return RedirectToAction("Login", "Login");
}
}