コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var vm = new ShowHelpLinksViewModel {
                IsOnline = false
            };

            try
            {
                var helpPath = await pathDataService.GetPath("help").ConfigureAwait(false);

                if (helpPath != null)
                {
                    vm.IsOnline    = helpPath.IsOnline;
                    vm.OfflineHtml = new HtmlString(helpPath.OfflineHtml);
                }
            }
            catch (BrokenCircuitException ex)
            {
                var errorString = $"{nameof(ShowHelpLinksViewComponent)}: BrokenCircuit: {ex.Message}";

                logger.LogError(ex, errorString);

                throw;
            }

            return(View(vm));
        }
コード例 #2
0
        public async Task <ApplicationModel> GetApplicationAsync(string path)
        {
            var applicationModel = new ApplicationModel();

            var pathModel = await pathDataService.GetPath(path).ConfigureAwait(false);

            if (pathModel == null)
            {
                return(applicationModel);
            }

            applicationModel.Path    = pathModel;
            applicationModel.Regions = await regionService.GetRegions(pathModel.Path).ConfigureAwait(false);

            var bodyRegion = applicationModel.Regions?.FirstOrDefault(x => x.PageRegion == PageRegion.Body);

            if (bodyRegion != null && !string.IsNullOrWhiteSpace(bodyRegion.RegionEndpoint))
            {
                var uri = new Uri(bodyRegion.RegionEndpoint);
                var url = $"{uri.Scheme}://{uri.Authority}";

                applicationModel.RootUrl = url;
            }

            return(applicationModel);
        }
コード例 #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
            };
        }