< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Query.HealthChecks.DatabaseHealthCheck
Assembly: ArturRios.Heimdall.Query
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Query/HealthChecks/DatabaseHealthCheck.cs
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 31
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/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Query/HealthChecks/DatabaseHealthCheck.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.Interfaces;
 2using ArturRios.Heimdall.Domain.Entities;
 3using Microsoft.EntityFrameworkCore;
 4
 5namespace ArturRios.Heimdall.Query.HealthChecks;
 6
 7/// <summary>
 8///     Verifies the database connection (UC-30, FR-HC-03) by issuing a trivial read through the
 9///     repository abstraction. If the query completes the connection is healthy; any failure (the
 10///     database being unreachable throws on execution) is treated as unhealthy rather than
 11///     propagated, so the detailed health check can still report the aggregate status (AF-30c).
 12/// </summary>
 413public class DatabaseHealthCheck(IAsyncReadOnlyRepository<Role, long> roleReader) : IServiceHealthCheck
 14{
 315    public string ServiceName => "Database";
 16
 17    public async Task<bool> IsHealthyAsync()
 18    {
 19        try
 20        {
 21            // A minimal round-trip to the database — succeeds only if the connection is usable.
 422            await roleReader.Query().AnyAsync();
 23
 324            return true;
 25        }
 126        catch
 27        {
 128            return false;
 29        }
 430    }
 31}