282 references to HealthStatus
Aspire.Components.Common.Tests (3)
Aspire.Dashboard (13)
Aspire.Dashboard.Components.Tests (1)
Aspire.Dashboard.Tests (10)
Model\ResourceViewModelTests.cs (7)
10using DiagnosticsHealthStatus = Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus;
24[InlineData(KnownResourceState.Running, DiagnosticsHealthStatus.Healthy, new string[]{})]
25[InlineData(KnownResourceState.Running, DiagnosticsHealthStatus.Healthy, new string?[] {"Healthy"})]
26[InlineData(KnownResourceState.Running, DiagnosticsHealthStatus.Unhealthy, new string?[] {null})]
27[InlineData(KnownResourceState.Running, DiagnosticsHealthStatus.Degraded, new string?[] {"Healthy", "Degraded"})]
28public void Resource_WithHealthReportAndState_ReturnsCorrectHealthStatus(KnownResourceState? state, DiagnosticsHealthStatus? expectedStatus, string?[]? healthStatusStrings)
30var reports = healthStatusStrings?.Select<string?, HealthReportViewModel>((h, i) => new HealthReportViewModel(i.ToString(), h is null ? null : System.Enum.Parse<DiagnosticsHealthStatus>(h), null, null)).ToImmutableArray() ?? [];
Aspire.Hosting (14)
Aspire.Hosting.Elasticsearch.Tests (1)
Aspire.Hosting.Qdrant (1)
Aspire.Hosting.Qdrant.Tests (1)
Aspire.Hosting.Tests (8)
Health\HealthStatusTests.cs (6)
20[InlineData(RunningState, HealthStatus.Healthy, new string[]{})]
21[InlineData(RunningState, HealthStatus.Healthy, new string?[] {"Healthy"})]
22[InlineData(RunningState, HealthStatus.Unhealthy, new string?[] {null})]
23[InlineData(RunningState, HealthStatus.Degraded, new string?[] {"Healthy", "Degraded"})]
24public void Resource_WithHealthReportAndState_ReturnsCorrectHealthStatus(string? state, HealthStatus? expectedStatus, string?[]? healthStatusStrings)
26var reports = healthStatusStrings?.Select<string?, HealthReportSnapshot>((h, i) => new HealthReportSnapshot(i.ToString(), h is null ? null : Enum.Parse<HealthStatus>(h), null, null)).ToImmutableArray() ?? [];
Aspire.Milvus.Client (1)
Aspire.Qdrant.Client (1)
HealthChecksSample (4)
HealthChecksSandbox.AppHost (6)
Program.cs (6)
12AddTestResource("healthy", HealthStatus.Healthy, "I'm fine, thanks for asking.");
13AddTestResource("unhealthy", HealthStatus.Unhealthy, "I can't do that, Dave.", exceptionMessage: "Feeling unhealthy.");
14AddTestResource("degraded", HealthStatus.Degraded, "Had better days.", exceptionMessage: "Feeling degraded.");
28void AddTestResource(string name, HealthStatus status, string? description = null, string? exceptionMessage = null)
41return new HealthCheckResult(HealthStatus.Unhealthy, "Initial failure state.");
44return new HealthCheckResult(HealthStatus.Healthy, "Healthy beginning second health check run.");
Microsoft.AspNetCore.Diagnostics.HealthChecks (26)
HealthCheckOptions.cs (19)
25private IDictionary<HealthStatus, int> _resultStatusCodes = new Dictionary<HealthStatus, int>(DefaultStatusCodesMapping);
27private static readonly IReadOnlyDictionary<HealthStatus, int> DefaultStatusCodesMapping = new Dictionary<HealthStatus, int>
29{HealthStatus.Healthy, StatusCodes.Status200OK},
30{HealthStatus.Degraded, StatusCodes.Status200OK},
31{HealthStatus.Unhealthy, StatusCodes.Status503ServiceUnavailable},
35/// Gets or sets a dictionary mapping the <see cref="HealthStatus"/> to an HTTP status code applied
40/// <see cref="HealthStatus.Healthy"/> to 200 (OK), <see cref="HealthStatus.Degraded"/> to 200 (OK) and
41/// <see cref="HealthStatus.Unhealthy"/> to 503 (Service Unavailable).
43/// <exception cref="InvalidOperationException">Thrown if at least one <see cref="HealthStatus"/> is missing when setting this property.</exception>
44public IDictionary<HealthStatus, int> ResultStatusCodes
47set => _resultStatusCodes = value != null ? ValidateStatusCodesMapping(value) : new Dictionary<HealthStatus, int>(DefaultStatusCodesMapping);
50private static IDictionary<HealthStatus, int> ValidateStatusCodesMapping(IDictionary<HealthStatus, int> mapping)
52var missingHealthStatus = Enum.GetValues<HealthStatus>().Except(mapping.Keys).ToList();
55var missing = string.Join(", ", missingHealthStatus.Select(status => $"{nameof(HealthStatus)}.{status}"));
58$"{nameof(HealthStatus)} values. Missing: {missing}";
Microsoft.AspNetCore.Diagnostics.HealthChecks.Tests (26)
HealthCheckMiddlewareTests.cs (26)
384[HealthStatus.Healthy] = 201,
904Assert.Equal(StatusCodes.Status200OK, options.ResultStatusCodes[HealthStatus.Healthy]);
905Assert.Equal(StatusCodes.Status200OK, options.ResultStatusCodes[HealthStatus.Degraded]);
906Assert.Equal(StatusCodes.Status503ServiceUnavailable, options.ResultStatusCodes[HealthStatus.Unhealthy]);
914Assert.Equal(StatusCodes.Status200OK, options.ResultStatusCodes[HealthStatus.Healthy]);
915Assert.Equal(StatusCodes.Status200OK, options.ResultStatusCodes[HealthStatus.Degraded]);
916Assert.Equal(StatusCodes.Status503ServiceUnavailable, options.ResultStatusCodes[HealthStatus.Unhealthy]);
924ResultStatusCodes = new Dictionary<HealthStatus, int>
926[HealthStatus.Healthy] = 200,
927[HealthStatus.Degraded] = 200,
928[HealthStatus.Unhealthy] = 503
937new HealthCheckOptions { ResultStatusCodes = new Dictionary<HealthStatus, int>() }
939Assert.Contains($"{nameof(HealthStatus)}.{nameof(HealthStatus.Healthy)}", exception.Message);
940Assert.Contains($"{nameof(HealthStatus)}.{nameof(HealthStatus.Degraded)}", exception.Message);
941Assert.Contains($"{nameof(HealthStatus)}.{nameof(HealthStatus.Unhealthy)}", exception.Message);
950ResultStatusCodes = new Dictionary<HealthStatus, int>
952[HealthStatus.Healthy] = 200
956Assert.DoesNotContain($"{nameof(HealthStatus)}.{nameof(HealthStatus.Healthy)}", exception.Message);
957Assert.Contains($"{nameof(HealthStatus)}.{nameof(HealthStatus.Degraded)}", exception.Message);
958Assert.Contains($"{nameof(HealthStatus)}.{nameof(HealthStatus.Unhealthy)}", exception.Message);
Microsoft.Extensions.Diagnostics.HealthChecks (29)
DefaultHealthCheckService.cs (8)
208public static void HealthCheckProcessingEnd(ILogger logger, HealthStatus status, TimeSpan duration) =>
212private static partial void HealthCheckProcessingEnd(ILogger logger, HealthStatus HealthStatus, double ElapsedMilliseconds);
223private static partial void HealthCheckEndHealthy(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription);
226private static partial void HealthCheckEndDegraded(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription, Exception? exception);
229private static partial void HealthCheckEndUnhealthy(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription, Exception? exception);
237case HealthStatus.Healthy:
241case HealthStatus.Degraded:
245case HealthStatus.Unhealthy:
DependencyInjection\HealthChecksBuilderAddCheckExtensions.cs (21)
24/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
25/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
34HealthStatus? failureStatus,
47/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
48/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
58HealthStatus? failureStatus = null,
76/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
77/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
91HealthStatus? failureStatus,
104/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
105/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
119HealthStatus? failureStatus = null,
166/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
167/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
179HealthStatus? failureStatus,
195/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
196/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
209HealthStatus? failureStatus,
231/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
232/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
246HealthStatus? failureStatus,
Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (34)
HealthCheckRegistration.cs (14)
40public HealthCheckRegistration(string name, IHealthCheck instance, HealthStatus? failureStatus, IEnumerable<string>? tags)
51/// The <see cref="HealthStatus"/> that should be reported upon failure of the health check. If the provided value
52/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
56public HealthCheckRegistration(string name, IHealthCheck instance, HealthStatus? failureStatus, IEnumerable<string>? tags, TimeSpan? timeout)
67FailureStatus = failureStatus ?? HealthStatus.Unhealthy;
79/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
80/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
86HealthStatus? failureStatus,
98/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
99/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
106HealthStatus? failureStatus,
119FailureStatus = failureStatus ?? HealthStatus.Unhealthy;
140/// Gets or sets the <see cref="HealthStatus"/> that should be reported upon failure of the health check.
142public HealthStatus FailureStatus { get; set; }
HealthCheckResult.cs (5)
24public HealthCheckResult(HealthStatus status, string? description = null, Exception? exception = null, IReadOnlyDictionary<string, object>? data = null)
50public HealthStatus Status { get; }
60return new HealthCheckResult(status: HealthStatus.Healthy, description, exception: null, data);
72return new HealthCheckResult(status: HealthStatus.Degraded, description, exception: exception, data);
84return new HealthCheckResult(status: HealthStatus.Unhealthy, description, exception, data);
HealthReportEntry.cs (3)
26public HealthReportEntry(HealthStatus status, string? description, TimeSpan duration, Exception? exception, IReadOnlyDictionary<string, object>? data)
41public HealthReportEntry(HealthStatus status, string? description, TimeSpan duration, Exception? exception, IReadOnlyDictionary<string, object>? data, IEnumerable<string>? tags = null)
74public HealthStatus Status { get; }
Microsoft.Extensions.Diagnostics.HealthChecks.Common (9)
Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests (44)
ManualHealthCheckTests.cs (12)
21Assert.Equal(HealthStatus.Healthy, healthCheckResult.Status);
25Assert.Equal(HealthStatus.Unhealthy, manualHealthCheck.Result.Status);
38Assert.Equal(HealthStatus.Unhealthy, (await manualHealthCheckService.CheckHealthAsync(context, CancellationToken.None)).Status);
43Assert.Equal(HealthStatus.Unhealthy, healthCheckResultUnhealthy.Status);
48Assert.Equal(HealthStatus.Healthy, healthCheckResultHealthy.Status);
62Assert.Equal(HealthStatus.Unhealthy, (await manualHealthCheckService.CheckHealthAsync(context, CancellationToken.None)).Status);
68Assert.Equal(HealthStatus.Unhealthy, healthCheckResultUnhealthy.Status);
74Assert.Equal(HealthStatus.Healthy, healthCheckResultHealthy.Status);
89Assert.Equal(HealthStatus.Unhealthy, (await manualHealthCheckService.CheckHealthAsync(context, CancellationToken.None)).Status);
97Assert.Equal(HealthStatus.Unhealthy, healthCheckResult2Unhealthy.Status);
104Assert.Equal(HealthStatus.Unhealthy, healthCheckResult1Unhealthy.Status);
111Assert.Equal(HealthStatus.Healthy, healthCheckResultHealthy.Status);
TelemetryHealthChecksPublisherTests.cs (28)
23public static TheoryData<List<HealthStatus>, bool, int, string, LogLevel, string> PublishAsyncArgs => new()
26new List<HealthStatus> { HealthStatus.Healthy },
31HealthStatus.Healthy.ToString()
34new List<HealthStatus> { HealthStatus.Degraded },
39HealthStatus.Degraded.ToString()
42new List<HealthStatus> { HealthStatus.Unhealthy },
47HealthStatus.Unhealthy.ToString()
50new List<HealthStatus> { HealthStatus.Healthy, HealthStatus.Healthy },
55HealthStatus.Healthy.ToString()
58new List<HealthStatus> { HealthStatus.Healthy, HealthStatus.Unhealthy },
63HealthStatus.Unhealthy.ToString()
66new List<HealthStatus> { HealthStatus.Healthy, HealthStatus.Degraded, HealthStatus.Unhealthy },
72HealthStatus.Unhealthy.ToString()
79IList<HealthStatus> healthStatuses,
120var healthStatus = healthStatuses[i];
121if (healthStatus != HealthStatus.Healthy)
152private static HealthReport CreateHealthReport(IEnumerable<HealthStatus> healthStatuses)
157foreach (var status in healthStatuses)
Microsoft.Extensions.Diagnostics.HealthChecks.Tests (46)
DefaultHealthCheckServiceTest.cs (24)
89Assert.Equal(HealthStatus.Degraded, actual.Value.Status);
98Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
111Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
143Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
152Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
191Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
297Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
304Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
311Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
353Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
377Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
401Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
427Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
432Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
481Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
524Assert.Equal(HealthStatus.Healthy, entry.Value.Status);
529Assert.Equal(HealthStatus.Healthy, entry.Value.Status);
555Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
598b.AddCheck<FailCapturingCheck>("degraded", HealthStatus.Degraded);
599b.AddCheck<FailCapturingCheck>("healthy", HealthStatus.Healthy);
600b.AddCheck<FailCapturingCheck>("unhealthy", HealthStatus.Unhealthy);
612Assert.Equal(HealthStatus.Degraded, actual.Value.Status);
617Assert.Equal(HealthStatus.Healthy, actual.Value.Status);
622Assert.Equal(HealthStatus.Unhealthy, actual.Value.Status);
DependencyInjection\HealthChecksBuilderTest.cs (12)
27services.AddHealthChecks().AddCheck("test", failureStatus: HealthStatus.Degraded, tags: new[] { "tag", }, instance: instance);
37Assert.Equal(HealthStatus.Degraded, registration.FailureStatus);
47services.AddHealthChecks().AddCheck<TestHealthCheck>("test", failureStatus: HealthStatus.Degraded, tags: new[] { "tag", });
57Assert.Equal(HealthStatus.Degraded, registration.FailureStatus);
70services.AddHealthChecks().AddCheck<TestHealthCheck>("test", failureStatus: HealthStatus.Degraded, tags: new[] { "tag", });
80Assert.Equal(HealthStatus.Degraded, registration.FailureStatus);
92.AddTypeActivatedCheck<TestHealthCheckWithArgs>("test", failureStatus: HealthStatus.Degraded, tags: new[] { "tag", }, args: new object[] { 5, "hi", });
102Assert.Equal(HealthStatus.Degraded, registration.FailureStatus);
128Assert.Equal(HealthStatus.Unhealthy, registration.FailureStatus);
151Assert.Equal(HealthStatus.Unhealthy, registration.FailureStatus);
174Assert.Equal(HealthStatus.Unhealthy, registration.FailureStatus);
197Assert.Equal(HealthStatus.Unhealthy, registration.FailureStatus);
HealthReportTest.cs (10)
15[InlineData(HealthStatus.Healthy)]
16[InlineData(HealthStatus.Degraded)]
17[InlineData(HealthStatus.Unhealthy)]
18public void Status_MatchesWorstStatusInResults(HealthStatus status)
22{"Foo", new HealthReportEntry(HealthStatus.Healthy, null,TimeSpan.MinValue, null, null) },
23{"Bar", new HealthReportEntry(HealthStatus.Healthy, null, TimeSpan.MinValue,null, null) },
25{"Quick", new HealthReportEntry(HealthStatus.Healthy, null, TimeSpan.MinValue, null, null) },
26{"Quack", new HealthReportEntry(HealthStatus.Healthy, null, TimeSpan.MinValue, null, null) },
27{"Quock", new HealthReportEntry(HealthStatus.Healthy, null, TimeSpan.MinValue, null, null) },
41{"Foo", new HealthReportEntry(HealthStatus.Healthy, null,TimeSpan.MinValue, null, null) }
Microsoft.Extensions.Diagnostics.Probes (1)
Microsoft.Extensions.Diagnostics.Probes.Tests (3)