< Summary

Class:Azure.ResourceManager.Compute.UsageRestOperations
Assembly:Azure.ResourceManager.Compute
File(s):C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\UsageRestOperations.cs
Covered lines:41
Uncovered lines:45
Coverable lines:86
Total lines:217
Line coverage:47.6% (41 of 86)
Covered branches:8
Total branches:32
Branch coverage:25% (8 of 32)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateListRequest(...)-100%100%
ListAsync()-76.92%50%
List(...)-76.92%50%
CreateListNextPageRequest(...)-0%100%
ListNextPageAsync()-0%0%
ListNextPage(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\UsageRestOperations.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.Compute.Models;
 16
 17namespace Azure.ResourceManager.Compute
 18{
 19    internal partial class UsageRestOperations
 20    {
 21        private string subscriptionId;
 22        private Uri endpoint;
 23        private ClientDiagnostics _clientDiagnostics;
 24        private HttpPipeline _pipeline;
 25
 26        /// <summary> Initializes a new instance of UsageRestOperations. </summary>
 27        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 28        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 29        /// <param name="subscriptionId"> Subscription credentials which uniquely identify Microsoft Azure subscription.
 30        /// <param name="endpoint"> server parameter. </param>
 31        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception
 39632        public UsageRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscriptionId, Ur
 33        {
 39634            if (subscriptionId == null)
 35            {
 036                throw new ArgumentNullException(nameof(subscriptionId));
 37            }
 39638            endpoint ??= new Uri("https://management.azure.com");
 39
 39640            this.subscriptionId = subscriptionId;
 39641            this.endpoint = endpoint;
 39642            _clientDiagnostics = clientDiagnostics;
 39643            _pipeline = pipeline;
 39644        }
 45
 46        internal HttpMessage CreateListRequest(string location)
 47        {
 448            var message = _pipeline.CreateMessage();
 449            var request = message.Request;
 450            request.Method = RequestMethod.Get;
 451            var uri = new RawRequestUriBuilder();
 452            uri.Reset(endpoint);
 453            uri.AppendPath("/subscriptions/", false);
 454            uri.AppendPath(subscriptionId, true);
 455            uri.AppendPath("/providers/Microsoft.Compute/locations/", false);
 456            uri.AppendPath(location, true);
 457            uri.AppendPath("/usages", false);
 458            uri.AppendQuery("api-version", "2019-12-01", true);
 459            request.Uri = uri;
 460            return message;
 61        }
 62
 63        /// <summary> Gets, for the specified location, the current compute resource usage information as well as the li
 64        /// <param name="location"> The location for which resource usage is queried. </param>
 65        /// <param name="cancellationToken"> The cancellation token to use. </param>
 66        public async Task<Response<ListUsagesResult>> ListAsync(string location, CancellationToken cancellationToken = d
 67        {
 268            if (location == null)
 69            {
 070                throw new ArgumentNullException(nameof(location));
 71            }
 72
 273            using var message = CreateListRequest(location);
 274            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 275            switch (message.Response.Status)
 76            {
 77                case 200:
 78                    {
 279                        ListUsagesResult value = default;
 280                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 281                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 82                        {
 083                            value = null;
 84                        }
 85                        else
 86                        {
 287                            value = ListUsagesResult.DeserializeListUsagesResult(document.RootElement);
 88                        }
 289                        return Response.FromValue(value, message.Response);
 90                    }
 91                default:
 092                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 93            }
 294        }
 95
 96        /// <summary> Gets, for the specified location, the current compute resource usage information as well as the li
 97        /// <param name="location"> The location for which resource usage is queried. </param>
 98        /// <param name="cancellationToken"> The cancellation token to use. </param>
 99        public Response<ListUsagesResult> List(string location, CancellationToken cancellationToken = default)
 100        {
 2101            if (location == null)
 102            {
 0103                throw new ArgumentNullException(nameof(location));
 104            }
 105
 2106            using var message = CreateListRequest(location);
 2107            _pipeline.Send(message, cancellationToken);
 2108            switch (message.Response.Status)
 109            {
 110                case 200:
 111                    {
 2112                        ListUsagesResult value = default;
 2113                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2114                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 115                        {
 0116                            value = null;
 117                        }
 118                        else
 119                        {
 2120                            value = ListUsagesResult.DeserializeListUsagesResult(document.RootElement);
 121                        }
 2122                        return Response.FromValue(value, message.Response);
 123                    }
 124                default:
 0125                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 126            }
 2127        }
 128
 129        internal HttpMessage CreateListNextPageRequest(string nextLink, string location)
 130        {
 0131            var message = _pipeline.CreateMessage();
 0132            var request = message.Request;
 0133            request.Method = RequestMethod.Get;
 0134            var uri = new RawRequestUriBuilder();
 0135            uri.Reset(endpoint);
 0136            uri.AppendRawNextLink(nextLink, false);
 0137            request.Uri = uri;
 0138            return message;
 139        }
 140
 141        /// <summary> Gets, for the specified location, the current compute resource usage information as well as the li
 142        /// <param name="nextLink"> The URL to the next page of results. </param>
 143        /// <param name="location"> The location for which resource usage is queried. </param>
 144        /// <param name="cancellationToken"> The cancellation token to use. </param>
 145        public async Task<Response<ListUsagesResult>> ListNextPageAsync(string nextLink, string location, CancellationTo
 146        {
 0147            if (nextLink == null)
 148            {
 0149                throw new ArgumentNullException(nameof(nextLink));
 150            }
 0151            if (location == null)
 152            {
 0153                throw new ArgumentNullException(nameof(location));
 154            }
 155
 0156            using var message = CreateListNextPageRequest(nextLink, location);
 0157            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0158            switch (message.Response.Status)
 159            {
 160                case 200:
 161                    {
 0162                        ListUsagesResult value = default;
 0163                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0164                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 165                        {
 0166                            value = null;
 167                        }
 168                        else
 169                        {
 0170                            value = ListUsagesResult.DeserializeListUsagesResult(document.RootElement);
 171                        }
 0172                        return Response.FromValue(value, message.Response);
 173                    }
 174                default:
 0175                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 176            }
 0177        }
 178
 179        /// <summary> Gets, for the specified location, the current compute resource usage information as well as the li
 180        /// <param name="nextLink"> The URL to the next page of results. </param>
 181        /// <param name="location"> The location for which resource usage is queried. </param>
 182        /// <param name="cancellationToken"> The cancellation token to use. </param>
 183        public Response<ListUsagesResult> ListNextPage(string nextLink, string location, CancellationToken cancellationT
 184        {
 0185            if (nextLink == null)
 186            {
 0187                throw new ArgumentNullException(nameof(nextLink));
 188            }
 0189            if (location == null)
 190            {
 0191                throw new ArgumentNullException(nameof(location));
 192            }
 193
 0194            using var message = CreateListNextPageRequest(nextLink, location);
 0195            _pipeline.Send(message, cancellationToken);
 0196            switch (message.Response.Status)
 197            {
 198                case 200:
 199                    {
 0200                        ListUsagesResult value = default;
 0201                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0202                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 203                        {
 0204                            value = null;
 205                        }
 206                        else
 207                        {
 0208                            value = ListUsagesResult.DeserializeListUsagesResult(document.RootElement);
 209                        }
 0210                        return Response.FromValue(value, message.Response);
 211                    }
 212                default:
 0213                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 214            }
 0215        }
 216    }
 217}