Exemplo n.º 1
0
        private Task <string> GetApplicationBodyRegionMarkUpAsync(ApplicationModel application, string queryString, IHeaderDictionary headers)
        {
            //Get the body region
            var bodyRegion = application.AppRegistrationModel.Regions.FirstOrDefault(x => x.PageRegion == PageRegion.Body);

            if (bodyRegion == null || string.IsNullOrWhiteSpace(bodyRegion.RegionEndpoint))
            {
                return(Task.FromResult(string.Empty));
            }

            var url = FormatArticleUrl(bodyRegion.RegionEndpoint, application.Article, queryString);

            return(contentRetriever.GetContent(url, application.AppRegistrationModel.Path, bodyRegion, false, RequestBaseUrl, headers));
        }
Exemplo n.º 2
0
        public async Task GetMarkupAsyncForOnlineApplication()
        {
            // Arrange
            var pageModel = new PageViewModel();

            mapper.Map(defaultApplicationModel, pageModel);

            //Act
            await applicationService.GetMarkupAsync(defaultApplicationModel, "index", pageModel, string.Empty).ConfigureAwait(false);

            //Assert
            Assert.Equal(defaultRegions.Count, pageModel.PageRegionContentModels.Count);
            Assert.Equal(HeadRegionContent, pageModel.PageRegionContentModels.First(x => x.PageRegionType == PageRegion.Head).Content.Value);
            Assert.Equal(BodyRegionContent, pageModel.PageRegionContentModels.First(x => x.PageRegionType == PageRegion.Body).Content.Value);
            Assert.Equal(BodyFooterRegionContent, pageModel.PageRegionContentModels.First(x => x.PageRegionType == PageRegion.BodyFooter).Content.Value);

            A.CallTo(() => contentRetriever.GetContent($"{defaultHeadRegion.RegionEndpoint}/index", defaultHeadRegion, A <bool> .Ignored, RequestBaseUrl)).MustHaveHappenedOnceExactly();
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyRegion.RegionEndpoint}/index", defaultBodyRegion, A <bool> .Ignored, RequestBaseUrl)).MustHaveHappenedOnceExactly();
            A.CallTo(() => contentRetriever.GetContent($"{defaultBodyFooterRegion.RegionEndpoint}/index", defaultBodyFooterRegion, A <bool> .Ignored, RequestBaseUrl)).MustHaveHappenedOnceExactly();
        }
Exemplo n.º 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
            };
        }