Session Mocking-Rhino Mocks

时间:2011-11-02 15:25:16

标签: rhino-mocks

我想使用RhinoMocks

在我的动作控制器中模拟以下内容
Session["myId"] = someGuid.ToString();

我该怎么做?

谢谢

1 个答案:

答案 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);
}