Exemplo n.º 1
0
        public async Task CheckHealthAsync_ExceptionFromPingIsConsideredUnhealthy(
            HealthStatus?failureStatus,
            HealthStatus expectedStatus)
        {
            // Arrange

            var service           = new Mock <IGitLabService>();
            var expectedException = new Exception("OBJECTION!");

            service
            .Setup(m => m.PingAsync(It.IsAny <CancellationToken>()))
            .ThrowsAsync(expectedException);

            var healthCheck = new GitLabHealthCheck(service.Object);

            var context = NextHealthCheckContext(failureStatus);

            // Act

            var result = await healthCheck.CheckHealthAsync(context, default(CancellationToken));

            // Assert

            Assert.Equal(
                $"Exception thrown when attempting to access {context.Registration.Name}.",
                result.Description
                );

            Assert.Equal(expectedException, result.Exception);
            Assert.Equal(expectedStatus, result.Status);
        }
Exemplo n.º 2
0
        public async Task CheckHealthAsync_SuccessfulPingIsConsideredHealthy()
        {
            // Arrange

            var service     = MockService(pingSuccessful: true);
            var healthCheck = new GitLabHealthCheck(service);

            var context = NextHealthCheckContext();

            // Act

            var result = await healthCheck.CheckHealthAsync(context, default(CancellationToken));

            // Assert

            Assert.Equal($"{context.Registration.Name} is accessible.", result.Description);
            Assert.Null(result.Exception);
            Assert.Equal(HealthStatus.Healthy, result.Status);
        }
Exemplo n.º 3
0
        public async Task CheckHealthAsync_UnsuccessfulPingIsConsideredUnhealthy(
            HealthStatus?failureStatus,
            HealthStatus expectedStatus)
        {
            // Arrange

            var service     = MockService(pingSuccessful: false);
            var healthCheck = new GitLabHealthCheck(service);

            var context = NextHealthCheckContext(failureStatus);

            // Act

            var result = await healthCheck.CheckHealthAsync(context);

            // Assert

            Assert.Equal($"{context.Registration.Name} is inaccessible.", result.Description);
            Assert.Null(result.Exception);
            Assert.Equal(expectedStatus, result.Status);
        }