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); }
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); }
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); }