< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Query.Handlers.GetDetailedHealthQueryHandler
Assembly: ArturRios.Heimdall.Query
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Query/Handlers/GetDetailedHealthQueryHandler.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()100%66100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Query/Handlers/GetDetailedHealthQueryHandler.cs

#LineLine coverage
 1using ArturRios.Heimdall.Query.HealthChecks;
 2using ArturRios.Heimdall.Query.Input;
 3using ArturRios.Heimdall.Query.Output;
 4using ArturRios.Mediator.Query.Interfaces;
 5using ArturRios.Output;
 6
 7namespace ArturRios.Heimdall.Query.Handlers;
 8
 9/// <summary>
 10///     Handles <see cref="DetailedHealthQuery" /> (UC-30, FR-HC-02…06): runs every registered
 11///     <see cref="IServiceHealthCheck" />, reports each service's status, and computes the aggregate
 12///     general status — <c>Healthy</c> only when all services are up, <c>Unhealthy</c> if any is down
 13///     (FR-HC-05, AF-30c). The set of checks is injected, so new verifications participate without
 14///     changing this handler.
 15/// </summary>
 516public class GetDetailedHealthQueryHandler(IEnumerable<IServiceHealthCheck> healthChecks)
 17    : IQueryHandlerAsync<DetailedHealthQuery, HealthCheckOutput>
 18{
 19    public async Task<DataOutput<HealthCheckOutput?>> HandleAsync(DetailedHealthQuery query, CancellationToken cancellat
 20    {
 521        var services = new List<ServiceHealthOutput>();
 22
 2023        foreach (var check in healthChecks)
 24        {
 525            var healthy = await check.IsHealthyAsync();
 26
 527            services.Add(new ServiceHealthOutput
 528            {
 529                Name = check.ServiceName,
 530                Status = healthy ? HealthStatuses.Healthy : HealthStatuses.Unhealthy
 531            });
 532        }
 33
 34        // Aggregate: any unhealthy service makes the whole API unhealthy (FR-HC-05).
 1035        var aggregate = services.TrueForAll(service => service.Status == HealthStatuses.Healthy)
 536            ? HealthStatuses.Healthy
 537            : HealthStatuses.Unhealthy;
 38
 539        var result = new HealthCheckOutput
 540        {
 541            Status = aggregate,
 542            Services = services
 543        };
 44
 545        return DataOutput<HealthCheckOutput?>.New.WithData(result);
 546    }
 47}