< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Runtime.EnvironmentHelper
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Runtime/EnvironmentHelper.cs
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
62%
Covered lines: 10
Uncovered lines: 6
Coverable lines: 16
Total lines: 85
Line coverage: 62.5%
Branch coverage
78%
Covered branches: 11
Total branches: 14
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 11/19/2025 - 17:40:50 Line coverage: 62.5% (10/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02612/12/2025 - 17:27:19 Line coverage: 56.2% (9/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/15/2025 - 02:23:46 Line coverage: 62.5% (10/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@7a3839f4de2254e22daae81ab8dc7cb2f40c8330 11/19/2025 - 17:40:50 Line coverage: 62.5% (10/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02612/12/2025 - 17:27:19 Line coverage: 56.2% (9/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/15/2025 - 02:23:46 Line coverage: 62.5% (10/16) Branch coverage: 78.5% (11/14) Total lines: 85 Tag: Kestrun/Kestrun@7a3839f4de2254e22daae81ab8dc7cb2f40c8330

Coverage delta

Coverage delta 7 -7

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SetHostEnvironment(...)100%210%
SetOverrideName(...)50%22100%
SetOverride(...)100%210%
ClearOverride()100%11100%
ResolveEnvironment()83.33%121287.5%
get_Name()100%11100%
IsDevelopment()100%210%
IsStaging()100%210%
IsProduction()100%210%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Runtime/EnvironmentHelper.cs

#LineLine coverage
 1namespace Kestrun.Runtime;
 2
 3/// <summary>
 4/// Helpers for determining the current environment name.
 5/// </summary>
 6public static class EnvironmentHelper
 7{
 8    private static Func<string?>? _overrideProvider;
 9    private static IHostEnvironment? _cachedEnv;
 10
 11    /// <summary>
 12    /// Set the host environment (usually from DI).
 13    /// </summary>
 14    /// <param name="env">The host environment.</param>
 015    public static void SetHostEnvironment(IHostEnvironment env) => _cachedEnv = env;
 16
 17    /// <summary>
 18    /// Set an explicit override for the environment name.
 19    /// </summary>
 20    /// <param name="name">The environment name to override with.</param>
 21    public static void SetOverrideName(string? name)
 622        => _overrideProvider = string.IsNullOrWhiteSpace(name) ? null : () => name;
 23
 24    /// <summary>
 25    /// Set an explicit override provider for the environment name.
 26    /// </summary>
 27    /// <param name="provider">The provider function to retrieve the environment name.</param>
 028    public static void SetOverride(Func<string?> provider) => _overrideProvider = provider;
 29
 30    /// <summary>
 31    /// Clear any explicit override for the environment name.
 32    /// </summary>
 133    public static void ClearOverride() => _overrideProvider = null;
 34
 35    /// <summary>
 36    /// Determine the current environment name.
 37    /// </summary>
 38    /// <returns> The current environment name.</returns>
 39    private static string ResolveEnvironment()
 40    {
 41        // 1️⃣ Explicit override
 72442        var fromOverride = _overrideProvider?.Invoke();
 72443        if (!string.IsNullOrWhiteSpace(fromOverride))
 44        {
 545            return fromOverride;
 46        }
 47
 48        // 2️⃣ Cached host environment (from SetHostEnvironment)
 71949        if (!string.IsNullOrWhiteSpace(_cachedEnv?.EnvironmentName))
 50        {
 051            return _cachedEnv.EnvironmentName;
 52        }
 53
 54        // 3️⃣ Standard environment variables (like Kestrel)
 71955        return Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
 71956            ?? Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT")
 71957            ?? "Production";
 58    }
 59
 60    /// <summary>
 61    /// The current environment name.
 62    /// </summary>
 72463    public static string Name => ResolveEnvironment();
 64
 65    /// <summary>
 66    /// Is the current environment "Development"?
 67    /// </summary>
 68    /// <returns>True if the current environment is "Development"; otherwise, false.</returns>
 69    public static bool IsDevelopment()
 070        => string.Equals(Name, Environments.Development, StringComparison.OrdinalIgnoreCase);
 71
 72    /// <summary>
 73    /// Is the current environment "Staging"?
 74    /// </summary>
 75    /// <returns>True if the current environment is "Staging"; otherwise, false.</returns>
 76    public static bool IsStaging()
 077        => string.Equals(Name, Environments.Staging, StringComparison.OrdinalIgnoreCase);
 78
 79    /// <summary>
 80    /// Is the current environment "Production"?
 81    /// </summary>
 82    /// <returns>True if the current environment is "Production"; otherwise, false.</returns>
 83    public static bool IsProduction()
 084        => string.Equals(Name, Environments.Production, StringComparison.OrdinalIgnoreCase);
 85}