public async Task CheckHealthAsync_HeaderValueIsEmpty_ReturnsHealthy() { string contentText = nameof(CheckHealthAsync_WhenExpectedStatus_ReturnsHealthy); HttpStatusCode status = HttpStatusCode.Found; KeyValuePair <string, object>[] reportData = Array.Empty <KeyValuePair <string, object> >(); HttpResponseMessage response = new HttpResponseMessage(status) { Content = new StringContent(contentText) }; HttpHealthCheckParameters parameters = HttpHealthCheckParametersTests.Create( headers: new Dictionary <string, IEnumerable <string> > { { "testheader", new List <string>() } }, expectedStatus: status, reportData: reportData); (MockClient _, HealthCheckResult result) = await RunHealthCheckAsync(parameters, response); Assert.AreEqual(HealthStatus.Healthy, result.Status, FormattableString.Invariant($"Should return {HealthStatus.Healthy} for expected status")); Assert.AreEqual(string.Empty, result.Description, "Content should not be in the description for healthy check"); CollectionAssert.AreEquivalent(reportData, result.Data.ToArray(), "Result should propagate reportData"); }
public async Task CheckHealthAsync_WithAdditionalCheck_ReturnsOverridenResult() { string contentText = nameof(CheckHealthAsync_WithAdditionalCheck_ReturnsOverridenResult); KeyValuePair <string, object>[] reportData = new KeyValuePair <string, object> [0]; HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.Ambiguous) { Content = new StringContent(contentText) }; HttpResponseMessage?actualResponce = null; HealthCheckResult initialResult = default; HealthCheckResult expectedResult = HealthCheckResult.Healthy("Some description", new Dictionary <string, object>()); HttpHealthCheckParameters parameters = HttpHealthCheckParametersTests.Create( expectedStatus: HttpStatusCode.BadRequest, additionalCheck: (response, result) => { actualResponce = response; initialResult = result; return(expectedResult); }, reportData: reportData); (MockClient _, HealthCheckResult result) = await RunHealthCheckAsync(parameters, expectedResponse); Assert.AreEqual(expectedResult, result, "Should return overridden result"); Assert.AreEqual(expectedResponse, actualResponce, "Should provide proper HttpResponse to function"); Assert.AreEqual(HealthStatus.Unhealthy, initialResult.Status, "Provided result should have proper status"); Assert.AreEqual(contentText, initialResult.Description, "Provided result should have proper description"); CollectionAssert.AreEquivalent(reportData, result.Data.ToArray(), "Provided result should have proper data"); }
public async Task CheckHealthAsync_HeaderKeyIsWhiteSpace_ReturnsUnhealthy() { string contentText = nameof(CheckHealthAsync_WhenExpectedStatus_ReturnsHealthy); HttpStatusCode status = HttpStatusCode.Found; KeyValuePair <string, object>[] reportData = Array.Empty <KeyValuePair <string, object> >(); HttpResponseMessage response = new HttpResponseMessage(status) { Content = new StringContent(contentText) }; HttpHealthCheckParameters parameters = HttpHealthCheckParametersTests.Create( headers: new Dictionary <string, IEnumerable <string> > { { string.Empty, new List <string> { "value" } } }, expectedStatus: status, reportData: reportData); (MockClient _, HealthCheckResult result) = await RunHealthCheckAsync(parameters, response); Assert.AreEqual(HealthStatus.Unhealthy, result.Status, FormattableString.Invariant($"Should return {HealthStatus.Unhealthy} for expected status")); }
public async Task CheckHealthAsync_WhenWrongStatusAndExplicitRegistrationFailureStatus_ReturnsRegistrationFailureStatus() { string contentText = nameof(CheckHealthAsync_WhenWrongStatusAndExplicitRegistrationFailureStatus_ReturnsRegistrationFailureStatus); KeyValuePair <string, object>[] reportData = new KeyValuePair <string, object> [0]; HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(contentText) }; HttpHealthCheckParameters parameters = HttpHealthCheckParametersTests.Create( expectedStatus: HttpStatusCode.NotFound, reportData: reportData); (MockClient _, HealthCheckResult result) = await RunHealthCheckAsync(parameters, response, failureStatus : HealthStatus.Degraded); Assert.AreEqual(HealthStatus.Degraded, result.Status, FormattableString.Invariant($"Should return {HealthStatus.Unhealthy} for wrong status")); Assert.AreEqual(contentText, result.Description, "Content should be in the description for unhealthy check"); CollectionAssert.AreEquivalent(reportData, result.Data.ToArray(), "Result should propagate reportData"); }