< 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@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 69
Line coverage: 100%
Branch coverage
66%
Covered branches: 12
Total branches: 18
Branch coverage: 66.6%
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@5438f2d36871da1fed01100cfe878a4720b76931 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@5438f2d36871da1fed01100cfe878a4720b76931

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetVariablesMap(...)75%44100%
GetSharedStateStore(...)75%44100%
GetCommonProperties(...)60%1010100%

File(s)

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

#LineLine coverage
 1using System.Reflection;
 2using Kestrun.Models;
 3using Kestrun.SharedState;
 4
 5namespace Kestrun.Runtime;
 6
 7/// <summary>
 8/// Helper class to map common request and server properties, as well as shared state variables, into a dictionary.
 9/// </summary>
 10public static class VariablesMap
 11{
 12    /// <summary>
 13    /// Populates the provided dictionary with variables from the request context and shared state store.
 14    /// </summary>
 15    /// <param name="ctx">The Kestrun context containing request information.</param>
 16    /// <param name="vars">The dictionary to populate with variables.</param>
 17    /// <returns>True if variables were successfully mapped; otherwise, false.</returns>
 18    public static bool GetVariablesMap(KestrunContext ctx, ref Dictionary<string, object?> vars)
 19    {
 20        // ① Initialize the dictionary
 121        vars ??= new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
 122        return GetCommonProperties(ctx, ref vars) // ② Add common request properties
 123        && GetSharedStateStore(ref vars); // ③ Add shared state variables
 24    }
 25
 26    /// <summary>
 27    /// Populates the provided dictionary with variables from the shared state store.
 28    /// </summary>
 29    /// <param name="vars">The dictionary to populate with shared state variables.</param>
 30    /// <returns>True if variables were successfully mapped; otherwise, false.</returns>
 31    public static bool GetSharedStateStore(ref Dictionary<string, object?> vars)
 32    {
 133        vars ??= new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
 834        foreach (var kv in SharedStateStore.Snapshot())
 35        {
 336            vars[kv.Key] = kv.Value; // 1) top-level JSON
 37        }
 38
 139        return true;
 40    }
 41
 42    /// <summary>
 43    /// Populates the provided dictionary with common request and server properties from the Kestrun context.
 44    /// </summary>
 45    /// <param name="ctx">The Kestrun context containing request information.</param>
 46    /// <param name="vars">The dictionary to populate with common properties.</param>
 47    /// <returns>True if properties were successfully mapped; otherwise, false.</returns>
 48    public static bool GetCommonProperties(KestrunContext ctx, ref Dictionary<string, object?> vars)
 49    {
 50        // ① Initialize the dictionary
 251        vars["Context"] = ctx;
 252        vars["Request"] = ctx.Request;
 253        vars["QueryString"] = ctx.Request.Query.ToDictionary(q => q.Key, q => q.Value.ToString());
 254        vars["Form"] = ctx.Request.Form;
 255        vars["Cookies"] = ctx.Request.Cookies;
 656        vars["Headers"] = ctx.Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString());
 257        vars["UserAgent"] = ctx.Request.Headers["User-Agent"].ToString();
 258        vars["ServerVersion"] = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
 259        vars["ServerOS"] = Environment.OSVersion.ToString();
 260        vars["ServerArch"] = Environment.Is64BitOperatingSystem ? "x64" : "x86";
 261        vars["ServerIP"] = ctx.HttpContext.Connection.LocalIpAddress?.ToString() ?? "unknown";
 262        vars["ServerPort"] = ctx.HttpContext.Connection.LocalPort;
 263        vars["ServerName"] = Environment.MachineName;
 264        vars["Timestamp"] = DateTimeOffset.UtcNow.ToString("O");
 65
 266        return true;
 67    }
 68}
 69