public async Task HealthCheckResultProcessor_should_return_ok_with_custom_rule()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations
            {
                PassCheckRule = m => m.StatusCode != HttpStatusCode.OK     // if is ok should fail
            });

            var messages = new List <HttpResponseMessage>
            {
                new HttpResponseMessage(HttpStatusCode.AlreadyReported),
                new HttpResponseMessage(HttpStatusCode.Ambiguous),
                new HttpResponseMessage(HttpStatusCode.BadRequest),
                new HttpResponseMessage(HttpStatusCode.InternalServerError),
            };

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                messages.ToArray(),
                new ProbeResult[0]);

            // assert
            Assert.NotNull(result);
            Assert.Equal(200, (int)result.HttpStatus);
            Assert.True(result.Success);
        }
        public async Task HealthCheckResultProcessor_should_return_custom_response_code_with_default_rule()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations
            {
                DefaultHealthyResponseCode = HttpStatusCode.Continue
            });

            var messages = new List <HttpResponseMessage>
            {
                new HttpResponseMessage(HttpStatusCode.OK),
                new HttpResponseMessage(HttpStatusCode.AlreadyReported),
                new HttpResponseMessage(HttpStatusCode.Ambiguous),
                new HttpResponseMessage(HttpStatusCode.BadRequest)
            };

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                messages.ToArray(),
                new ProbeResult[0]);

            // assert
            Assert.NotNull(result);
            Assert.Equal(HttpStatusCode.Continue, result.HttpStatus);
            Assert.True(result.Success);
        }
Пример #3
0
        public async Task HealthCheckResultProcessor_should_fail_returning_500_with_default_rule()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations());     // default rule

            var messages = new List <HttpResponseMessage>
            {
                new HttpResponseMessage(HttpStatusCode.InternalServerError),
                new HttpResponseMessage(HttpStatusCode.BadGateway)
            };

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                messages.ToArray(),
                new ProbeResult[0]);

            // assert
            Assert.NotNull(result);
            Assert.Equal(500, (int)result.HttpStatus);
            Assert.False(result.Success);
            Assert.Equal(2, result.UnhealthyEndpoints.Count);
            Assert.Equal(500, result.UnhealthyEndpoints[0].HttpStatusCode);
            Assert.Equal(502, result.UnhealthyEndpoints[1].HttpStatusCode);
        }
Пример #4
0
        public async Task HealthCheckResultProcessor_should_fail_with_bad_probes()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations());     // default rule

            var probes = new List <ProbeResult>
            {
                ProbeResult.Error("error"),
                ProbeResult.Ok()
            };

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                new HttpResponseMessage[0],
                probes.ToArray());

            // assert
            Assert.NotNull(result);
            Assert.Equal(500, (int)result.HttpStatus);
            Assert.Equal("error", result.UnhealthyProbes.First().ErrorMessage);
            Assert.False(result.Success);
        }
Пример #5
0
        public async Task HealthCheckResultProcessor_should_return_ok_with_successfully_probes()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations());     // default rule

            var probes = new List <ProbeResult>
            {
                ProbeResult.Ok(),
                ProbeResult.Ok()
            };

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                new HttpResponseMessage[0],
                probes.ToArray());

            // assert
            Assert.NotNull(result);
            Assert.Equal(200, (int)result.HttpStatus);
            Assert.True(result.Success);
        }
Пример #6
0
        public async Task HealthCheckResultProcessor_should_return_ok_with_empty_both_results()
        {
            // arrange
            var watch = new Stopwatch();

            watch.Start();
            var context = new Mock <IAutoHealthCheckContext>();

            context.Setup(c => c.Configurations)
            .Returns(new AutoHealthCheckConfigurations());

            // act
            var result = await HealthCheckResultProcessor.ProcessResult(
                context.Object,
                watch,
                new HttpResponseMessage[0],
                new ProbeResult[0]);

            // assert
            Assert.NotNull(result);
            Assert.Equal(200, (int)result.HttpStatus);
            Assert.True(result.Success);
        }