< Summary

Information
Class: Chronicis.Client.Services.VersionService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/VersionService.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 48
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/VersionService.cs

#LineLine coverage
 1using System.Net.Http.Json;
 2
 3namespace Chronicis.Client.Services;
 4
 5/// <summary>
 6/// Fetches build version information from wwwroot/version.json (stamped by CI).
 7/// The result is cached after the first successful fetch.
 8/// </summary>
 9public class VersionService : IVersionService
 10{
 11    private readonly HttpClient _httpClient;
 12    private readonly ILogger<VersionService> _logger;
 13    private BuildInfo? _cached;
 14
 15    public VersionService(HttpClient httpClient, ILogger<VersionService> logger)
 16    {
 2217        _httpClient = httpClient;
 2218        _logger = logger;
 2219    }
 20
 21    /// <inheritdoc />
 22    public async Task<BuildInfo> GetBuildInfoAsync()
 23    {
 24        if (_cached is not null)
 25            return _cached;
 26
 27        try
 28        {
 29            var info = await _httpClient.GetFromJsonAsync<BuildInfo>("version.json");
 30            _cached = info ?? Fallback();
 31        }
 32        catch (Exception ex)
 33        {
 34            _logger.LogWarning(ex, "Failed to fetch version.json — using fallback version info");
 35            _cached = Fallback();
 36        }
 37
 38        return _cached;
 39    }
 40
 341    private static BuildInfo Fallback() => new()
 342    {
 343        Version = "0.0.0",
 344        BuildNumber = "0",
 345        Sha = "unknown",
 346        BuildDate = string.Empty
 347    };
 48}