public void PossiblyReleaseController_CorrectFactory_ReleasesController() { // Arrange RequestContext requestContext = GetRequestContext(); IHttpHandler originalHttpHandler = requestContext.HttpContext.Handler; Controller controller = new ControllerReadOnlySession(); Mock <IControllerFactory> mockControllerFactory = new Mock <IControllerFactory>(); mockControllerFactory.Expect(o => o.CreateController(requestContext, "home")).Returns(controller); mockControllerFactory.Expect(o => o.ReleaseController(controller)).Verifiable(); ControllerBuilder controllerBuilder = new ControllerBuilder(); controllerBuilder.SetControllerFactory(new MvcDynamicSessionControllerFactory(mockControllerFactory.Object)); MvcDynamicSessionModule module = new MvcDynamicSessionModule() { ControllerBuilder = controllerBuilder }; // Act module.SetSessionStateMode(requestContext.HttpContext, SimpleDynamicSessionStateConfigurator.ExpectMode(ControllerSessionState.ReadOnly)); MvcDynamicSessionModule.PossiblyReleaseController(requestContext.HttpContext); // Assert mockControllerFactory.Verify(); }
public void PossiblyReleaseController_CorrectFactory_ReleasesController() { // Arrange RequestContext requestContext = GetRequestContext(); IHttpHandler originalHttpHandler = requestContext.HttpContext.Handler; Controller controller = new ControllerReadOnlySession(); Mock<IControllerFactory> mockControllerFactory = new Mock<IControllerFactory>(); mockControllerFactory.Expect(o => o.CreateController(requestContext, "home")).Returns(controller); mockControllerFactory.Expect(o => o.ReleaseController(controller)).Verifiable(); ControllerBuilder controllerBuilder = new ControllerBuilder(); controllerBuilder.SetControllerFactory(new MvcDynamicSessionControllerFactory(mockControllerFactory.Object)); MvcDynamicSessionModule module = new MvcDynamicSessionModule() { ControllerBuilder = controllerBuilder }; // Act module.SetSessionStateMode(requestContext.HttpContext, SimpleDynamicSessionStateConfigurator.ExpectMode(ControllerSessionState.ReadOnly)); MvcDynamicSessionModule.PossiblyReleaseController(requestContext.HttpContext); // Assert mockControllerFactory.Verify(); }