< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Hosting.KestrunContext
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Hosting/KestrunContext.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 55
Line coverage: 100%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
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
get_Request()100%11100%
get_Session()100%22100%
get_HasSession()100%11100%
TryGetSession(...)100%11100%
get_Ct()100%11100%
get_Items()100%11100%
get_User()100%11100%
ToString()50%66100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Hosting/KestrunContext.cs

#LineLine coverage
 1
 2
 3using System.Security.Claims;
 4using Kestrun.Models;
 5using Microsoft.AspNetCore.Http.Features;
 6
 7namespace Kestrun.Hosting;
 8
 9/// <summary>
 10/// Represents the context for a Kestrun request, including the request, response, HTTP context, and host.
 11/// </summary>
 12/// <param name="Request">The Kestrun request.</param>
 13/// <param name="Response">The Kestrun response.</param>
 14/// <param name="HttpContext">The associated HTTP context.</param>
 10015public sealed record KestrunContext(KestrunRequest Request, KestrunResponse Response, HttpContext HttpContext)
 16{
 17    /// <summary>
 18    /// Returns the ASP.NET Core session if the Session middleware is active; otherwise null.
 19    /// </summary>
 820    public ISession? Session => HttpContext.Features.Get<ISessionFeature>()?.Session;
 21
 22    /// <summary>
 23    /// True if Session middleware is active for this request.
 24    /// </summary>
 425    public bool HasSession => Session is not null;
 26
 27    /// <summary>
 28    /// Try pattern to get session without exceptions.
 29    /// </summary>
 30    public bool TryGetSession(out ISession? session)
 31    {
 232        session = Session;
 233        return session is not null;
 34    }
 35
 36    /// <summary>
 37    /// Gets the cancellation token that is triggered when the HTTP request is aborted.
 38    /// </summary>
 139    public CancellationToken Ct => HttpContext.RequestAborted;
 40    /// <summary>
 41    /// Gets the collection of key/value pairs associated with the current HTTP context.
 42    /// </summary>
 343    public IDictionary<object, object?> Items => HttpContext.Items;
 44
 45    /// <summary>
 46    /// Gets the user associated with the current HTTP context.
 47    /// </summary>
 248    public ClaimsPrincipal User => HttpContext.User;
 49
 50    /// <summary>
 51    /// Returns a string representation of the KestrunContext, including path, user, and session status.
 52    /// </summary>
 53    public override string ToString()
 254        => $"KestrunContext{{ Path={HttpContext.Request.Path}, User={User?.Identity?.Name ?? "<anon>"}, HasSession={HasS
 55}