From b8b438d9450bf068ae56da9dd7ddd3c02196cb85 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 5 Aug 2020 14:21:55 -0700 Subject: [PATCH] Add additional constructor to HealthReport (#24597) Co-authored-by: Serg046 --- .../Abstractions/src/HealthReport.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/HealthChecks/Abstractions/src/HealthReport.cs b/src/HealthChecks/Abstractions/src/HealthReport.cs index 6a796b0d82..aace74286d 100644 --- a/src/HealthChecks/Abstractions/src/HealthReport.cs +++ b/src/HealthChecks/Abstractions/src/HealthReport.cs @@ -17,9 +17,23 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks /// A containing the results from each health check. /// A value indicating the time the health check service took to execute. public HealthReport(IReadOnlyDictionary entries, TimeSpan totalDuration) + : this( + entries, + CalculateAggregateStatus(entries?.Values ?? throw new ArgumentNullException(nameof(entries))), + totalDuration) + { + } + + /// + /// Create a new from the specified results. + /// + /// A containing the results from each health check. + /// A representing the aggregate status of all the health checks. + /// A value indicating the time the health check service took to execute. + public HealthReport(IReadOnlyDictionary entries, HealthStatus status, TimeSpan totalDuration) { Entries = entries; - Status = CalculateAggregateStatus(entries.Values); + Status = status; TotalDuration = totalDuration; } @@ -43,7 +57,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks /// public TimeSpan TotalDuration { get; } - private HealthStatus CalculateAggregateStatus(IEnumerable entries) + private static HealthStatus CalculateAggregateStatus(IEnumerable entries) { // This is basically a Min() check, but we know the possible range, so we don't need to walk the whole list var currentValue = HealthStatus.Healthy;