I've read many articles and blogs about mocking in mvc... Many of them were helpful, but i still have some problems:
One such issue is that I need to use Session in My ActionResult, but in my Tests i get a NullReferenceException when Session is accessed.
public ActionResult Index() { if (Session["Something"] == null) { Session.Add("Something", <smth>); } else { Session["Something"] = <smth>; } return redirect to action("Index2"); }
My test look like this:
HomeController controller = new HomeController; var result = controller.Index() as ViewResult; Assert.AreEqual("Index2", result.ViewName);