< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Runtime.VariablesMap
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Runtime/VariablesMap.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
92%
Covered lines: 25
Uncovered lines: 2
Coverable lines: 27
Total lines: 87
Line coverage: 92.5%
Branch coverage
58%
Covered branches: 14
Total branches: 24
Branch coverage: 58.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e10/15/2025 - 01:01:18 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc584010/15/2025 - 14:41:22 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@b8b9998b417b75ba511e5145a7d5cf848bac551710/15/2025 - 21:27:26 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b66559410/15/2025 - 22:47:55 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@f97c41150c4de89829eca919cc8b9b7e7df3df8e10/17/2025 - 17:13:00 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@72ffc26b6676ccf0f60d50c94e4bb52de23743be10/17/2025 - 20:53:54 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@5438f2d36871da1fed01100cfe878a4720b7693110/27/2025 - 15:14:42 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@29b7a3fdf10e67fea44e784a49929d1eb2a8874610/27/2025 - 17:48:01 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@43d8ece4bc8573b7948ce1cea478a13ad32652d011/14/2025 - 12:29:34 Line coverage: 92.5% (25/27) Branch coverage: 58.3% (14/24) Total lines: 87 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626 10/13/2025 - 16:52:37 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e10/15/2025 - 01:01:18 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc584010/15/2025 - 14:41:22 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@b8b9998b417b75ba511e5145a7d5cf848bac551710/15/2025 - 21:27:26 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b66559410/15/2025 - 22:47:55 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@f97c41150c4de89829eca919cc8b9b7e7df3df8e10/17/2025 - 17:13:00 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@72ffc26b6676ccf0f60d50c94e4bb52de23743be10/17/2025 - 20:53:54 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@5438f2d36871da1fed01100cfe878a4720b7693110/27/2025 - 15:14:42 Line coverage: 95.4% (21/22) Branch coverage: 61.1% (11/18) Total lines: 69 Tag: Kestrun/Kestrun@29b7a3fdf10e67fea44e784a49929d1eb2a8874610/27/2025 - 17:48:01 Line coverage: 100% (22/22) Branch coverage: 66.6% (12/18) Total lines: 69 Tag: Kestrun/Kestrun@43d8ece4bc8573b7948ce1cea478a13ad32652d011/14/2025 - 12:29:34 Line coverage: 92.5% (25/27) Branch coverage: 58.3% (14/24) Total lines: 87 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetVariablesMap(...)66.66%66100%
GetHostSharedState(...)50%4475%
GetSharedStateStore(...)50%4475%
GetCommonProperties(...)60%1010100%

File(s)

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

#LineLine coverage
 1using System.Reflection;
 2using Kestrun.Hosting;
 3using Kestrun.Models;
 4using Kestrun.SharedState;
 5
 6namespace Kestrun.Runtime;
 7
 8/// <summary>
 9/// Helper class to map common request and server properties, as well as shared state variables, into a dictionary.
 10/// </summary>
 11public static class VariablesMap
 12{
 13    /// <summary>
 14    /// Populates the provided dictionary with variables from the request context and shared state store.
 15    /// </summary>
 16    /// <param name="ctx">The Kestrun context containing request information.</param>
 17    /// <param name="vars">The dictionary to populate with variables.</param>
 18    /// <returns>True if variables were successfully mapped; otherwise, false.</returns>
 19    public static bool GetVariablesMap(KestrunContext ctx, ref Dictionary<string, object?> vars)
 20    {
 21        // ① Initialize the dictionary
 122        vars ??= new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
 123        return GetCommonProperties(ctx, ref vars) // ② Add common request properties
 124            && GetHostSharedState(ctx.Host, ref vars) // ③ Add host shared state variables
 125            && GetSharedStateStore(ref vars); // ③ Add shared state variables
 26    }
 27
 28    /// <summary>
 29    /// Populates the provided dictionary with variables from the shared state store.
 30    /// </summary>
 31    /// <param name="host">The Kestrun host instance.</param>
 32    /// <param name="vars">The dictionary to populate with shared state variables.</param>
 33    /// <returns>True if variables were successfully mapped; otherwise, false.</returns>
 34    private static bool GetHostSharedState(KestrunHost host, ref Dictionary<string, object?> vars)
 35    {
 136        vars ??= new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
 237        foreach (var kv in host.SharedState.Snapshot())
 38        {
 039            vars[kv.Key] = kv.Value; // 1) top-level JSON
 40        }
 41
 142        return true;
 43    }
 44
 45    /// <summary>
 46    /// Populates the provided dictionary with variables from the global shared state store.
 47    /// </summary>
 48    /// <param name="vars">The dictionary to populate with global shared state variables.</param>
 49    /// <returns>True if variables were successfully mapped; otherwise, false.</returns>
 50    private static bool GetSharedStateStore(ref Dictionary<string, object?> vars)
 51    {
 152        vars ??= new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
 253        foreach (var kv in GlobalStore.Snapshot())
 54        {
 055            vars[kv.Key] = kv.Value; // 1) top-level JSON
 56        }
 57
 158        return true;
 59    }
 60    /// <summary>
 61    /// Populates the provided dictionary with common request and server properties from the Kestrun context.
 62    /// </summary>
 63    /// <param name="ctx">The Kestrun context containing request information.</param>
 64    /// <param name="vars">The dictionary to populate with common properties.</param>
 65    /// <returns>True if properties were successfully mapped; otherwise, false.</returns>
 66    public static bool GetCommonProperties(KestrunContext ctx, ref Dictionary<string, object?> vars)
 67    {
 68        // ① Initialize the dictionary
 269        vars["Context"] = ctx;
 270        vars["Request"] = ctx.Request;
 271        vars["QueryString"] = ctx.Request.Query.ToDictionary(q => q.Key, q => q.Value.ToString());
 272        vars["Form"] = ctx.Request.Form;
 273        vars["Cookies"] = ctx.Request.Cookies;
 674        vars["Headers"] = ctx.Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString());
 275        vars["UserAgent"] = ctx.Request.Headers["User-Agent"].ToString();
 276        vars["ServerVersion"] = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
 277        vars["ServerOS"] = Environment.OSVersion.ToString();
 278        vars["ServerArch"] = Environment.Is64BitOperatingSystem ? "x64" : "x86";
 279        vars["ServerIP"] = ctx.HttpContext.Connection.LocalIpAddress?.ToString() ?? "unknown";
 280        vars["ServerPort"] = ctx.HttpContext.Connection.LocalPort;
 281        vars["ServerName"] = Environment.MachineName;
 282        vars["Timestamp"] = DateTimeOffset.UtcNow.ToString("O");
 83
 284        return true;
 85    }
 86}
 87