Exemplo n.º 1
0
        public async void Health_check_is_not_healthy()
        {
            const string ExpectedBadHealthMessage = "Bad health mess.";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                BadHealthMessageForTests = ExpectedBadHealthMessage
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest();

            var listLogger = new ListLoggerFixture();

            var func = new HealthCheckFunction(fakeApiAuthorization);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsType <HealthCheckResult>(((OkObjectResult)actionResult).Value);

            var healthCheckResult = (HealthCheckResult)((OkObjectResult)actionResult).Value;

            Assert.False(healthCheckResult.IsHealthy);
            Assert.Equal(ExpectedBadHealthMessage, healthCheckResult.BadHealthMessage);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageThatStartsWith(
                            LogLevel.Error,
                            $"{nameof(HealthCheckFunction)} health check failed."));
        }
Exemplo n.º 2
0
        public async Task Given_Parameters_When_Invoked_With_Error_Then_InvokeAsync_Should_Return_Result()
        {
            var endpoints = new Mock <EndpointsSettings>();

            endpoints.SetupGet(p => p.HealthCheck).Returns("ping");

            var settings = new Mock <ExternalApiSettings>();

            settings.SetupGet(p => p.BaseUri).Returns("http://localhost");
            settings.SetupGet(p => p.Endpoints).Returns(endpoints.Object);

            var message = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            var options = new HttpMessageOptions()
            {
                HttpMethod          = HttpMethod.Get,
                HttpResponseMessage = message
            };
            var handler    = new FakeHttpMessageHandler(options);
            var httpClient = new HttpClient(handler);
            var function   = new HealthCheckFunction(settings.Object, httpClient);

            var req    = new Mock <HttpRequest>();
            var result = await function.InvokeAsync <HttpRequest, IActionResult>(req.Object)
                         .ConfigureAwait(false);

            result
            .Should().BeOfType <ObjectResult>()
            .And.Subject.As <ObjectResult>()
            .StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Exemplo n.º 3
0
        public async void Health_check_is_healthy()
        {
            var fakeApiAuthorization = new FakeApiAuthorizationService();

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest();

            var listLogger = new ListLoggerFixture();

            var func = new HealthCheckFunction(fakeApiAuthorization);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsType <HealthCheckResult>(((OkObjectResult)actionResult).Value);

            var healthCheckResult = (HealthCheckResult)((OkObjectResult)actionResult).Value;

            Assert.True(healthCheckResult.IsHealthy);
            Assert.Null(healthCheckResult.BadHealthMessage);
        }