< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Utilities.HttpVerbExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/HttpVerb.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 225
Line coverage: 95.8%
Branch coverage
94%
Covered branches: 17
Total branches: 18
Branch coverage: 94.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 09/08/2025 - 20:34:03 Line coverage: 95.8% (23/24) Branch coverage: 94.4% (17/18) Total lines: 216 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7201/09/2026 - 02:57:32 Line coverage: 95.8% (23/24) Branch coverage: 94.4% (17/18) Total lines: 225 Tag: Kestrun/Kestrun@e3a5419e6c64edac795b8d501a4f334796c09139 09/08/2025 - 20:34:03 Line coverage: 95.8% (23/24) Branch coverage: 94.4% (17/18) Total lines: 216 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7201/09/2026 - 02:57:32 Line coverage: 95.8% (23/24) Branch coverage: 94.4% (17/18) Total lines: 225 Tag: Kestrun/Kestrun@e3a5419e6c64edac795b8d501a4f334796c09139

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToMethodString(...)100%11100%
FromMethodString(...)100%1616100%
TryFromMethodString(...)50%2287.5%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/HttpVerb.cs

#LineLine coverage
 1namespace Kestrun.Utilities;
 2
 3/// <summary>
 4/// Common HTTP verbs recognized by the framework.
 5/// </summary>
 6/// <remarks>
 7/// This enum includes standard HTTP methods as well as WebDAV extensions.
 8/// It is designed to be extensible for future HTTP methods.
 9/// The enum values correspond to the HTTP methods as defined in various RFCs:
 10/// RFC 4918 - HTTP Extensions for WebDAV
 11/// RFC 3744 - WebDAV Access Control Protocol
 12/// RFC 3253 - Versioning Extensions to WebDAV
 13/// RFC 5323 - WebDAV SEARCH
 14/// RFC 5842 - WebDAV Ordered Collections
 15/// RFC 5689 - WebDAV Bindings
 16/// RFC 6620 - WebDAV MERGE
 17/// RFC 5689 - WebDAV BIND
 18/// RFC 4918 - WebDAV
 19/// RFC 7231 - HTTP/1.1 Semantics and Content
 20/// RFC 7232 - HTTP/1.1 Conditional Requests
 21/// RFC 7233 - HTTP/1.1 Range Requests
 22/// RFC 7234 - HTTP/1.1 Caching
 23/// RFC 7235 - HTTP/1.1 Authentication
 24/// RFC 9535 - QUERY Method for HTTP
 25/// </remarks>
 26[Flags]
 27public enum HttpVerb
 28{
 29    /// <summary>
 30    /// Represents the HTTP GET method.
 31    /// </summary>
 32    Get = 1 << 0,
 33    /// <summary>
 34    /// Represents the HTTP HEAD method.
 35    /// </summary>
 36    Head = 1 << 1,
 37    /// <summary>
 38    /// Represents the HTTP POST method.
 39    /// </summary>
 40    Post = 1 << 2,
 41    /// <summary>
 42    /// Represents the HTTP PUT method.
 43    /// </summary>
 44    Put = 1 << 3,
 45    /// <summary>
 46    /// Represents the HTTP PATCH method.
 47    /// </summary>
 48    Patch = 1 << 4,
 49    /// <summary>
 50    /// Represents the HTTP DELETE method.
 51    /// </summary>
 52    Delete = 1 << 5,
 53    /// <summary>
 54    /// Represents the HTTP OPTIONS method.
 55    /// </summary>
 56    Options = 1 << 6,
 57    /// <summary>
 58    /// Represents the HTTP TRACE method.
 59    /// </summary>
 60    Trace = 1 << 7,
 61    /// <summary>
 62    /// Represents the HTTP QUERY method.
 63    /// </summary>
 64    Query = 1 << 8,
 65
 66    //*******************
 67    // WebDAV verbs
 68    //*******************
 69
 70    /// <summary>
 71    /// Represents the HTTP PROPFIND method (WebDAV).
 72    /// </summary>
 73    PropFind = 1 << 9,
 74    /// <summary>
 75    /// Represents the HTTP PROPPATCH method (WebDAV).
 76    /// </summary>
 77    PropPatch = 1 << 10,
 78    /// <summary>
 79    /// Represents the HTTP MKCOL method (WebDAV).
 80    /// </summary>
 81    MkCol = 1 << 11,
 82    /// <summary>
 83    /// Represents the HTTP COPY method (WebDAV).
 84    /// </summary>
 85    Copy = 1 << 12,
 86    /// <summary>
 87    /// Represents the HTTP MOVE method (WebDAV).
 88    /// </summary>
 89    Move = 1 << 13,
 90    /// <summary>
 91    /// Represents the HTTP LOCK method (WebDAV).
 92    /// </summary>
 93    Lock = 1 << 14,
 94    /// <summary>
 95    /// Represents the HTTP UNLOCK method (WebDAV).
 96    /// </summary>
 97    Unlock = 1 << 15,
 98    /// <summary>
 99    /// Represents the HTTP REPORT method (WebDAV).
 100    /// </summary>
 101    Report = 1 << 16,
 102    /// <summary>
 103    /// Represents the HTTP ACL method (WebDAV).
 104    /// </summary>
 105    Acl = 1 << 17,
 106    /// <summary>
 107    /// Represents the HTTP SEARCH method (WebDAV).
 108    /// </summary>
 109    Search = 1 << 18,
 110    /// <summary>
 111    /// Represents the HTTP MERGE method (WebDAV).
 112    /// </summary>
 113    Merge = 1 << 19,
 114    /// <summary>
 115    /// Represents the HTTP BIND method (WebDAV).
 116    /// </summary>
 117    Bind = 1 << 20,
 118    /// <summary>
 119    /// Represents the HTTP UNBIND method (WebDAV).
 120    /// </summary>
 121    Unbind = 1 << 21,
 122    /// <summary>
 123    /// Represents the HTTP REBIND method (WebDAV).
 124    /// </summary>
 125    Rebind = 1 << 22,
 126    /// <summary>
 127    /// Represents the HTTP UPDATE method (WebDAV).
 128    /// </summary>
 129    Update = 1 << 23,
 130    /// <summary>
 131    /// Represents the HTTP VERSION-CONTROL method (WebDAV).
 132    /// </summary>
 133    VersionControl = 1 << 24,
 134    /// <summary>
 135    /// Represents the HTTP CHECKIN method (WebDAV).
 136    /// </summary>
 137    Checkin = 1 << 25,
 138    /// <summary>
 139    /// Represents the HTTP CHECKOUT method (WebDAV).
 140    /// </summary>
 141    Checkout = 1 << 26,
 142    /// <summary>
 143    /// Represents the HTTP UNCHECKOUT method (WebDAV).
 144    /// </summary>
 145    Uncheckout = 1 << 27,
 146    /// <summary>
 147    /// Represents the HTTP MKWORKSPACE method (WebDAV).
 148    /// </summary>
 149    MkWorkspace = 1 << 28,
 150    /// <summary>
 151    /// Represents the HTTP LABEL method (WebDAV).
 152    /// </summary>
 153    Label = 1 << 29,
 154    /// <summary>
 155    /// Represents the HTTP ORDERPATCH method (WebDAV).
 156    /// </summary>
 157    OrderPatch = 1 << 30
 158}
 159
 160/// <summary>
 161/// Extension methods for the <see cref="HttpVerb"/> enum.
 162/// </summary>
 163public static class HttpVerbExtensions
 164{
 165    /// <summary>
 166    /// Convert the verb enum to its uppercase HTTP method string.
 167    /// </summary>
 112168    public static string ToMethodString(this HttpVerb v) => v.ToString().ToUpperInvariant();
 169
 170    /// <summary>
 171    /// Convert a HTTP method string to its corresponding HttpVerb enum value.
 172    /// </summary>
 173    /// <param name="method">The HTTP method string (case-insensitive).</param>
 174    /// <returns>The corresponding HttpVerb enum value.</returns>
 175    /// <exception cref="ArgumentException">Thrown when the method string is not recognized.</exception>
 176    public static HttpVerb FromMethodString(string method)
 177    {
 147178        if (string.IsNullOrWhiteSpace(method))
 179        {
 2180            throw new ArgumentException("Method cannot be null or whitespace.", nameof(method));
 181        }
 182
 183        // Handle special cases where enum names don't match HTTP method strings
 145184        var normalizedMethod = method.Trim().ToUpperInvariant() switch
 145185        {
 3186            "PROPFIND" => "PropFind",
 2187            "PROPPATCH" => "PropPatch",
 2188            "MKCOL" => "MkCol",
 3189            "VERSION-CONTROL" => "VersionControl",
 3190            "MKWORKSPACE" => "MkWorkspace",
 2191            "ORDERPATCH" => "OrderPatch",
 130192            _ => method.Trim()
 145193        };
 194
 145195        return Enum.TryParse<HttpVerb>(normalizedMethod, true, out var result)
 145196            ? result
 145197            : throw new ArgumentException($"Unknown HTTP method: {method}", nameof(method));
 198    }
 199
 200    /// <summary>
 201    /// Try to convert a HTTP method string to its corresponding HttpVerb enum value.
 202    /// </summary>
 203    /// <param name="method">The HTTP method string (case-insensitive).</param>
 204    /// <param name="verb">When this method returns, contains the HttpVerb value if conversion succeeded, or default val
 205    /// <returns>true if the conversion succeeded; otherwise, false.</returns>
 206    public static bool TryFromMethodString(string method, out HttpVerb verb)
 207    {
 10208        verb = default;
 209
 10210        if (string.IsNullOrWhiteSpace(method))
 211        {
 0212            return false;
 213        }
 214
 215        try
 216        {
 10217            verb = FromMethodString(method);
 8218            return true;
 219        }
 2220        catch (ArgumentException)
 221        {
 2222            return false;
 223        }
 10224    }
 225}