< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Forms.KrPartContext
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Forms/KrFormContext.cs
Tag: Kestrun/Kestrun@d9261bd752e45afa789d10bc0c82b7d5724d9589
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 140
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 02/05/2026 - 00:28:18 Line coverage: 100% (8/8) Total lines: 140 Tag: Kestrun/Kestrun@d9261bd752e45afa789d10bc0c82b7d5724d9589

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Index()100%11100%
get_Name()100%11100%
get_FileName()100%11100%
get_ContentType()100%11100%
get_ContentEncoding()100%11100%
get_DeclaredLength()100%11100%
get_Headers()100%11100%
get_Rule()100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Forms/KrFormContext.cs

#LineLine coverage
 1using System.Collections.ObjectModel;
 2using Kestrun.Hosting;
 3using Kestrun.Models;
 4
 5namespace Kestrun.Forms;
 6/// <summary>
 7/// Represents the form parsing context for a request.
 8/// </summary>
 9public sealed record KrFormContext
 10{
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="KrFormContext"/> class.
 13    /// </summary>
 14    /// <param name="kestrunContext">The Kestrun context.</param>
 15    /// <param name="options">The form parsing options.</param>
 16    /// <param name="payload">The parsed payload.</param>
 17    public KrFormContext(KestrunContext kestrunContext, KrFormOptions options, IKrFormPayload payload)
 18    {
 19        KestrunContext = kestrunContext;
 20        Host = kestrunContext.Host;
 21        HttpContext = kestrunContext.HttpContext;
 22        Options = options;
 23        Payload = payload;
 24    }
 25
 26    /// <summary>
 27    /// Gets the associated Kestrun host.
 28    /// </summary>
 29    public KestrunHost Host { get; }
 30
 31    /// <summary>
 32    /// Gets the associated Kestrun context.
 33    /// </summary>
 34    public KestrunContext KestrunContext { get; }
 35
 36    /// <summary>
 37    /// Gets the underlying HTTP context.
 38    /// </summary>
 39    public HttpContext HttpContext { get; }
 40
 41    /// <summary>
 42    /// Gets the form parsing options.
 43    /// </summary>
 44    public KrFormOptions Options { get; }
 45
 46    /// <summary>
 47    /// Gets the parsed payload.
 48    /// </summary>
 49    public IKrFormPayload Payload { get; }
 50
 51    /// <summary>
 52    /// Gets the logger associated with the host.
 53    /// </summary>
 54    public Serilog.ILogger Logger => Host.Logger;
 55}
 56
 57/// <summary>
 58/// Represents the context for a part as it is being processed.
 59/// </summary>
 60public sealed record KrPartContext
 61{
 62    /// <summary>
 63    /// Gets the zero-based index of the part within the multipart body.
 64    /// </summary>
 465    public int Index { get; init; }
 66
 67    /// <summary>
 68    /// Gets the part name, if present.
 69    /// </summary>
 1370    public string? Name { get; init; }
 71
 72    /// <summary>
 73    /// Gets the original filename, if present.
 74    /// </summary>
 475    public string? FileName { get; init; }
 76
 77    /// <summary>
 78    /// Gets the content type of the part.
 79    /// </summary>
 1880    public string ContentType { get; init; } = "application/octet-stream";
 81
 82    /// <summary>
 83    /// Gets the content encoding of the part, if present.
 84    /// </summary>
 885    public string? ContentEncoding { get; init; }
 86
 87    /// <summary>
 88    /// Gets the declared length of the part, if present.
 89    /// </summary>
 490    public long? DeclaredLength { get; init; }
 91
 92    /// <summary>
 93    /// Gets the headers associated with the part.
 94    /// </summary>
 1295    public IReadOnlyDictionary<string, string[]> Headers { get; init; } = new ReadOnlyDictionary<string, string[]>(new D
 96
 97    /// <summary>
 98    /// Gets the matching rule for the part, if any.
 99    /// </summary>
 8100    public KrFormPartRule? Rule { get; init; }
 101}
 102
 103/// <summary>
 104/// Defines the action taken for a part.
 105/// </summary>
 106public enum KrPartAction
 107{
 108    /// <summary>
 109    /// Continue processing the part.
 110    /// </summary>
 111    Continue,
 112
 113    /// <summary>
 114    /// Skip the part content without storing.
 115    /// </summary>
 116    Skip,
 117
 118    /// <summary>
 119    /// Reject the request.
 120    /// </summary>
 121    Reject
 122}
 123
 124/// <summary>
 125/// Represents form parsing errors with HTTP status codes.
 126/// </summary>
 127public class KrFormException(string message, int statusCode) : InvalidOperationException(message)
 128{
 129    /// <summary>
 130    /// Gets the HTTP status code to return.
 131    /// </summary>
 132    public int StatusCode { get; } = statusCode;
 133}
 134
 135/// <summary>
 136/// Represents a form parsing limit violation.
 137/// </summary>
 138public sealed class KrFormLimitExceededException(string message, int statusCode = StatusCodes.Status413PayloadTooLarge)
 139    : KrFormException(message, statusCode)
 140{ }