< Summary

Class:Azure.Core.Http.Multipart.ThrowHelper
Assembly:Azure.Storage.Blobs.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\ThrowHelper.cs
Covered lines:0
Uncovered lines:20
Coverable lines:20
Total lines:112
Line coverage:0% (0 of 20)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ThrowArgumentNullException(...)-0%100%
ThrowArgumentOutOfRangeException(...)-0%100%
ThrowArgumentException(...)-0%100%
ThrowInvalidOperationException(...)-0%100%
ThrowInvalidOperationException(...)-0%100%
GetArgumentNullException(...)-0%100%
GetArgumentOutOfRangeException(...)-0%100%
GetArgumentException(...)-0%100%
GetResourceText(...)-0%0%
GetArgumentName(...)-0%100%
GetResourceName(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\ThrowHelper.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// Copied from https://github.com/aspnet/Extensions/tree/master/src/Primitives/src
 5
 6using System;
 7using System.Diagnostics;
 8
 9#pragma warning disable CA1305  // ToString Locale
 10#pragma warning disable IDE0051 // Private member not used
 11
 12namespace Azure.Core.Http.Multipart
 13{
 14    internal static class ThrowHelper
 15    {
 16        internal static void ThrowArgumentNullException(ExceptionArgument argument)
 17        {
 018            throw new ArgumentNullException(GetArgumentName(argument));
 19        }
 20
 21        internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument)
 22        {
 023            throw new ArgumentOutOfRangeException(GetArgumentName(argument));
 24        }
 25
 26        internal static void ThrowArgumentException(ExceptionResource resource)
 27        {
 028            throw new ArgumentException(GetResourceText(resource));
 29        }
 30
 31        internal static void ThrowInvalidOperationException(ExceptionResource resource)
 32        {
 033            throw new InvalidOperationException(GetResourceText(resource));
 34        }
 35
 36        internal static void ThrowInvalidOperationException(ExceptionResource resource, params object[] args)
 37        {
 038            var message = string.Format(GetResourceText(resource), args);
 39
 040            throw new InvalidOperationException(message);
 41        }
 42
 43        internal static ArgumentNullException GetArgumentNullException(ExceptionArgument argument)
 44        {
 045            return new ArgumentNullException(GetArgumentName(argument));
 46        }
 47
 48        internal static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument)
 49        {
 050            return new ArgumentOutOfRangeException(GetArgumentName(argument));
 51        }
 52
 53        internal static ArgumentException GetArgumentException(ExceptionResource resource)
 54        {
 055            return new ArgumentException(GetResourceText(resource));
 56        }
 57
 58        private static string GetResourceText(ExceptionResource resource)
 59        {
 60            // return Resources.ResourceManager.GetString(GetResourceName(resource), Resources.Culture);
 61            // Hack to avoid including the resx:
 062            return resource switch
 063            {
 064                ExceptionResource.Argument_InvalidOffsetLength => "Offset and length are out of bounds for the string or
 065                ExceptionResource.Argument_InvalidOffsetLengthStringSegment => "Offset and length are out of bounds for 
 066                ExceptionResource.Capacity_CannotChangeAfterWriteStarted => "Cannot change capacity after write started.
 067                ExceptionResource.Capacity_NotEnough => "Not enough capacity to write '{0}' characters, only '{1}' left.
 068                ExceptionResource.Capacity_NotUsedEntirely => "Entire reserved capacity was not used. Capacity: '{0}', w
 069                _ => throw new ArgumentOutOfRangeException(nameof(resource))
 070            };
 71        }
 72
 73        private static string GetArgumentName(ExceptionArgument argument)
 74        {
 75            Debug.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument),
 76                "The enum value is not defined, please check the ExceptionArgument Enum.");
 77
 078            return argument.ToString();
 79        }
 80
 81        private static string GetResourceName(ExceptionResource resource)
 82        {
 83            Debug.Assert(Enum.IsDefined(typeof(ExceptionResource), resource),
 84                "The enum value is not defined, please check the ExceptionResource Enum.");
 85
 086            return resource.ToString();
 87        }
 88    }
 89
 90    internal enum ExceptionArgument
 91    {
 92        buffer,
 93        offset,
 94        length,
 95        text,
 96        start,
 97        count,
 98        index,
 99        value,
 100        capacity,
 101        separators
 102    }
 103
 104    internal enum ExceptionResource
 105    {
 106        Argument_InvalidOffsetLength,
 107        Argument_InvalidOffsetLengthStringSegment,
 108        Capacity_CannotChangeAfterWriteStarted,
 109        Capacity_NotEnough,
 110        Capacity_NotUsedEntirely
 111    }
 112}