< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Query.HealthChecks.DatabaseHealthCheck
Assembly: ArturRios.Heimdall.Query
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Application/ArturRios.Heimdall.Query/HealthChecks/DatabaseHealthCheck.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 41
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 3
Fully covered methods: 3
Total methods: 3
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ServiceName()100%11100%
IsHealthyAsync()100%11100%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Application/ArturRios.Heimdall.Query/HealthChecks/DatabaseHealthCheck.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.Interfaces;
 2using ArturRios.Heimdall.Domain.Entities;
 3using Microsoft.EntityFrameworkCore;
 4using Microsoft.Extensions.Logging;
 5
 6namespace ArturRios.Heimdall.Query.HealthChecks;
 7
 8/// <summary>
 9///     Verifies the database connection (UC-30, FR-HC-03) by issuing a trivial read through the
 10///     repository abstraction. If the query completes the connection is healthy; any failure (the
 11///     database being unreachable throws on execution) is treated as unhealthy rather than
 12///     propagated, so the detailed health check can still report the aggregate status (AF-30c).
 13/// </summary>
 14/// <remarks>
 15///     The exception is swallowed so the endpoint keeps answering, but it is logged at Warning: the
 16///     response says only "Unhealthy", and without the cause in the log nobody reading it has a
 17///     reason to go on.
 18/// </remarks>
 3219public class DatabaseHealthCheck(
 3220    IAsyncReadOnlyRepository<Role, long> roleReader,
 3221    ILogger<DatabaseHealthCheck> logger) : IServiceHealthCheck
 22{
 323    public string ServiceName => "Database";
 24
 25    public async Task<bool> IsHealthyAsync()
 26    {
 27        try
 28        {
 29            // A minimal round-trip to the database — succeeds only if the connection is usable.
 930            await roleReader.Query().AnyAsync();
 31
 632            return true;
 33        }
 334        catch (Exception exception)
 35        {
 336            logger.LogWarning(exception, "The database health check failed");
 37
 338            return false;
 39        }
 940    }
 41}