< Summary

Class:Azure.HttpRange
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\HttpRange.cs
Covered lines:16
Uncovered lines:2
Coverable lines:18
Total lines:102
Line coverage:88.8% (16 of 18)
Covered branches:12
Total branches:14
Branch coverage:85.7% (12 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Offset()-100%100%
get_Length()-100%100%
.ctor(...)-100%100%
ToString()-100%100%
op_Equality(...)-100%100%
op_Inequality(...)-100%100%
Equals(...)-100%100%
Equals(...)-0%0%
GetHashCode()-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.ComponentModel;
 6using System.Globalization;
 7using Azure.Core;
 8
 9namespace Azure
 10{
 11    /// <summary>
 12    /// Defines a range of bytes within an HTTP resource, starting at an offset and
 13    /// ending at offset+count-1 inclusively.
 14    /// </summary>
 15    public readonly struct HttpRange : IEquatable<HttpRange>
 16    {
 17        // We only support using the "bytes" unit.
 18        private const string Unit = "bytes";
 19
 20        /// <summary>
 21        /// Gets the starting offset of the <see cref="HttpRange"/>.
 22        /// </summary>
 5223        public long Offset { get; }
 24
 25        /// <summary>
 26        /// Gets the size of the <see cref="HttpRange"/>.  null means the range
 27        /// extends all the way to the end.
 28        /// </summary>
 4229        public long? Length { get; }
 30
 31        /// <summary>
 32        /// Creates an instance of HttpRange.
 33        /// </summary>
 34        /// <param name="offset">The starting offset of the <see cref="HttpRange"/>. Defaults to 0.</param>
 35        /// <param name="length">The length of the range. null means to the end.</param>
 36        public HttpRange(long offset = 0, long? length = default)
 37        {
 2638            if (offset < 0)
 239                throw new ArgumentOutOfRangeException(nameof(offset));
 2440            if (length.HasValue && length <= 0)
 441                throw new ArgumentOutOfRangeException(nameof(length));
 42
 2043            Offset = offset;
 2044            Length = length;
 2045        }
 46
 47        /// <summary>
 48        /// Converts the specified range to a string.
 49        /// </summary>
 50        /// <returns>String representation of the range.</returns>
 51        /// <remarks>For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/specifying-the-
 52        public override string ToString()
 53        {
 54            // No additional validation by design. API can validate parameter by case, and use this method.
 1055            var endRange = "";
 1056            if (Length.HasValue && Length != 0)
 57            {
 658                endRange = (Offset + Length.Value - 1).ToString(CultureInfo.InvariantCulture);
 59            }
 60
 1061            return FormattableString.Invariant($"{Unit}={Offset}-{endRange}");
 62        }
 63
 64        /// <summary>
 65        /// Check if two <see cref="HttpRange"/> instances are equal.
 66        /// </summary>
 67        /// <param name="left">The first instance to compare.</param>
 68        /// <param name="right">The second instance to compare.</param>
 69        /// <returns>True if they're equal, false otherwise.</returns>
 1670        public static bool operator ==(HttpRange left, HttpRange right) => left.Equals(right);
 71
 72        /// <summary>
 73        /// Check if two <see cref="HttpRange"/> instances are not equal.
 74        /// </summary>
 75        /// <param name="left">The first instance to compare.</param>
 76        /// <param name="right">The second instance to compare.</param>
 77        /// <returns>True if they're not equal, false otherwise.</returns>
 878        public static bool operator !=(HttpRange left, HttpRange right) => !(left == right);
 79
 80        /// <summary>
 81        /// Check if two <see cref="HttpRange"/> instances are equal.
 82        /// </summary>
 83        /// <param name="other">The instance to compare to.</param>
 84        /// <returns>True if they're equal, false otherwise.</returns>
 1885        public bool Equals(HttpRange other) => Offset == other.Offset && Length == other.Length;
 86
 87        /// <summary>
 88        /// Check if two <see cref="HttpRange"/> instances are equal.
 89        /// </summary>
 90        /// <param name="obj">The instance to compare to.</param>
 91        /// <returns>True if they're equal, false otherwise.</returns>
 92        [EditorBrowsable(EditorBrowsableState.Never)]
 093        public override bool Equals(object? obj) => obj is HttpRange other && Equals(other);
 94
 95        /// <summary>
 96        /// Get a hash code for the <see cref="HttpRange"/>.
 97        /// </summary>
 98        /// <returns>Hash code for the <see cref="HttpRange"/>.</returns>
 99        [EditorBrowsable(EditorBrowsableState.Never)]
 0100        public override int GetHashCode() => HashCodeBuilder.Combine(Offset, Length);
 101    }
 102}