Example #1
0
 public virtual void ExecuteModuleHeader(PortalRequestContext portalContext, ModuleRequestResult moduleResult)
 {
     IHeaderContributingResult headerResult = moduleResult.ActionResult as IHeaderContributingResult;
     if (headerResult != null) {
         RunInModuleResultContext(portalContext,
                                  moduleResult,
                                  () => headerResult.ExecuteHeader(moduleResult.ControllerContext));
     }
 }
        public void GetPortalContext_Returns_Stored_PortalRequestContext_If_Present()
        {
            // Arrange
            HttpContextBase context = Mockery.CreateMockHttpContext();
            PortalRequestContext expected = new PortalRequestContext(context);
            context.Items.Add(HttpContextBaseExtensions.GetKeyFor<PortalRequestContext>(), expected);

            // Act
            PortalRequestContext actual = context.GetPortalContext();

            // Assert
            Assert.AreSame(expected, actual);
        }
        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));
        }
Example #5
0
 public override string GetTitle(PortalRequestContext context)
 {
     return(Client.ClientResources.ExtensionName);
 }
Example #6
0
        protected internal void RunInModuleResultContext(PortalRequestContext portalContext, ModuleRequestResult moduleResult, Action action)
        {
            // Set the active module
            ModuleRequestResult oldRequest = portalContext.ActiveModuleRequest;
            portalContext.ActiveModuleRequest = moduleResult;

            // Run the action
            action();

            // Restore the previous active module
            portalContext.ActiveModuleRequest = oldRequest;
        }
Example #7
0
 public virtual void ExecuteModuleResult(PortalRequestContext portalContext, ModuleRequestResult moduleResult)
 {
     RunInModuleResultContext(portalContext,
                              moduleResult,
                              () => moduleResult.ActionResult.ExecuteResult(moduleResult.ControllerContext));
 }
        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_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_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);
        }