< Summary

Class:Azure.ResourceManager.Storage.ObjectReplicationPoliciesRestOperations
Assembly:Azure.ResourceManager.Storage
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\ObjectReplicationPoliciesRestOperations.cs
Covered lines:165
Uncovered lines:40
Coverable lines:205
Total lines:458
Line coverage:80.4% (165 of 205)
Covered branches:43
Total branches:86
Branch coverage:50% (43 of 86)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-83.33%50%
CreateListRequest(...)-100%100%
ListAsync()-73.33%50%
List(...)-73.33%50%
CreateGetRequest(...)-100%100%
GetAsync()-70.59%50%
Get(...)-70.59%50%
CreateCreateOrUpdateRequest(...)-100%100%
CreateOrUpdateAsync()-68.42%50%
CreateOrUpdate(...)-68.42%50%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-66.67%50%
Delete(...)-66.67%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.ResourceManager.Storage\src\Generated\ObjectReplicationPoliciesRestOperations.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 ObjectReplicationPoliciesRestOperations
 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 ObjectReplicationPoliciesRestOperations. </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 ObjectReplicationPoliciesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, strin
 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 CreateListRequest(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("/objectReplicationPolicies", false);
 867            uri.AppendQuery("api-version", apiVersion, true);
 868            request.Uri = uri;
 869            return message;
 70        }
 71
 72        /// <summary> List the object replication policies associated with the storage account. </summary>
 73        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 74        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 75        /// <param name="cancellationToken"> The cancellation token to use. </param>
 76        public async Task<Response<ObjectReplicationPolicies>> ListAsync(string resourceGroupName, string accountName, C
 77        {
 478            if (resourceGroupName == null)
 79            {
 080                throw new ArgumentNullException(nameof(resourceGroupName));
 81            }
 482            if (accountName == null)
 83            {
 084                throw new ArgumentNullException(nameof(accountName));
 85            }
 86
 487            using var message = CreateListRequest(resourceGroupName, accountName);
 488            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 489            switch (message.Response.Status)
 90            {
 91                case 200:
 92                    {
 493                        ObjectReplicationPolicies value = default;
 494                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 495                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 96                        {
 097                            value = null;
 98                        }
 99                        else
 100                        {
 4101                            value = ObjectReplicationPolicies.DeserializeObjectReplicationPolicies(document.RootElement)
 102                        }
 4103                        return Response.FromValue(value, message.Response);
 104                    }
 105                default:
 0106                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 107            }
 4108        }
 109
 110        /// <summary> List the object replication policies associated with the storage account. </summary>
 111        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 112        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 113        /// <param name="cancellationToken"> The cancellation token to use. </param>
 114        public Response<ObjectReplicationPolicies> List(string resourceGroupName, string accountName, CancellationToken 
 115        {
 4116            if (resourceGroupName == null)
 117            {
 0118                throw new ArgumentNullException(nameof(resourceGroupName));
 119            }
 4120            if (accountName == null)
 121            {
 0122                throw new ArgumentNullException(nameof(accountName));
 123            }
 124
 4125            using var message = CreateListRequest(resourceGroupName, accountName);
 4126            _pipeline.Send(message, cancellationToken);
 4127            switch (message.Response.Status)
 128            {
 129                case 200:
 130                    {
 4131                        ObjectReplicationPolicies value = default;
 4132                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4133                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 134                        {
 0135                            value = null;
 136                        }
 137                        else
 138                        {
 4139                            value = ObjectReplicationPolicies.DeserializeObjectReplicationPolicies(document.RootElement)
 140                        }
 4141                        return Response.FromValue(value, message.Response);
 142                    }
 143                default:
 0144                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 145            }
 4146        }
 147
 148        internal HttpMessage CreateGetRequest(string resourceGroupName, string accountName, string objectReplicationPoli
 149        {
 8150            var message = _pipeline.CreateMessage();
 8151            var request = message.Request;
 8152            request.Method = RequestMethod.Get;
 8153            var uri = new RawRequestUriBuilder();
 8154            uri.Reset(endpoint);
 8155            uri.AppendPath("/subscriptions/", false);
 8156            uri.AppendPath(subscriptionId, true);
 8157            uri.AppendPath("/resourceGroups/", false);
 8158            uri.AppendPath(resourceGroupName, true);
 8159            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 8160            uri.AppendPath(accountName, true);
 8161            uri.AppendPath("/objectReplicationPolicies/", false);
 8162            uri.AppendPath(objectReplicationPolicyId, true);
 8163            uri.AppendQuery("api-version", apiVersion, true);
 8164            request.Uri = uri;
 8165            return message;
 166        }
 167
 168        /// <summary> Get the object replication policy of the storage account by policy ID. </summary>
 169        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 170        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 171        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 172        /// <param name="cancellationToken"> The cancellation token to use. </param>
 173        public async Task<Response<ObjectReplicationPolicy>> GetAsync(string resourceGroupName, string accountName, stri
 174        {
 4175            if (resourceGroupName == null)
 176            {
 0177                throw new ArgumentNullException(nameof(resourceGroupName));
 178            }
 4179            if (accountName == null)
 180            {
 0181                throw new ArgumentNullException(nameof(accountName));
 182            }
 4183            if (objectReplicationPolicyId == null)
 184            {
 0185                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 186            }
 187
 4188            using var message = CreateGetRequest(resourceGroupName, accountName, objectReplicationPolicyId);
 4189            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4190            switch (message.Response.Status)
 191            {
 192                case 200:
 193                    {
 4194                        ObjectReplicationPolicy value = default;
 4195                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4196                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 197                        {
 0198                            value = null;
 199                        }
 200                        else
 201                        {
 4202                            value = ObjectReplicationPolicy.DeserializeObjectReplicationPolicy(document.RootElement);
 203                        }
 4204                        return Response.FromValue(value, message.Response);
 205                    }
 206                default:
 0207                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 208            }
 4209        }
 210
 211        /// <summary> Get the object replication policy of the storage account by policy ID. </summary>
 212        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 213        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 214        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 215        /// <param name="cancellationToken"> The cancellation token to use. </param>
 216        public Response<ObjectReplicationPolicy> Get(string resourceGroupName, string accountName, string objectReplicat
 217        {
 4218            if (resourceGroupName == null)
 219            {
 0220                throw new ArgumentNullException(nameof(resourceGroupName));
 221            }
 4222            if (accountName == null)
 223            {
 0224                throw new ArgumentNullException(nameof(accountName));
 225            }
 4226            if (objectReplicationPolicyId == null)
 227            {
 0228                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 229            }
 230
 4231            using var message = CreateGetRequest(resourceGroupName, accountName, objectReplicationPolicyId);
 4232            _pipeline.Send(message, cancellationToken);
 4233            switch (message.Response.Status)
 234            {
 235                case 200:
 236                    {
 4237                        ObjectReplicationPolicy value = default;
 4238                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4239                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 240                        {
 0241                            value = null;
 242                        }
 243                        else
 244                        {
 4245                            value = ObjectReplicationPolicy.DeserializeObjectReplicationPolicy(document.RootElement);
 246                        }
 4247                        return Response.FromValue(value, message.Response);
 248                    }
 249                default:
 0250                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 251            }
 4252        }
 253
 254        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string accountName, string objectRepl
 255        {
 8256            var message = _pipeline.CreateMessage();
 8257            var request = message.Request;
 8258            request.Method = RequestMethod.Put;
 8259            var uri = new RawRequestUriBuilder();
 8260            uri.Reset(endpoint);
 8261            uri.AppendPath("/subscriptions/", false);
 8262            uri.AppendPath(subscriptionId, true);
 8263            uri.AppendPath("/resourceGroups/", false);
 8264            uri.AppendPath(resourceGroupName, true);
 8265            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 8266            uri.AppendPath(accountName, true);
 8267            uri.AppendPath("/objectReplicationPolicies/", false);
 8268            uri.AppendPath(objectReplicationPolicyId, true);
 8269            uri.AppendQuery("api-version", apiVersion, true);
 8270            request.Uri = uri;
 8271            request.Headers.Add("Content-Type", "application/json");
 8272            var content = new Utf8JsonRequestContent();
 8273            content.JsonWriter.WriteObjectValue(properties);
 8274            request.Content = content;
 8275            return message;
 276        }
 277
 278        /// <summary> Create or update the object replication policy of the storage account. </summary>
 279        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 280        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 281        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 282        /// <param name="properties"> The object replication policy set to a storage account. A unique policy ID will be
 283        /// <param name="cancellationToken"> The cancellation token to use. </param>
 284        public async Task<Response<ObjectReplicationPolicy>> CreateOrUpdateAsync(string resourceGroupName, string accoun
 285        {
 4286            if (resourceGroupName == null)
 287            {
 0288                throw new ArgumentNullException(nameof(resourceGroupName));
 289            }
 4290            if (accountName == null)
 291            {
 0292                throw new ArgumentNullException(nameof(accountName));
 293            }
 4294            if (objectReplicationPolicyId == null)
 295            {
 0296                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 297            }
 4298            if (properties == null)
 299            {
 0300                throw new ArgumentNullException(nameof(properties));
 301            }
 302
 4303            using var message = CreateCreateOrUpdateRequest(resourceGroupName, accountName, objectReplicationPolicyId, p
 4304            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4305            switch (message.Response.Status)
 306            {
 307                case 200:
 308                    {
 4309                        ObjectReplicationPolicy value = default;
 4310                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4311                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 312                        {
 0313                            value = null;
 314                        }
 315                        else
 316                        {
 4317                            value = ObjectReplicationPolicy.DeserializeObjectReplicationPolicy(document.RootElement);
 318                        }
 4319                        return Response.FromValue(value, message.Response);
 320                    }
 321                default:
 0322                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 323            }
 4324        }
 325
 326        /// <summary> Create or update the object replication policy of the storage account. </summary>
 327        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 328        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 329        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 330        /// <param name="properties"> The object replication policy set to a storage account. A unique policy ID will be
 331        /// <param name="cancellationToken"> The cancellation token to use. </param>
 332        public Response<ObjectReplicationPolicy> CreateOrUpdate(string resourceGroupName, string accountName, string obj
 333        {
 4334            if (resourceGroupName == null)
 335            {
 0336                throw new ArgumentNullException(nameof(resourceGroupName));
 337            }
 4338            if (accountName == null)
 339            {
 0340                throw new ArgumentNullException(nameof(accountName));
 341            }
 4342            if (objectReplicationPolicyId == null)
 343            {
 0344                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 345            }
 4346            if (properties == null)
 347            {
 0348                throw new ArgumentNullException(nameof(properties));
 349            }
 350
 4351            using var message = CreateCreateOrUpdateRequest(resourceGroupName, accountName, objectReplicationPolicyId, p
 4352            _pipeline.Send(message, cancellationToken);
 4353            switch (message.Response.Status)
 354            {
 355                case 200:
 356                    {
 4357                        ObjectReplicationPolicy value = default;
 4358                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4359                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 360                        {
 0361                            value = null;
 362                        }
 363                        else
 364                        {
 4365                            value = ObjectReplicationPolicy.DeserializeObjectReplicationPolicy(document.RootElement);
 366                        }
 4367                        return Response.FromValue(value, message.Response);
 368                    }
 369                default:
 0370                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 371            }
 4372        }
 373
 374        internal HttpMessage CreateDeleteRequest(string resourceGroupName, string accountName, string objectReplicationP
 375        {
 8376            var message = _pipeline.CreateMessage();
 8377            var request = message.Request;
 8378            request.Method = RequestMethod.Delete;
 8379            var uri = new RawRequestUriBuilder();
 8380            uri.Reset(endpoint);
 8381            uri.AppendPath("/subscriptions/", false);
 8382            uri.AppendPath(subscriptionId, true);
 8383            uri.AppendPath("/resourceGroups/", false);
 8384            uri.AppendPath(resourceGroupName, true);
 8385            uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false);
 8386            uri.AppendPath(accountName, true);
 8387            uri.AppendPath("/objectReplicationPolicies/", false);
 8388            uri.AppendPath(objectReplicationPolicyId, true);
 8389            uri.AppendQuery("api-version", apiVersion, true);
 8390            request.Uri = uri;
 8391            return message;
 392        }
 393
 394        /// <summary> Deletes the object replication policy associated with the specified storage account. </summary>
 395        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 396        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 397        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 398        /// <param name="cancellationToken"> The cancellation token to use. </param>
 399        public async Task<Response> DeleteAsync(string resourceGroupName, string accountName, string objectReplicationPo
 400        {
 4401            if (resourceGroupName == null)
 402            {
 0403                throw new ArgumentNullException(nameof(resourceGroupName));
 404            }
 4405            if (accountName == null)
 406            {
 0407                throw new ArgumentNullException(nameof(accountName));
 408            }
 4409            if (objectReplicationPolicyId == null)
 410            {
 0411                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 412            }
 413
 4414            using var message = CreateDeleteRequest(resourceGroupName, accountName, objectReplicationPolicyId);
 4415            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4416            switch (message.Response.Status)
 417            {
 418                case 200:
 419                case 204:
 4420                    return message.Response;
 421                default:
 0422                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 423            }
 4424        }
 425
 426        /// <summary> Deletes the object replication policy associated with the specified storage account. </summary>
 427        /// <param name="resourceGroupName"> The name of the resource group within the user&apos;s subscription. The nam
 428        /// <param name="accountName"> The name of the storage account within the specified resource group. Storage acco
 429        /// <param name="objectReplicationPolicyId"> The ID of object replication policy or &apos;default&apos; if the p
 430        /// <param name="cancellationToken"> The cancellation token to use. </param>
 431        public Response Delete(string resourceGroupName, string accountName, string objectReplicationPolicyId, Cancellat
 432        {
 4433            if (resourceGroupName == null)
 434            {
 0435                throw new ArgumentNullException(nameof(resourceGroupName));
 436            }
 4437            if (accountName == null)
 438            {
 0439                throw new ArgumentNullException(nameof(accountName));
 440            }
 4441            if (objectReplicationPolicyId == null)
 442            {
 0443                throw new ArgumentNullException(nameof(objectReplicationPolicyId));
 444            }
 445
 4446            using var message = CreateDeleteRequest(resourceGroupName, accountName, objectReplicationPolicyId);
 4447            _pipeline.Send(message, cancellationToken);
 4448            switch (message.Response.Status)
 449            {
 450                case 200:
 451                case 204:
 4452                    return message.Response;
 453                default:
 0454                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 455            }
 4456        }
 457    }
 458}