コード例 #1
0
        private void PopulatePageRegionContent(ApplicationModel application, PageViewModel pageModel, PageRegion regionType, Task <string> task)
        {
            if (task == null)
            {
                return;
            }

            string outputHtmlMarkup = string.Empty;

            if (taskHelper.TaskCompletedSuccessfully(task))
            {
                var taskResult = task.Result;
                var result     = contentProcessorService.Process(taskResult, RequestBaseUrl, application.RootUrl);
                outputHtmlMarkup = result;
            }
            else
            {
                var pageRegionModel = application.Regions.FirstOrDefault(x => x.PageRegion == regionType);
                if (pageRegionModel != null)
                {
                    outputHtmlMarkup = pageRegionModel.OfflineHTML;
                }
            }

            var pageRegionContentModel = pageModel.PageRegionContentModels.FirstOrDefault(x => x.PageRegionType == regionType);

            if (pageRegionContentModel != null)
            {
                pageRegionContentModel.Content = new HtmlString(outputHtmlMarkup);
            }
        }
コード例 #2
0
        private void PopulatePageRegionContent(ApplicationModel application, PageViewModel pageModel, Task <PostResponseModel> task)
        {
            var pageRegionContentModel = pageModel.PageRegionContentModels.FirstOrDefault(x => x.PageRegionType == PageRegion.Body);

            if (pageRegionContentModel == null)
            {
                return;
            }

            if (task == null)
            {
                return;
            }

            var outputHtmlMarkup = string.Empty;

            if (taskHelper.TaskCompletedSuccessfully(task))
            {
                var taskResult = task.Result;
                if (taskResult.IsFileDownload)
                {
                    pageModel.FileDownloadModel = taskResult.FileDownloadModel;
                }
                else
                {
                    outputHtmlMarkup = contentProcessorService.Process(taskResult.Html, RequestBaseUrl, application.RootUrl);
                    pageRegionContentModel.Content = new HtmlString(outputHtmlMarkup);
                }
            }
            else
            {
                var pageRegionModel = application.AppRegistrationModel.Regions.FirstOrDefault(x => x.PageRegion == PageRegion.Body);
                if (pageRegionModel != null)
                {
                    outputHtmlMarkup = !string.IsNullOrWhiteSpace(pageRegionModel.OfflineHtml) ? pageRegionModel.OfflineHtml : markupMessages.GetRegionOfflineHtml(pageRegionModel.PageRegion);
                    pageRegionContentModel.Content = new HtmlString(outputHtmlMarkup);
                }
            }
        }
コード例 #3
0
        public ApplicationServiceTests()
        {
            mapper = new ApplicationToPageModelMapper();

            pathDataService  = A.Fake <IPathDataService>();
            regionService    = A.Fake <IRegionService>();
            contentRetriever = A.Fake <IContentRetriever>();
            contentProcessor = A.Fake <IContentProcessorService>();

            defaultPathModel = new PathModel {
                Path = Path, TopNavigationOrder = 1, IsOnline = true
            };

            var headRegionEndPoint   = $"{RequestBaseUrl}/headRegionEndpoint";
            var bodyRegionEndPoint   = $"{RequestBaseUrl}/bodyRegionEndpoint";
            var footerRegionEndPoint = $"{RequestBaseUrl}/footerRegionEndpoint";

            defaultHeadRegion = new RegionModel {
                PageRegion = PageRegion.Head, RegionEndpoint = headRegionEndPoint, IsHealthy = true, OfflineHTML = OfflineHTML
            };
            defaultBodyRegion = new RegionModel {
                PageRegion = PageRegion.Body, RegionEndpoint = bodyRegionEndPoint, IsHealthy = true, OfflineHTML = OfflineHTML
            };
            defaultBodyFooterRegion = new RegionModel {
                PageRegion = PageRegion.BodyFooter, RegionEndpoint = footerRegionEndPoint, IsHealthy = true, OfflineHTML = OfflineHTML
            };
            defaultRegions = new List <RegionModel>
            {
                defaultHeadRegion,
                defaultBodyRegion,
                defaultBodyFooterRegion,
            };

            defaultPageViewModel = new PageViewModel
            {
                PageRegionContentModels = new List <PageRegionContentModel>
                {
                    new PageRegionContentModel
                    {
                        PageRegionType = PageRegion.Body,
                    },
                },
            };

            defaultApplicationModel = new ApplicationModel {
                Path = defaultPathModel, Regions = defaultRegions
            };
            offlineApplicationModel = new ApplicationModel {
                Path = new PathModel {
                    IsOnline = false, OfflineHtml = OfflineHTML
                }
            };

            A.CallTo(() => pathDataService.GetPath(Path)).Returns(defaultPathModel);
            A.CallTo(() => regionService.GetRegions(A <string> .Ignored)).Returns(defaultRegions);
            A.CallTo(() => contentRetriever.GetContent($"{defaultHeadRegion.RegionEndpoint}/index", defaultHeadRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(HeadRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyRegion.RegionEndpoint}/index", defaultBodyRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyFooterRegion.RegionEndpoint}", defaultBodyFooterRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyFooterRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyFooterRegion.RegionEndpoint}/index", defaultBodyFooterRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyFooterRegionContent);

            A.CallTo(() => contentProcessor.Process(HeadRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(HeadRegionContent);
            A.CallTo(() => contentProcessor.Process(BodyRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(BodyRegionContent);
            A.CallTo(() => contentProcessor.Process(BodyFooterRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(BodyFooterRegionContent);

            defaultFormPostParams = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("formParam1", "testvalue")
            };

            taskHelper = A.Fake <ITaskHelper>();
            A.CallTo(() => taskHelper.TaskCompletedSuccessfully(A <Task> .Ignored)).Returns(true);

            applicationService = new ApplicationService(pathDataService, regionService, contentRetriever, contentProcessor, taskHelper)
            {
                RequestBaseUrl = RequestBaseUrl
            };
        }
        public ApplicationServiceTests()
        {
            appRegistryDataService = A.Fake <IAppRegistryDataService>();
            mapper           = new ApplicationToPageModelMapper(appRegistryDataService);
            contentRetriever = A.Fake <IContentRetriever>();
            contentProcessor = A.Fake <IContentProcessorService>();

            markupMessages = new MarkupMessages
            {
                AppOfflineHtml    = "<h3>App offline</h3>",
                RegionOfflineHtml = new Dictionary <PageRegion, string>
                {
                    {
                        PageRegion.Head, "<h3>Head Region is offline</h3>"
                    },
                    {
                        PageRegion.Breadcrumb, "<h3>Breadcrumb Region is offline</h3>"
                    },
                    {
                        PageRegion.BodyTop, "<h3>BodyTop Region is offline</h3>"
                    },
                    {
                        PageRegion.Body, "<h3>Body Region is offline</h3>"
                    },
                    {
                        PageRegion.SidebarRight, "<h3>SidebarRight Region is offline</h3>"
                    },
                    {
                        PageRegion.SidebarLeft, "<h3>SidebarLeft Region is offline</h3>"
                    },
                    {
                        PageRegion.BodyFooter, "<h3>BodyFooter Region is offline</h3>"
                    },
                    {
                        PageRegion.HeroBanner, "<h3>HeroBanner Region is offline</h3>"
                    },
                },
            };

            var headRegionEndPoint   = $"{RequestBaseUrl}/headRegionEndpoint";
            var bodyRegionEndPoint   = $"{RequestBaseUrl}/bodyRegionEndpoint";
            var footerRegionEndPoint = $"{RequestBaseUrl}/footerRegionEndpoint";

            defaultHeadRegion = new RegionModel {
                PageRegion = PageRegion.Head, RegionEndpoint = headRegionEndPoint, IsHealthy = true, OfflineHtml = OfflineHtml
            };
            defaultBodyRegion = new RegionModel {
                PageRegion = PageRegion.Body, RegionEndpoint = bodyRegionEndPoint, IsHealthy = true, OfflineHtml = OfflineHtml
            };
            defaultBodyFooterRegion = new RegionModel {
                PageRegion = PageRegion.BodyFooter, RegionEndpoint = footerRegionEndPoint, IsHealthy = true, OfflineHtml = OfflineHtml
            };
            defaultRegions = new List <RegionModel>
            {
                defaultHeadRegion,
                defaultBodyRegion,
                defaultBodyFooterRegion,
            };
            defaultAppRegistrationModel = new AppRegistrationModel {
                Path = ChildAppPath, TopNavigationOrder = 1, IsOnline = true, Regions = defaultRegions
            };
            pagesAppRegistrationModel = new AppRegistrationModel {
                Path = AppRegistryPathNameForPagesApp, TopNavigationOrder = 1, IsOnline = true, Regions = defaultRegions
            };

            defaultPageViewModel = new PageViewModel
            {
                PageRegionContentModels = new List <PageRegionContentModel>
                {
                    new PageRegionContentModel
                    {
                        PageRegionType = PageRegion.Body,
                    },
                },
            };

            defaultApplicationModel = new ApplicationModel {
                AppRegistrationModel = defaultAppRegistrationModel, Article = "index"
            };
            pagesApplicationModel = new ApplicationModel {
                AppRegistrationModel = pagesAppRegistrationModel
            };
            offlineApplicationModel = new ApplicationModel {
                AppRegistrationModel = new AppRegistrationModel {
                    IsOnline = false, OfflineHtml = OfflineHtml
                }
            };
            offlineApplicationModelWithoutMarkup = new ApplicationModel {
                AppRegistrationModel = new AppRegistrationModel {
                    IsOnline = false, OfflineHtml = null
                }
            };

            A.CallTo(() => appRegistryDataService.GetAppRegistrationModel($"{ChildAppPath}/{ChildAppData}")).Returns(nullAppRegistrationModel);
            A.CallTo(() => appRegistryDataService.GetAppRegistrationModel(ChildAppPath)).Returns(defaultAppRegistrationModel);
            A.CallTo(() => appRegistryDataService.GetAppRegistrationModel(AppRegistryPathNameForPagesApp)).Returns(pagesAppRegistrationModel);
            A.CallTo(() => contentRetriever.GetContent($"{defaultHeadRegion.RegionEndpoint}/index", defaultApplicationModel.AppRegistrationModel.Path, defaultHeadRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(HeadRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyRegion.RegionEndpoint}/index", defaultApplicationModel.AppRegistrationModel.Path, defaultBodyRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyFooterRegion.RegionEndpoint}", defaultApplicationModel.AppRegistrationModel.Path, defaultBodyFooterRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyFooterRegionContent);
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyFooterRegion.RegionEndpoint}/index", defaultApplicationModel.AppRegistrationModel.Path, defaultBodyFooterRegion, A <bool> .Ignored, RequestBaseUrl)).Returns(BodyFooterRegionContent);

            A.CallTo(() => contentProcessor.Process(HeadRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(HeadRegionContent);
            A.CallTo(() => contentProcessor.Process(BodyRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(BodyRegionContent);
            A.CallTo(() => contentProcessor.Process(BodyFooterRegionContent, A <string> .Ignored, A <string> .Ignored)).Returns(BodyFooterRegionContent);

            defaultFormPostParams = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("formParam1", "testvalue")
            };

            taskHelper = A.Fake <ITaskHelper>();
            A.CallTo(() => taskHelper.TaskCompletedSuccessfully(A <Task> .Ignored)).Returns(true);

            applicationService = new ApplicationService(appRegistryDataService, contentRetriever, contentProcessor, taskHelper, markupMessages)
            {
                RequestBaseUrl = RequestBaseUrl
            };
        }