< Summary

Class:Azure.ResourceManager.Storage.UsagesRestOperations
Assembly:Azure.ResourceManager.Storage
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\UsagesRestOperations.cs
Covered lines:43
Uncovered lines:8
Coverable lines:51
Total lines:136
Line coverage:84.3% (43 of 51)
Covered branches:9
Total branches:18
Branch coverage:50% (9 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-83.33%50%
CreateListByLocationRequest(...)-100%100%
ListByLocationAsync()-76.92%50%
ListByLocation(...)-76.92%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\UsagesRestOperations.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.ResourceManager.Storage.Models;
 16
 17namespace Azure.ResourceManager.Storage
 18{
 19    internal partial class UsagesRestOperations
 20    {
 21        private string subscriptionId;
 22        private Uri endpoint;
 23        private string apiVersion;
 24        private ClientDiagnostics _clientDiagnostics;
 25        private HttpPipeline _pipeline;
 26
 27        /// <summary> Initializes a new instance of UsagesRestOperations. </summary>
 28        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 29        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 30        /// <param name="subscriptionId"> The ID of the target subscription. </param>
 31        /// <param name="endpoint"> server parameter. </param>
 32        /// <param name="apiVersion"> Api Version. </param>
 33        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception
 24034        public UsagesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscriptionId, U
 35        {
 24036            if (subscriptionId == null)
 37            {
 038                throw new ArgumentNullException(nameof(subscriptionId));
 39            }
 24040            endpoint ??= new Uri("https://management.azure.com");
 24041            if (apiVersion == null)
 42            {
 043                throw new ArgumentNullException(nameof(apiVersion));
 44            }
 45
 24046            this.subscriptionId = subscriptionId;
 24047            this.endpoint = endpoint;
 24048            this.apiVersion = apiVersion;
 24049            _clientDiagnostics = clientDiagnostics;
 24050            _pipeline = pipeline;
 24051        }
 52
 53        internal HttpMessage CreateListByLocationRequest(string location)
 54        {
 455            var message = _pipeline.CreateMessage();
 456            var request = message.Request;
 457            request.Method = RequestMethod.Get;
 458            var uri = new RawRequestUriBuilder();
 459            uri.Reset(endpoint);
 460            uri.AppendPath("/subscriptions/", false);
 461            uri.AppendPath(subscriptionId, true);
 462            uri.AppendPath("/providers/Microsoft.Storage/locations/", false);
 463            uri.AppendPath(location, true);
 464            uri.AppendPath("/usages", false);
 465            uri.AppendQuery("api-version", apiVersion, true);
 466            request.Uri = uri;
 467            return message;
 68        }
 69
 70        /// <summary> Gets the current usage count and the limit for the resources of the location under the subscriptio
 71        /// <param name="location"> The location of the Azure Storage resource. </param>
 72        /// <param name="cancellationToken"> The cancellation token to use. </param>
 73        public async Task<Response<UsageListResult>> ListByLocationAsync(string location, CancellationToken cancellation
 74        {
 275            if (location == null)
 76            {
 077                throw new ArgumentNullException(nameof(location));
 78            }
 79
 280            using var message = CreateListByLocationRequest(location);
 281            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 282            switch (message.Response.Status)
 83            {
 84                case 200:
 85                    {
 286                        UsageListResult value = default;
 287                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 288                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 89                        {
 090                            value = null;
 91                        }
 92                        else
 93                        {
 294                            value = UsageListResult.DeserializeUsageListResult(document.RootElement);
 95                        }
 296                        return Response.FromValue(value, message.Response);
 97                    }
 98                default:
 099                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 100            }
 2101        }
 102
 103        /// <summary> Gets the current usage count and the limit for the resources of the location under the subscriptio
 104        /// <param name="location"> The location of the Azure Storage resource. </param>
 105        /// <param name="cancellationToken"> The cancellation token to use. </param>
 106        public Response<UsageListResult> ListByLocation(string location, CancellationToken cancellationToken = default)
 107        {
 2108            if (location == null)
 109            {
 0110                throw new ArgumentNullException(nameof(location));
 111            }
 112
 2113            using var message = CreateListByLocationRequest(location);
 2114            _pipeline.Send(message, cancellationToken);
 2115            switch (message.Response.Status)
 116            {
 117                case 200:
 118                    {
 2119                        UsageListResult value = default;
 2120                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2121                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 122                        {
 0123                            value = null;
 124                        }
 125                        else
 126                        {
 2127                            value = UsageListResult.DeserializeUsageListResult(document.RootElement);
 128                        }
 2129                        return Response.FromValue(value, message.Response);
 130                    }
 131                default:
 0132                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 133            }
 2134        }
 135    }
 136}