< Summary

Class:Azure.ResourceManager.Storage.ManagementPoliciesRestOperations
Assembly:Azure.ResourceManager.Storage
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\ManagementPoliciesRestOperations.cs
Covered lines:124
Uncovered lines:24
Coverable lines:148
Total lines:333
Line coverage:83.7% (124 of 148)
Covered branches:33
Total branches:58
Branch coverage:56.8% (33 of 58)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-83.33%50%
CreateGetRequest(...)-100%100%
GetAsync()-80%62.5%
Get(...)-80%62.5%
CreateCreateOrUpdateRequest(...)-100%100%
CreateOrUpdateAsync()-70.59%50%
CreateOrUpdate(...)-70.59%50%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-70%62.5%
Delete(...)-70%62.5%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\ManagementPoliciesRestOperations.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 ManagementPoliciesRestOperations
 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 ManagementPoliciesRestOperations. </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 ManagementPoliciesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subsc
 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 CreateGetRequest(string resourceGroupName, string accountName)
 54        {
 855            var message = _pipeline.CreateMessage();
 856            var request = message.Request;
 857            request.Method = RequestMethod.Get;
 858            var uri = new RawRequestUriBuilder();
 859            uri.Reset(endpoint);
 860            uri.AppendPath("/subscriptions/", false);
 861            uri.AppendPath(subscriptionId, true);
 862            uri.AppendPath("/resourceGroups/", false);
 863            uri.AppendPath(resourceGroupName, true);
 864            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 865            uri.AppendPath(accountName, true);
 866            uri.AppendPath("/managementPolicies/", false);
 867            uri.AppendPath("default", true);
 868            uri.AppendQuery("api-version", apiVersion, true);
 869            request.Uri = uri;
 870            return message;
 71        }
 72
 73        /// <summary> Gets the managementpolicy associated with the specified storage account. </summary>
 74        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 75        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 76        /// <param name="cancellationToken"> The cancellation token to use. </param>
 77        public async Task<Response<ManagementPolicy>> GetAsync(string resourceGroupName, string accountName, Cancellatio
 78        {
 479            if (resourceGroupName == null)
 80            {
 081                throw new ArgumentNullException(nameof(resourceGroupName));
 82            }
 483            if (accountName == null)
 84            {
 085                throw new ArgumentNullException(nameof(accountName));
 86            }
 87
 488            using var message = CreateGetRequest(resourceGroupName, accountName);
 489            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 490            switch (message.Response.Status)
 91            {
 92                case 200:
 93                    {
 294                        ManagementPolicy value = default;
 295                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 296                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 97                        {
 098                            value = null;
 99                        }
 100                        else
 101                        {
 2102                            value = ManagementPolicy.DeserializeManagementPolicy(document.RootElement);
 103                        }
 2104                        return Response.FromValue(value, message.Response);
 105                    }
 106                default:
 2107                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 108            }
 2109        }
 110
 111        /// <summary> Gets the managementpolicy associated with the specified storage account. </summary>
 112        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 113        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 114        /// <param name="cancellationToken"> The cancellation token to use. </param>
 115        public Response<ManagementPolicy> Get(string resourceGroupName, string accountName, CancellationToken cancellati
 116        {
 4117            if (resourceGroupName == null)
 118            {
 0119                throw new ArgumentNullException(nameof(resourceGroupName));
 120            }
 4121            if (accountName == null)
 122            {
 0123                throw new ArgumentNullException(nameof(accountName));
 124            }
 125
 4126            using var message = CreateGetRequest(resourceGroupName, accountName);
 4127            _pipeline.Send(message, cancellationToken);
 4128            switch (message.Response.Status)
 129            {
 130                case 200:
 131                    {
 2132                        ManagementPolicy value = default;
 2133                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2134                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 135                        {
 0136                            value = null;
 137                        }
 138                        else
 139                        {
 2140                            value = ManagementPolicy.DeserializeManagementPolicy(document.RootElement);
 141                        }
 2142                        return Response.FromValue(value, message.Response);
 143                    }
 144                default:
 2145                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 146            }
 2147        }
 148
 149        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string accountName, ManagementPolicy 
 150        {
 4151            var message = _pipeline.CreateMessage();
 4152            var request = message.Request;
 4153            request.Method = RequestMethod.Put;
 4154            var uri = new RawRequestUriBuilder();
 4155            uri.Reset(endpoint);
 4156            uri.AppendPath("/subscriptions/", false);
 4157            uri.AppendPath(subscriptionId, true);
 4158            uri.AppendPath("/resourceGroups/", false);
 4159            uri.AppendPath(resourceGroupName, true);
 4160            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 4161            uri.AppendPath(accountName, true);
 4162            uri.AppendPath("/managementPolicies/", false);
 4163            uri.AppendPath("default", true);
 4164            uri.AppendQuery("api-version", apiVersion, true);
 4165            request.Uri = uri;
 4166            request.Headers.Add("Content-Type", "application/json");
 4167            var content = new Utf8JsonRequestContent();
 4168            content.JsonWriter.WriteObjectValue(properties);
 4169            request.Content = content;
 4170            return message;
 171        }
 172
 173        /// <summary> Sets the managementpolicy to the specified storage account. </summary>
 174        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 175        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 176        /// <param name="properties"> The ManagementPolicy set to a storage account. </param>
 177        /// <param name="cancellationToken"> The cancellation token to use. </param>
 178        public async Task<Response<ManagementPolicy>> CreateOrUpdateAsync(string resourceGroupName, string accountName, 
 179        {
 2180            if (resourceGroupName == null)
 181            {
 0182                throw new ArgumentNullException(nameof(resourceGroupName));
 183            }
 2184            if (accountName == null)
 185            {
 0186                throw new ArgumentNullException(nameof(accountName));
 187            }
 2188            if (properties == null)
 189            {
 0190                throw new ArgumentNullException(nameof(properties));
 191            }
 192
 2193            using var message = CreateCreateOrUpdateRequest(resourceGroupName, accountName, properties);
 2194            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2195            switch (message.Response.Status)
 196            {
 197                case 200:
 198                    {
 2199                        ManagementPolicy value = default;
 2200                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2201                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 202                        {
 0203                            value = null;
 204                        }
 205                        else
 206                        {
 2207                            value = ManagementPolicy.DeserializeManagementPolicy(document.RootElement);
 208                        }
 2209                        return Response.FromValue(value, message.Response);
 210                    }
 211                default:
 0212                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 213            }
 2214        }
 215
 216        /// <summary> Sets the managementpolicy to the specified storage account. </summary>
 217        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 218        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 219        /// <param name="properties"> The ManagementPolicy set to a storage account. </param>
 220        /// <param name="cancellationToken"> The cancellation token to use. </param>
 221        public Response<ManagementPolicy> CreateOrUpdate(string resourceGroupName, string accountName, ManagementPolicy 
 222        {
 2223            if (resourceGroupName == null)
 224            {
 0225                throw new ArgumentNullException(nameof(resourceGroupName));
 226            }
 2227            if (accountName == null)
 228            {
 0229                throw new ArgumentNullException(nameof(accountName));
 230            }
 2231            if (properties == null)
 232            {
 0233                throw new ArgumentNullException(nameof(properties));
 234            }
 235
 2236            using var message = CreateCreateOrUpdateRequest(resourceGroupName, accountName, properties);
 2237            _pipeline.Send(message, cancellationToken);
 2238            switch (message.Response.Status)
 239            {
 240                case 200:
 241                    {
 2242                        ManagementPolicy value = default;
 2243                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2244                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 245                        {
 0246                            value = null;
 247                        }
 248                        else
 249                        {
 2250                            value = ManagementPolicy.DeserializeManagementPolicy(document.RootElement);
 251                        }
 2252                        return Response.FromValue(value, message.Response);
 253                    }
 254                default:
 0255                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 256            }
 2257        }
 258
 259        internal HttpMessage CreateDeleteRequest(string resourceGroupName, string accountName)
 260        {
 8261            var message = _pipeline.CreateMessage();
 8262            var request = message.Request;
 8263            request.Method = RequestMethod.Delete;
 8264            var uri = new RawRequestUriBuilder();
 8265            uri.Reset(endpoint);
 8266            uri.AppendPath("/subscriptions/", false);
 8267            uri.AppendPath(subscriptionId, true);
 8268            uri.AppendPath("/resourceGroups/", false);
 8269            uri.AppendPath(resourceGroupName, true);
 8270            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 8271            uri.AppendPath(accountName, true);
 8272            uri.AppendPath("/managementPolicies/", false);
 8273            uri.AppendPath("default", true);
 8274            uri.AppendQuery("api-version", apiVersion, true);
 8275            request.Uri = uri;
 8276            return message;
 277        }
 278
 279        /// <summary> Deletes the managementpolicy associated with the specified storage account. </summary>
 280        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 281        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 282        /// <param name="cancellationToken"> The cancellation token to use. </param>
 283        public async Task<Response> DeleteAsync(string resourceGroupName, string accountName, CancellationToken cancella
 284        {
 4285            if (resourceGroupName == null)
 286            {
 0287                throw new ArgumentNullException(nameof(resourceGroupName));
 288            }
 4289            if (accountName == null)
 290            {
 0291                throw new ArgumentNullException(nameof(accountName));
 292            }
 293
 4294            using var message = CreateDeleteRequest(resourceGroupName, accountName);
 4295            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4296            switch (message.Response.Status)
 297            {
 298                case 200:
 299                case 204:
 4300                    return message.Response;
 301                default:
 0302                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 303            }
 4304        }
 305
 306        /// <summary> Deletes the managementpolicy associated with the specified storage account. </summary>
 307        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 308        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 309        /// <param name="cancellationToken"> The cancellation token to use. </param>
 310        public Response Delete(string resourceGroupName, string accountName, CancellationToken cancellationToken = defau
 311        {
 4312            if (resourceGroupName == null)
 313            {
 0314                throw new ArgumentNullException(nameof(resourceGroupName));
 315            }
 4316            if (accountName == null)
 317            {
 0318                throw new ArgumentNullException(nameof(accountName));
 319            }
 320
 4321            using var message = CreateDeleteRequest(resourceGroupName, accountName);
 4322            _pipeline.Send(message, cancellationToken);
 4323            switch (message.Response.Status)
 324            {
 325                case 200:
 326                case 204:
 4327                    return message.Response;
 328                default:
 0329                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 330            }
 4331        }
 332    }
 333}