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); }
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); }
public async Task <ProbeResult> Check() { await Task.Delay(1000); Order++; return(ProbeResult.Ok()); }
public void ProbeResult_ok_should_be_successfully() { // arrange // act var result = ProbeResult.Ok(); // assert Assert.True(result.Succeed); Assert.Null(result.ErrorMessage); }
public async Task <ProbeResult> Check() { var context = _autoHealthCheckContextAccessor.Context; var baseUtl = context.Configurations.BaseUrl; var endpointUrl = $"{baseUtl}{Path}"; var request = new HttpRequestMessage(HttpMethod.Get, endpointUrl); var client = _clientFactory.CreateClient(); var response = await client.SendAsync(request).ConfigureAwait(false); var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false); switch (body.ToUpper()) { case "HEALTHY": return(ProbeResult.Ok()); default: return(ProbeResult.Error($"{Name} failed.")); } }
public Task <ProbeResult> Check() { return(Task.FromResult(ProbeResult.Ok())); }