Exemplo n.º 1
0
        public async Task IsHealthyCatchesExceptionWhenExceptionThrownByChildApp()
        {
            // Arrange
            var httpClientFactory = A.Fake <IHttpClientFactory>();

            A.CallTo(() => httpClientFactory.CreateClient(A <string> .Ignored)).Throws <Exception>();
            var service = new HealthCheckerService(httpClientFactory, defaultLogger);

            var result = await service.IsHealthy(new Uri("http://someRegionEndpoint"), false, MediaTypeNames.Text.Html).ConfigureAwait(false);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 2
0
        public async Task IsHealthyReturnsTrueWhenSuccessResultFromChildApp(bool isHealthy, HttpStatusCode statusCode, bool treatNotFoundAsSuccessCode)
        {
            // Arrange
            var httpClientFactory = A.Fake <IHttpClientFactory>();

            using var httpResponse = new HttpResponseMessage { StatusCode = statusCode };
            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();

            using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            using var httpClient             = new HttpClient(fakeHttpMessageHandler);
            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);
            A.CallTo(() => httpClientFactory.CreateClient(A <string> .Ignored)).Returns(httpClient);
            var service = new HealthCheckerService(httpClientFactory, defaultLogger);

            // Act
            var result = await service.IsHealthy(new Uri("http://someRegionEndpoint"), treatNotFoundAsSuccessCode, MediaTypeNames.Text.Html).ConfigureAwait(false);

            // Assert
            Assert.Equal(isHealthy, result);
        }