< Summary

Information
Class: NanoRoute.HttpMethodExtensions
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Public/Extensions/HttpMethodExtensions.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 65
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

Metrics

MethodBlocks covered Blocks not covered
HttpMethodExtensions()210
For(...)70

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Public/Extensions/HttpMethodExtensions.cs

#LineLine coverage
 1/********************************************************************************
 2* HttpMethodExtensions.cs                                                       *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Collections.Frozen;
 8using System.Collections.Generic;
 9using System.Diagnostics;
 10using System.Net.Http;
 11
 12namespace NanoRoute
 13{
 14    using Internals;
 15
 16    /// <summary>
 17    /// <see cref="HttpMethod"/> helpers.
 18    /// </summary>
 19    /// <example>
 20    /// <code>
 21    /// HttpMethod method = HttpMethod.For("PATCH");
 22    /// </code>
 23    /// </example>
 24    public static class HttpMethodExtensions
 25    {
 26        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 227        private static readonly FrozenDictionary<string, HttpMethod> s_httpMethods = new Dictionary<string, HttpMethod>(
 228        {
 229            ["DELETE"] = HttpMethod.Delete,
 230            ["GET"] = HttpMethod.Get,
 231            ["HEAD"] = HttpMethod.Head,
 232            ["OPTIONS"] = HttpMethod.Options,
 233#if NETSTANDARD2_0
 234            ["PATCH"] = new HttpMethod("PATCH"),
 235#else
 236            ["PATCH"] = HttpMethod.Patch,
 237#endif
 238            ["POST"] = HttpMethod.Post,
 239            ["PUT"] = HttpMethod.Put,
 240            ["TRACE"] = HttpMethod.Trace
 241        }.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase);
 42
 43        extension(HttpMethod)
 44        {
 45            /// <summary>
 46            /// Returns the shared <see cref="HttpMethod"/> instance for a known method name, or creates one for a custo
 47            /// </summary>
 48            /// <param name="method">The HTTP method name.</param>
 49            /// <returns>The matching <see cref="HttpMethod"/>.</returns>
 50            /// <exception cref="ArgumentNullException">Thrown when <paramref name="method"/> is <see langword="null"/>.
 51            /// <exception cref="ArgumentException">Thrown when <paramref name="method"/> is empty or whitespace.</excep
 52            /// <exception cref="FormatException">Thrown when <paramref name="method"/> is not a valid HTTP method token
 53            /// <example>
 54            /// <code>
 55            /// HttpMethod method = HttpMethod.For("GET");
 56            /// </code>
 57            /// </example>
 58            public static HttpMethod For(string method)
 259            {
 260                Ensure.NotNull(method);
 261                return s_httpMethods.TryGetValue(method, out HttpMethod? httpMethod) ? httpMethod : new HttpMethod(metho
 62            }
 63        }
 64    }
 65}

Methods/Properties

HttpMethodExtensions()
For(string)