public void ExecuteModuleHeader_Does_Nothing_If_ModuleResult_Does_Not_Implement_IHeaderContributingResult()
        {
            // Arrange
            var mockResult = new Mock<ActionResult>();
            PortalRequestContext context = new PortalRequestContext(Mockery.CreateMockHttpContext());
            ModuleRequestResult result = new ModuleRequestResult() {
                ActionResult = mockResult.Object,
                ControllerContext = Mockery.CreateMockControllerContext()
            };
            ModuleExecutionEngine engine = new ModuleExecutionEngine();

            // Act
            engine.ExecuteModuleHeader(context, result);

            // Assert (nothing happened?)
        }
        public void ExecuteModuleHeader_Executes_ModuleResult_Header_If_It_Implements_IHeaderContributingResult()
        {
            // Arrange
            var mockResult = new Mock<ActionResult>();
            mockResult.As<IHeaderContributingResult>();
            PortalRequestContext context = new PortalRequestContext(Mockery.CreateMockHttpContext());
            ModuleRequestResult result = new ModuleRequestResult() {
                ActionResult = mockResult.Object,
                ControllerContext = Mockery.CreateMockControllerContext()
            };
            ModuleExecutionEngine engine = new ModuleExecutionEngine();

            // Act
            engine.ExecuteModuleHeader(context, result);

            // Assert
            mockResult.As<IHeaderContributingResult>()
                      .Verify(r => r.ExecuteHeader(result.ControllerContext));
        }
        public void RunInModuleContext_Runs_Provided_Action()
        {
            // Arrange
            HttpContextBase httpContext = Mockery.CreateMockHttpContext();
            ModuleRequestResult moduleResult = new ModuleRequestResult();
            PortalRequestContext portalContext = new PortalRequestContext(httpContext);
            ModuleExecutionEngine engine = new ModuleExecutionEngine();
            bool actionRun = false;

            // Act
            engine.RunInModuleResultContext(portalContext,
                                            moduleResult,
                                            () => {
                                                actionRun = true;
                                            });

            // Assert
            Assert.IsTrue(actionRun);
        }
        public void RunInModuleContext_Sets_ActiveModuleRequest_Before_Calling_Delegate()
        {
            // Arrange
            HttpContextBase httpContext = Mockery.CreateMockHttpContext();
            ModuleRequestResult moduleResult = new ModuleRequestResult();
            PortalRequestContext portalContext = new PortalRequestContext(httpContext);
            ModuleExecutionEngine engine = new ModuleExecutionEngine();

            // Act
            engine.RunInModuleResultContext(portalContext,
                                            moduleResult,
                                            () => {
                                                // Assert
                                                Assert.AreSame(moduleResult, portalContext.ActiveModuleRequest);
                                            });
        }
        public void RunInModuleContext_Restores_Original_ActiveModuleRequest_After_Returning_From_Delegate()
        {
            // Arrange
            HttpContextBase httpContext = Mockery.CreateMockHttpContext();
            ModuleRequestResult moduleResult = new ModuleRequestResult();
            ModuleRequestResult originalModuleResult = new ModuleRequestResult();
            PortalRequestContext portalContext = new PortalRequestContext(httpContext);
            ModuleExecutionEngine engine = new ModuleExecutionEngine();
            portalContext.ActiveModuleRequest = originalModuleResult;

            // Act
            engine.RunInModuleResultContext(portalContext,
                                            moduleResult,
                                            () => { });

            // Assert
            Assert.AreSame(originalModuleResult, portalContext.ActiveModuleRequest);
        }