< Summary

Class:Azure.Core.RequestMethod
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\RequestMethod.cs
Covered lines:36
Uncovered lines:2
Coverable lines:38
Total lines:164
Line coverage:94.7% (36 of 38)
Covered branches:23
Total branches:26
Branch coverage:88.4% (23 of 26)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Method()-100%100%
get_Get()-100%100%
get_Post()-100%100%
get_Put()-100%100%
get_Patch()-100%100%
get_Delete()-100%100%
get_Head()-100%100%
get_Options()-100%100%
get_Trace()-100%100%
.ctor(...)-100%100%
Parse(...)-100%100%
Equals(...)-100%100%
Equals(...)-0%0%
GetHashCode()-100%50%
op_Equality(...)-0%100%
op_Inequality(...)-100%100%
ToString()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\RequestMethod.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Core
 7{
 8    /// <summary>
 9    /// Represents HTTP methods sent as part of a <see cref="Request"/>.
 10    /// </summary>
 11    public readonly struct RequestMethod : IEquatable<RequestMethod>
 12    {
 13        /// <summary>
 14        /// Gets the HTTP method.
 15        /// </summary>
 314016        public string Method { get; }
 17
 18        /// <summary>
 19        /// Gets <see cref="RequestMethod"/> instance for GET method.
 20        /// </summary>
 353821        public static RequestMethod Get { get; } = new RequestMethod("GET");
 22        /// <summary>
 23        /// Gets <see cref="RequestMethod"/> instance for POST method.
 24        /// </summary>
 49825        public static RequestMethod Post { get; } = new RequestMethod("POST");
 26        /// <summary>
 27        /// Gets <see cref="RequestMethod"/> instance for PUT method.
 28        /// </summary>
 6829        public static RequestMethod Put { get; } = new RequestMethod("PUT");
 30        /// <summary>
 31        /// Gets <see cref="RequestMethod"/> instance for PATCH method.
 32        /// </summary>
 1433        public static RequestMethod Patch { get; } = new RequestMethod("PATCH");
 34        /// <summary>
 35        /// Gets <see cref="RequestMethod"/> instance for DELETE method.
 36        /// </summary>
 9237        public static RequestMethod Delete { get; } = new RequestMethod("DELETE");
 38        /// <summary>
 39        /// Gets <see cref="RequestMethod"/> instance for HEAD method.
 40        /// </summary>
 1841        public static RequestMethod Head { get; } = new RequestMethod("HEAD");
 42        /// <summary>
 43        /// Gets <see cref="RequestMethod"/> instance for OPTIONS method.
 44        /// </summary>
 645        public static RequestMethod Options { get; } = new RequestMethod("OPTIONS");
 46        /// <summary>
 47        /// Gets <see cref="RequestMethod"/> instance for TRACE method.
 48        /// </summary>
 649        public static RequestMethod Trace { get; } = new RequestMethod("TRACE");
 50
 51        /// <summary>
 52        /// Creates an instance of <see cref="RequestMethod"/> with provided method. Method must be all uppercase.
 53        /// Prefer <see cref="Parse"/> if <paramref name="method"/> can be one of predefined method names.
 54        /// </summary>
 55        /// <param name="method">The method to use.</param>
 56        public RequestMethod(string method)
 57        {
 2458            Argument.AssertNotNull(method, nameof(method));
 59
 2460            Method = method.ToUpperInvariant();
 2461        }
 62
 63        /// <summary>
 64        /// Parses string to it's <see cref="RequestMethod"/> representation.
 65        /// </summary>
 66        /// <param name="method">The method string to parse.</param>
 67        public static RequestMethod Parse(string method)
 68        {
 211869            Argument.AssertNotNull(method, nameof(method));
 70
 71            // Fast-path common values
 211872            if (method.Length == 3)
 73            {
 206074                if (string.Equals(method, "GET", StringComparison.OrdinalIgnoreCase))
 75                {
 205076                    return Get;
 77                }
 78
 1079                if (string.Equals(method, "PUT", StringComparison.OrdinalIgnoreCase))
 80                {
 1081                    return Put;
 82                }
 83            }
 5884            else if (method.Length == 4)
 85            {
 1286                if (string.Equals(method, "POST", StringComparison.OrdinalIgnoreCase))
 87                {
 688                    return Post;
 89                }
 690                if (string.Equals(method, "HEAD", StringComparison.OrdinalIgnoreCase))
 91                {
 692                    return Head;
 93                }
 94            }
 95            else
 96            {
 4697                if (string.Equals(method, "PATCH", StringComparison.OrdinalIgnoreCase))
 98                {
 699                    return Patch;
 100                }
 40101                if (string.Equals(method, "DELETE", StringComparison.OrdinalIgnoreCase))
 102                {
 32103                    return Delete;
 104                }
 8105                if (string.Equals(method, "OPTIONS", StringComparison.OrdinalIgnoreCase))
 106                {
 2107                    return Options;
 108                }
 6109                if (string.Equals(method, "TRACE", StringComparison.OrdinalIgnoreCase))
 110                {
 2111                    return Trace;
 112                }
 113            }
 114
 4115            return new RequestMethod(method);
 116        }
 117
 118        /// <inheritdoc />
 119        public bool Equals(RequestMethod other)
 120        {
 102121            return string.Equals(Method, other.Method, StringComparison.Ordinal);
 122        }
 123
 124        /// <inheritdoc />
 125        public override bool Equals(object? obj)
 126        {
 0127            return obj is RequestMethod other && Equals(other);
 128        }
 129
 130        /// <inheritdoc />
 131        public override int GetHashCode()
 132        {
 2133            return Method?.GetHashCode() ?? 0;
 134        }
 135
 136        /// <summary>
 137        /// Compares equality of two <see cref="RequestMethod"/> instances.
 138        /// </summary>
 139        /// <param name="left">The method to compare.</param>
 140        /// <param name="right">The method to compare against.</param>
 141        /// <returns><c>true</c> if <see cref="Method"/> values are equal for <paramref name="left"/> and <paramref name
 142        public static bool operator ==(RequestMethod left, RequestMethod right)
 143        {
 0144            return left.Equals(right);
 145        }
 146
 147        /// <summary>
 148        /// Compares inequality of two <see cref="RequestMethod"/> instances.
 149        /// </summary>
 150        /// <param name="left">The method to compare.</param>
 151        /// <param name="right">The method to compare against.</param>
 152        /// <returns><c>true</c> if <see cref="Method"/> values are equal for <paramref name="left"/> and <paramref name
 153        public static bool operator !=(RequestMethod left, RequestMethod right)
 154        {
 48155            return !left.Equals(right);
 156        }
 157
 158        /// <inheritdoc />
 159        public override string ToString()
 160        {
 2200161            return Method ?? "<null>";
 162        }
 163    }
 164}