< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Hosting.Options.KestrelOptionsExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Hosting/Options/KestrelOptionsExtensions.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CopyFromTemplate(...)100%1414100%
CopyLimits(...)100%88100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Hosting/Options/KestrelOptionsExtensions.cs

#LineLine coverage
 1using System.Reflection;
 2using Microsoft.AspNetCore.Server.Kestrel.Core;
 3namespace Kestrun.Hosting.Options;
 4
 5/// <summary>
 6/// Provides extension methods for copying configuration between <see cref="KestrelServerOptions"/> instances.
 7/// </summary>
 8public static class KestrelOptionsExtensions
 9{
 10    /// <summary>
 11    /// Shallow-copies every writable property from <paramref name="src"/> to <paramref name="dest"/>,
 12    /// then deep-copies the nested <see cref="KestrelServerLimits"/>.
 13    /// A small “skip” list prevents us from overwriting framework internals.
 14    /// </summary>
 15    public static void CopyFromTemplate(this KestrelServerOptions dest,
 16                                        KestrelServerOptions src)
 17    {
 2618        if (dest is null || src is null)
 19        {
 220            throw new ArgumentNullException();
 21        }
 22
 2423        var skip = new HashSet<string>
 2424        {
 2425            nameof(KestrelServerOptions.ApplicationServices), // owned by the WebHost
 2426           //nameof(KestrelServerOptions.ListenOptions)        // you add those yourself
 2427        };
 28
 29        // ── 1. copy all simple writable props ───────────────────────────────
 62430        foreach (var p in typeof(KestrelServerOptions)
 2431                                   .GetProperties(BindingFlags.Public | BindingFlags.Instance))
 32        {
 28833            if (!p.CanRead || !p.CanWrite)
 34            {
 35                continue;              // read-only
 36            }
 37
 26438            if (p.GetIndexParameters().Length > 0)
 39            {
 40                continue;              // indexer
 41            }
 42
 26443            if (skip.Contains(p.Name))
 44            {
 45                continue;              // infrastructure
 46            }
 47
 24048            p.SetValue(dest, p.GetValue(src));
 49        }
 50
 51        // ── 2. deep-copy the Limits object (property itself is read-only) ──
 2452        CopyLimits(dest.Limits, src.Limits);
 2453    }
 54
 55    private static void CopyLimits(KestrelServerLimits dest, KestrelServerLimits src)
 56    {
 72057        foreach (var p in typeof(KestrelServerLimits)
 2458                                   .GetProperties(BindingFlags.Public | BindingFlags.Instance))
 59        {
 33660            if (!p.CanRead || !p.CanWrite)
 61            {
 62                continue;
 63            }
 64
 28865            if (p.GetIndexParameters().Length > 0)
 66            {
 67                continue;
 68            }
 69
 28870            p.SetValue(dest, p.GetValue(src));
 71        }
 2472    }
 73}