我想使用RhinoMocks
在我的动作控制器中模拟以下内容Session["myId"] = someGuid.ToString();
我该怎么做?
谢谢
答案 0 :(得分:2)
从Codeplex http://mvccontrib.codeplex.com/或使用NUget下载MVC Contrib。添加对.net项目的引用,并按照以下示例进行操作:
[TestMethod]
public void MyController()
{
//Mocks your controller with the session
TestControllerBuilder builder = new TestControllerBuilder();
HomeController controller = new HomeController();
builder.InitializeController(controller);
ViewResult result = controller.MyController() as ViewResult;
Assert.IsNotNull(result);
}