Beispiel #1
0
        public async Task GetContentWhenContentRetrievedFromChildAppWithHeadersThatShouldBePassedOnThenRequestMadeWithHeaders()
        {
            var model = new RegionModel
            {
                IsHealthy      = true,
                RegionEndpoint = "SomeRegionEndpoint",
                PageRegion     = PageRegion.Body,
            };

            var headerSettings = Options.Create(new PassOnHeaderSettings
            {
                SupportedHeaders = new List <string>
                {
                    "referer",
                },
            });

            var service = new ContentRetriever(httpClientFactory, logger, appRegistryDataService, httpResponseMessageHandler, markupMessages, memoryCache, headerSettings);
            var result  = await service.GetContent("someUrl", "path", model, true, "baseUrl", new HeaderDictionary
            {
                new KeyValuePair <string, StringValues>("Referer", new StringValues("job-profiles")),
            });

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .That.Matches(x =>
                                                                                           x.Headers.Any(x => x.Key == "Referer" && x.Value.Contains("job-profiles"))))).MustHaveHappened();
        }
Beispiel #2
0
        public async Task WhenRequestNullThenDoNotCallVisitService()
        {
            var service = new Neo4JService(settings, client, logger);
            await service.InsertNewRequest(null);

            A.CallTo(() => logger.Log(LogLevel.Warning, A <Exception> .Ignored, A <string> .Ignored))
            .MustHaveHappened(1, Times.Exactly);
            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).MustNotHaveHappened();
        }
Beispiel #3
0
        public async Task GetPageBannersAsyncWhenErrorCallingBannerAppThenEmptyContentStringReturned()
        {
            // Arrange
            var expectedError      = "some reason";
            var expectedStatusCode = HttpStatusCode.BadRequest;

            httpResponse = new HttpResponseMessage {
                StatusCode = expectedStatusCode, ReasonPhrase = expectedError
            };
            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            // Act
            var result = await bannerService.GetPageBannersAsync(string.Empty);

            // Assert
            result.Should().NotBeNull();
            result.Value.Should().BeEquivalentTo(string.Empty);
        }
Beispiel #4
0
        public BannerServiceTests()
        {
            logger       = A.Fake <ILogger <BannerService> >();
            httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("some response."),
            };

            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://bannerappurl"),
            };

            memoryCache   = new MemoryCache(Options.Create(new MemoryCacheOptions()));
            bannerService = new BannerService(httpClient, logger, memoryCache);
        }
Beispiel #5
0
 protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     return(Task.FromResult(fakeHttpRequestSender.Send(request)));
 }
Beispiel #6
0
        public ContentRetrieverTests()
        {
            httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(DummyChildAppContent),
            };

            fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();
            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);

            httpClientFactory = A.Fake <IUriSpecifcHttpClientFactory>();
            httpClient        = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri("http://SomeRegionBaseAddress"),
            };

            A.CallTo(() => httpClientFactory.GetClientForRegionEndpoint(A <string> .Ignored)).Returns(httpClient);

            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>"
                    },
                },
            };

            memoryCache    = new MemoryCache(Options.Create(new MemoryCacheOptions()));
            defaultService = new ContentRetriever(httpClientFactory, logger, appRegistryDataService, httpResponseMessageHandler, markupMessages, memoryCache, passOnHeaderSettings);
        }