< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Security.TokenLifetimeSetting
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Security/TokenLifetimeSetting.cs
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 34
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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
get_Seconds()100%11100%
Parse(...)100%88100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Security/TokenLifetimeSetting.cs

#LineLine coverage
 1using System.Globalization;
 2
 3namespace ArturRios.Heimdall.WebApi.Security;
 4
 5/// <summary>
 6///     A person-token lifetime read from <c>HEIMDALL_AUTH_TOKEN_EXPIRATION_IN_SECONDS</c>: the seconds
 7///     to use, and the configured text when it was present but unusable and the default applied in its
 8///     place. Pulled out of <c>Startup.BuildJwtConfiguration</c> so the parse can be tested and the
 9///     fallback reported.
 10/// </summary>
 11/// <param name="Seconds">The lifetime to use.</param>
 12/// <param name="RejectedValue">
 13///     The configured text when it was present but unusable; <c>null</c> when the variable was absent
 14///     or usable (absent is the documented default, not a fallback).
 15/// </param>
 272116public sealed record TokenLifetimeSetting(double Seconds, string? RejectedValue)
 17{
 18    /// <summary>
 19    ///     Reads <paramref name="configured" /> as a positive, finite number of seconds, using
 20    ///     <paramref name="defaultSeconds" /> when it is absent or unusable.
 21    /// </summary>
 22    public static TokenLifetimeSetting Parse(string? configured, double defaultSeconds)
 23    {
 90724        if (string.IsNullOrWhiteSpace(configured))
 25        {
 90226            return new TokenLifetimeSetting(defaultSeconds, null);
 27        }
 28
 529        return double.TryParse(configured, NumberStyles.Float, CultureInfo.InvariantCulture, out var seconds)
 530               && double.IsFinite(seconds) && seconds > 0
 531            ? new TokenLifetimeSetting(seconds, null)
 532            : new TokenLifetimeSetting(defaultSeconds, configured);
 33    }
 34}