Search code examples
rhino-mocks

Session Mocking-Rhino Mocks


I want to mock the following in my action controller using RhinoMocks

Session["myId"] = someGuid.ToString();

How Do I do that?

Thank you


Solution

  • Download MVC Contrib from Codeplex http://mvccontrib.codeplex.com/ or using NUget. Add the references to your .net project and follow the example below:

    [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);
    }