public ContentRetrieverTests() { httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(DummyChildAppContent), }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomeRegionBaseAddress"), }; defaultFormPostParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("formParam1", "test value") }; logger = A.Fake <ILogger <ContentRetriever> >(); appRegistryDataService = A.Fake <IAppRegistryDataService>(); httpResponseMessageHandler = A.Fake <IHttpResponseMessageHandler>(); 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>" }, }, }; defaultService = new ContentRetriever(httpClient, logger, appRegistryDataService, httpResponseMessageHandler, markupMessages); }
public ContentRetriever(HttpClient httpClient, ILogger <ContentRetriever> logger, IAppRegistryDataService appRegistryDataService, IHttpResponseMessageHandler responseHandler, MarkupMessages markupMessages) { this.httpClient = httpClient; this.logger = logger; this.appRegistryDataService = appRegistryDataService; this.responseHandler = responseHandler; this.markupMessages = markupMessages; }
public ContentRetriever(IUriSpecifcHttpClientFactory httpClientFactory, ILogger <ContentRetriever> logger, IAppRegistryDataService appRegistryDataService, IHttpResponseMessageHandler responseHandler, MarkupMessages markupMessages, IMemoryCache memoryCache, IOptions <PassOnHeaderSettings> headerSettings) { this.httpClientFactory = httpClientFactory; this.logger = logger; this.appRegistryDataService = appRegistryDataService; this.responseHandler = responseHandler; this.markupMessages = markupMessages; this.memoryCache = memoryCache; this.headerSettings = headerSettings?.Value ?? new PassOnHeaderSettings(); }
public void MarkupMessagesReturnsAppOfflineMessage() { // arrange var model = new MarkupMessages(); // act var result = model.AppOfflineHtml; // assert Assert.Equal(model.AppOfflineHtml, result); }
public void MarkupMessagesReturnsRegionOfflineMessage(PageRegion pageRegion, string expected) { // arrange var model = new MarkupMessages(); // act var result = model.GetRegionOfflineHtml(pageRegion); // assert Assert.Equal(expected, result); }
public ApplicationService( IAppRegistryDataService appRegistryDataService, IContentRetriever contentRetriever, IContentProcessorService contentProcessorService, ITaskHelper taskHelper, MarkupMessages markupMessages) { this.appRegistryDataService = appRegistryDataService; this.contentRetriever = contentRetriever; this.contentProcessorService = contentProcessorService; this.taskHelper = taskHelper; this.markupMessages = markupMessages; }
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 }; }