< Summary

Class:Azure.ResourceManager.Resources.SubscriptionsRestOperations
Assembly:Azure.ResourceManager.Resources
File(s):C:\Git\azure-sdk-for-net\sdk\resources\Azure.ResourceManager.Resources\src\Generated\SubscriptionsRestOperations.cs
Covered lines:94
Uncovered lines:50
Coverable lines:144
Total lines:344
Line coverage:65.2% (94 of 144)
Covered branches:17
Total branches:46
Branch coverage:36.9% (17 of 46)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%50%
CreateListLocationsRequest(...)-100%100%
ListLocationsAsync()-76.92%50%
ListLocations(...)-76.92%50%
CreateGetRequest(...)-100%100%
GetAsync()-76.92%50%
Get(...)-76.92%50%
CreateListRequest()-100%100%
ListAsync()-81.82%50%
List(...)-81.82%50%
CreateListNextPageRequest(...)-0%100%
ListNextPageAsync()-0%0%
ListNextPage(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\resources\Azure.ResourceManager.Resources\src\Generated\SubscriptionsRestOperations.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.Resources.Models;
 16
 17namespace Azure.ResourceManager.Resources
 18{
 19    internal partial class SubscriptionsRestOperations
 20    {
 21        private Uri endpoint;
 22        private ClientDiagnostics _clientDiagnostics;
 23        private HttpPipeline _pipeline;
 24
 25        /// <summary> Initializes a new instance of SubscriptionsRestOperations. </summary>
 26        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 27        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 28        /// <param name="endpoint"> server parameter. </param>
 26829        public SubscriptionsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = nu
 30        {
 26831            endpoint ??= new Uri("https://management.azure.com");
 32
 26833            this.endpoint = endpoint;
 26834            _clientDiagnostics = clientDiagnostics;
 26835            _pipeline = pipeline;
 26836        }
 37
 38        internal Core.HttpMessage CreateListLocationsRequest(string subscriptionId)
 39        {
 440            var message = _pipeline.CreateMessage();
 441            var request = message.Request;
 442            request.Method = RequestMethod.Get;
 443            var uri = new RawRequestUriBuilder();
 444            uri.Reset(endpoint);
 445            uri.AppendPath("/subscriptions/", false);
 446            uri.AppendPath(subscriptionId, true);
 447            uri.AppendPath("/locations", false);
 448            uri.AppendQuery("api-version", "2019-11-01", true);
 449            request.Uri = uri;
 450            return message;
 51        }
 52
 53        /// <summary> This operation provides all the locations that are available for resource providers; however, each
 54        /// <param name="subscriptionId"> The ID of the target subscription. </param>
 55        /// <param name="cancellationToken"> The cancellation token to use. </param>
 56        public async Task<Response<LocationListResult>> ListLocationsAsync(string subscriptionId, CancellationToken canc
 57        {
 258            if (subscriptionId == null)
 59            {
 060                throw new ArgumentNullException(nameof(subscriptionId));
 61            }
 62
 263            using var message = CreateListLocationsRequest(subscriptionId);
 264            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 265            switch (message.Response.Status)
 66            {
 67                case 200:
 68                    {
 269                        LocationListResult value = default;
 270                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 271                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 72                        {
 073                            value = null;
 74                        }
 75                        else
 76                        {
 277                            value = LocationListResult.DeserializeLocationListResult(document.RootElement);
 78                        }
 279                        return Response.FromValue(value, message.Response);
 80                    }
 81                default:
 082                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 83            }
 284        }
 85
 86        /// <summary> This operation provides all the locations that are available for resource providers; however, each
 87        /// <param name="subscriptionId"> The ID of the target subscription. </param>
 88        /// <param name="cancellationToken"> The cancellation token to use. </param>
 89        public Response<LocationListResult> ListLocations(string subscriptionId, CancellationToken cancellationToken = d
 90        {
 291            if (subscriptionId == null)
 92            {
 093                throw new ArgumentNullException(nameof(subscriptionId));
 94            }
 95
 296            using var message = CreateListLocationsRequest(subscriptionId);
 297            _pipeline.Send(message, cancellationToken);
 298            switch (message.Response.Status)
 99            {
 100                case 200:
 101                    {
 2102                        LocationListResult value = default;
 2103                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2104                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 105                        {
 0106                            value = null;
 107                        }
 108                        else
 109                        {
 2110                            value = LocationListResult.DeserializeLocationListResult(document.RootElement);
 111                        }
 2112                        return Response.FromValue(value, message.Response);
 113                    }
 114                default:
 0115                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 116            }
 2117        }
 118
 119        internal Core.HttpMessage CreateGetRequest(string subscriptionId)
 120        {
 8121            var message = _pipeline.CreateMessage();
 8122            var request = message.Request;
 8123            request.Method = RequestMethod.Get;
 8124            var uri = new RawRequestUriBuilder();
 8125            uri.Reset(endpoint);
 8126            uri.AppendPath("/subscriptions/", false);
 8127            uri.AppendPath(subscriptionId, true);
 8128            uri.AppendQuery("api-version", "2019-11-01", true);
 8129            request.Uri = uri;
 8130            return message;
 131        }
 132
 133        /// <summary> Gets details about a specified subscription. </summary>
 134        /// <param name="subscriptionId"> The ID of the target subscription. </param>
 135        /// <param name="cancellationToken"> The cancellation token to use. </param>
 136        public async Task<Response<Subscription>> GetAsync(string subscriptionId, CancellationToken cancellationToken = 
 137        {
 4138            if (subscriptionId == null)
 139            {
 0140                throw new ArgumentNullException(nameof(subscriptionId));
 141            }
 142
 4143            using var message = CreateGetRequest(subscriptionId);
 4144            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4145            switch (message.Response.Status)
 146            {
 147                case 200:
 148                    {
 4149                        Subscription value = default;
 4150                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4151                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 152                        {
 0153                            value = null;
 154                        }
 155                        else
 156                        {
 4157                            value = Subscription.DeserializeSubscription(document.RootElement);
 158                        }
 4159                        return Response.FromValue(value, message.Response);
 160                    }
 161                default:
 0162                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 163            }
 4164        }
 165
 166        /// <summary> Gets details about a specified subscription. </summary>
 167        /// <param name="subscriptionId"> The ID of the target subscription. </param>
 168        /// <param name="cancellationToken"> The cancellation token to use. </param>
 169        public Response<Subscription> Get(string subscriptionId, CancellationToken cancellationToken = default)
 170        {
 4171            if (subscriptionId == null)
 172            {
 0173                throw new ArgumentNullException(nameof(subscriptionId));
 174            }
 175
 4176            using var message = CreateGetRequest(subscriptionId);
 4177            _pipeline.Send(message, cancellationToken);
 4178            switch (message.Response.Status)
 179            {
 180                case 200:
 181                    {
 4182                        Subscription value = default;
 4183                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4184                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 185                        {
 0186                            value = null;
 187                        }
 188                        else
 189                        {
 4190                            value = Subscription.DeserializeSubscription(document.RootElement);
 191                        }
 4192                        return Response.FromValue(value, message.Response);
 193                    }
 194                default:
 0195                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 196            }
 4197        }
 198
 199        internal Core.HttpMessage CreateListRequest()
 200        {
 8201            var message = _pipeline.CreateMessage();
 8202            var request = message.Request;
 8203            request.Method = RequestMethod.Get;
 8204            var uri = new RawRequestUriBuilder();
 8205            uri.Reset(endpoint);
 8206            uri.AppendPath("/subscriptions", false);
 8207            uri.AppendQuery("api-version", "2019-11-01", true);
 8208            request.Uri = uri;
 8209            return message;
 210        }
 211
 212        /// <summary> Gets all subscriptions for a tenant. </summary>
 213        /// <param name="cancellationToken"> The cancellation token to use. </param>
 214        public async Task<Response<SubscriptionListResult>> ListAsync(CancellationToken cancellationToken = default)
 215        {
 4216            using var message = CreateListRequest();
 4217            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4218            switch (message.Response.Status)
 219            {
 220                case 200:
 221                    {
 4222                        SubscriptionListResult value = default;
 4223                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4224                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 225                        {
 0226                            value = null;
 227                        }
 228                        else
 229                        {
 4230                            value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement);
 231                        }
 4232                        return Response.FromValue(value, message.Response);
 233                    }
 234                default:
 0235                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 236            }
 4237        }
 238
 239        /// <summary> Gets all subscriptions for a tenant. </summary>
 240        /// <param name="cancellationToken"> The cancellation token to use. </param>
 241        public Response<SubscriptionListResult> List(CancellationToken cancellationToken = default)
 242        {
 4243            using var message = CreateListRequest();
 4244            _pipeline.Send(message, cancellationToken);
 4245            switch (message.Response.Status)
 246            {
 247                case 200:
 248                    {
 4249                        SubscriptionListResult value = default;
 4250                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4251                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 252                        {
 0253                            value = null;
 254                        }
 255                        else
 256                        {
 4257                            value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement);
 258                        }
 4259                        return Response.FromValue(value, message.Response);
 260                    }
 261                default:
 0262                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 263            }
 4264        }
 265
 266        internal Core.HttpMessage CreateListNextPageRequest(string nextLink)
 267        {
 0268            var message = _pipeline.CreateMessage();
 0269            var request = message.Request;
 0270            request.Method = RequestMethod.Get;
 0271            var uri = new RawRequestUriBuilder();
 0272            uri.Reset(endpoint);
 0273            uri.AppendRawNextLink(nextLink, false);
 0274            request.Uri = uri;
 0275            return message;
 276        }
 277
 278        /// <summary> Gets all subscriptions for a tenant. </summary>
 279        /// <param name="nextLink"> The URL to the next page of results. </param>
 280        /// <param name="cancellationToken"> The cancellation token to use. </param>
 281        public async Task<Response<SubscriptionListResult>> ListNextPageAsync(string nextLink, CancellationToken cancell
 282        {
 0283            if (nextLink == null)
 284            {
 0285                throw new ArgumentNullException(nameof(nextLink));
 286            }
 287
 0288            using var message = CreateListNextPageRequest(nextLink);
 0289            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0290            switch (message.Response.Status)
 291            {
 292                case 200:
 293                    {
 0294                        SubscriptionListResult value = default;
 0295                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0296                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 297                        {
 0298                            value = null;
 299                        }
 300                        else
 301                        {
 0302                            value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement);
 303                        }
 0304                        return Response.FromValue(value, message.Response);
 305                    }
 306                default:
 0307                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 308            }
 0309        }
 310
 311        /// <summary> Gets all subscriptions for a tenant. </summary>
 312        /// <param name="nextLink"> The URL to the next page of results. </param>
 313        /// <param name="cancellationToken"> The cancellation token to use. </param>
 314        public Response<SubscriptionListResult> ListNextPage(string nextLink, CancellationToken cancellationToken = defa
 315        {
 0316            if (nextLink == null)
 317            {
 0318                throw new ArgumentNullException(nameof(nextLink));
 319            }
 320
 0321            using var message = CreateListNextPageRequest(nextLink);
 0322            _pipeline.Send(message, cancellationToken);
 0323            switch (message.Response.Status)
 324            {
 325                case 200:
 326                    {
 0327                        SubscriptionListResult value = default;
 0328                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0329                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 330                        {
 0331                            value = null;
 332                        }
 333                        else
 334                        {
 0335                            value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement);
 336                        }
 0337                        return Response.FromValue(value, message.Response);
 338                    }
 339                default:
 0340                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 341            }
 0342        }
 343    }
 344}