Ejemplo n.º 1
0
        public void Indexer_Returns_Existing_Zone_If_Zone_Does_Exist()
        {
            // Arrange
            PageViewModel model = new PageViewModel();
            ZoneViewModel expected = new ZoneViewModel() {ZoneName = "foo"};
            model.Zones.Add(expected);

            // Act
            ZoneViewModel actual = model["foo"];

            // Assert
            Assert.AreSame(expected, actual);
        }
Ejemplo n.º 2
0
        public ActionResult ViewPage(int? moduleId, string moduleRoute)
        {
            // Get the current page
            Page page = ActivePage;

            // Start setting up the view model
            PageViewModel pageModel = new PageViewModel {
                Page = page
            };

            IList<Module> modules = page.Modules.ToList();

            // Execute the control panel module if specified and the user has permission
            if (!String.IsNullOrEmpty(ControlPanelId)) {
                Guid controlPanelGuid = Guid.Empty;
                try {
                    controlPanelGuid = new Guid(ControlPanelId);
                } catch(FormatException) {}
                if (controlPanelGuid != Guid.Empty) {
                    Module controlPanelModule = new Module() { ModuleApplicationId = controlPanelGuid };
                    ModuleRequestResult controlPanelResult = ModuleExecutor.ExecuteModule(HttpContext,
                                                                                          controlPanelModule,
                                                                                          String.Empty);

                    // If the result is a "Page Override" result (meaning it should be executed as the sole ActionResult for this page)
                    // Then execute it immediately
                    if (controlPanelResult != null && controlPanelResult.ActionResult is PageOverrideResult) {
                        return new RenderModuleResult { ModuleRequestResult = controlPanelResult };
                    }
                    pageModel.ControlPanelResult = controlPanelResult;
                }
            }

            // If there is a selected module (moduleId != null), run it first
            ModuleRequestResult selectedResult = null;
            if (moduleId.HasValue) {
                Module selectedModule = modules.SingleOrDefault(m => m.Id == moduleId.Value);
                if (selectedModule != null) {
                    selectedResult = ModuleExecutor.ExecuteModule(HttpContext, selectedModule, moduleRoute);

                    // See Control Panel above
                    if (selectedResult != null && selectedResult.ActionResult is PageOverrideResult) {
                        return new RenderModuleResult {ModuleRequestResult = selectedResult};
                    }
                }
            }

            // Execute all the modules on the page
            foreach (Module module in page.Modules) {
                ModuleRequestResult result;

                // If the current module is the selected module, then we already have the result, so we
                // don't need to execute it.
                if (moduleId.HasValue && moduleId.Value == module.Id) {
                    result = selectedResult;
                } else {
                    result = ModuleExecutor.ExecuteModule(HttpContext, module, String.Empty);
                }

                if (result != null) {
                    // Store the result, only the selected module can override the page
                    pageModel[module.ZoneName].ModuleResults.Add(result);
                }
            }

            return View(pageModel);
        }
Ejemplo n.º 3
0
 private static PageViewModel SetupAllModulesTestModel()
 {
     PageViewModel model = new PageViewModel();
     ZoneViewModel zone1 = new ZoneViewModel();
     zone1.ModuleResults.Add(new ModuleRequestResult());
     zone1.ModuleResults.Add(new ModuleRequestResult());
     zone1.ModuleResults.Add(new ModuleRequestResult());
     ZoneViewModel zone2 = new ZoneViewModel();
     zone2.ModuleResults.Add(new ModuleRequestResult());
     zone2.ModuleResults.Add(new ModuleRequestResult());
     model.Zones.Add(zone1);
     model.Zones.Add(zone2);
     return model;
 }