【发布时间】:2011-12-09 09:52:25
【问题描述】:
我已经阅读了很多关于在 mvc 中进行模拟的文章和博客......其中很多很有帮助,但我仍然有一些问题:
-
一个这样的问题是我需要在我的 ActionResult 中使用 Session,但在我的测试中,当访问 Session 时我得到一个 NullReferenceException。
public ActionResult Index() { if (Session["Something"] == null) { Session.Add("Something", <smth>); } else { Session["Something"] = <smth>; } return redirect to action("Index2"); } -
我的测试如下所示:
HomeController controller = new HomeController; var result = controller.Index() as ViewResult; Assert.AreEqual("Index2", result.ViewName);
【问题讨论】:
标签: c# asp.net-mvc unit-testing mocking httpcontext