< Summary

Class:Azure.ResourceManager.Resources.PolicyDefinitionsRestOperations
Assembly:Azure.ResourceManager.Resources
File(s):C:\Git\azure-sdk-for-net\sdk\resources\Azure.ResourceManager.Resources\src\Generated\PolicyDefinitionsRestOperations.cs
Covered lines:192
Uncovered lines:296
Coverable lines:488
Total lines:1093
Line coverage:39.3% (192 of 488)
Covered branches:42
Total branches:176
Branch coverage:23.8% (42 of 176)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateCreateOrUpdateRequest(...)-100%100%
CreateOrUpdateAsync()-80%62.5%
CreateOrUpdate(...)-80%62.5%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-75%66.67%
Delete(...)-75%66.67%
CreateGetRequest(...)-100%100%
GetAsync()-84.62%66.67%
Get(...)-84.62%66.67%
CreateGetBuiltInRequest(...)-100%100%
GetBuiltInAsync()-76.92%50%
GetBuiltIn(...)-76.92%50%
CreateCreateOrUpdateAtManagementGroupRequest(...)-0%100%
CreateOrUpdateAtManagementGroupAsync()-0%0%
CreateOrUpdateAtManagementGroup(...)-0%0%
CreateDeleteAtManagementGroupRequest(...)-0%100%
DeleteAtManagementGroupAsync()-0%0%
DeleteAtManagementGroup(...)-0%0%
CreateGetAtManagementGroupRequest(...)-0%100%
GetAtManagementGroupAsync()-0%0%
GetAtManagementGroup(...)-0%0%
CreateListRequest()-100%100%
ListAsync()-81.82%50%
List(...)-81.82%50%
CreateListBuiltInRequest()-100%100%
ListBuiltInAsync()-81.82%50%
ListBuiltIn(...)-81.82%50%
CreateListByManagementGroupRequest(...)-0%100%
ListByManagementGroupAsync()-0%0%
ListByManagementGroup(...)-0%0%
CreateListNextPageRequest(...)-0%100%
ListNextPageAsync()-0%0%
ListNextPage(...)-0%0%
CreateListBuiltInNextPageRequest(...)-0%100%
ListBuiltInNextPageAsync()-0%0%
ListBuiltInNextPage(...)-0%0%
CreateListByManagementGroupNextPageRequest(...)-0%100%
ListByManagementGroupNextPageAsync()-0%0%
ListByManagementGroupNextPage(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\resources\Azure.ResourceManager.Resources\src\Generated\PolicyDefinitionsRestOperations.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 PolicyDefinitionsRestOperations
 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 PolicyDefinitionsRestOperations. </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"> The ID of the target subscription. </param>
 30        /// <param name="endpoint"> server parameter. </param>
 31        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception
 25632        public PolicyDefinitionsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscr
 33        {
 25634            if (subscriptionId == null)
 35            {
 036                throw new ArgumentNullException(nameof(subscriptionId));
 37            }
 25638            endpoint ??= new Uri("https://management.azure.com");
 39
 25640            this.subscriptionId = subscriptionId;
 25641            this.endpoint = endpoint;
 25642            _clientDiagnostics = clientDiagnostics;
 25643            _pipeline = pipeline;
 25644        }
 45
 46        internal Core.HttpMessage CreateCreateOrUpdateRequest(string policyDefinitionName, PolicyDefinition parameters)
 47        {
 6848            var message = _pipeline.CreateMessage();
 6849            var request = message.Request;
 6850            request.Method = RequestMethod.Put;
 6851            var uri = new RawRequestUriBuilder();
 6852            uri.Reset(endpoint);
 6853            uri.AppendPath("/subscriptions/", false);
 6854            uri.AppendPath(subscriptionId, true);
 6855            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 6856            uri.AppendPath(policyDefinitionName, true);
 6857            uri.AppendQuery("api-version", "2019-09-01", true);
 6858            request.Uri = uri;
 6859            request.Headers.Add("Content-Type", "application/json");
 6860            var content = new Utf8JsonRequestContent();
 6861            content.JsonWriter.WriteObjectValue(parameters);
 6862            request.Content = content;
 6863            return message;
 64        }
 65
 66        /// <summary> This operation creates or updates a policy definition in the given subscription with the given nam
 67        /// <param name="policyDefinitionName"> The name of the policy definition to create. </param>
 68        /// <param name="parameters"> The policy definition properties. </param>
 69        /// <param name="cancellationToken"> The cancellation token to use. </param>
 70        public async Task<Response<PolicyDefinition>> CreateOrUpdateAsync(string policyDefinitionName, PolicyDefinition 
 71        {
 3472            if (policyDefinitionName == null)
 73            {
 074                throw new ArgumentNullException(nameof(policyDefinitionName));
 75            }
 3476            if (parameters == null)
 77            {
 078                throw new ArgumentNullException(nameof(parameters));
 79            }
 80
 3481            using var message = CreateCreateOrUpdateRequest(policyDefinitionName, parameters);
 3482            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 3483            switch (message.Response.Status)
 84            {
 85                case 201:
 86                    {
 2687                        PolicyDefinition value = default;
 2688                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2689                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 90                        {
 091                            value = null;
 92                        }
 93                        else
 94                        {
 2695                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 96                        }
 2697                        return Response.FromValue(value, message.Response);
 98                    }
 99                default:
 8100                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 101            }
 26102        }
 103
 104        /// <summary> This operation creates or updates a policy definition in the given subscription with the given nam
 105        /// <param name="policyDefinitionName"> The name of the policy definition to create. </param>
 106        /// <param name="parameters"> The policy definition properties. </param>
 107        /// <param name="cancellationToken"> The cancellation token to use. </param>
 108        public Response<PolicyDefinition> CreateOrUpdate(string policyDefinitionName, PolicyDefinition parameters, Cance
 109        {
 34110            if (policyDefinitionName == null)
 111            {
 0112                throw new ArgumentNullException(nameof(policyDefinitionName));
 113            }
 34114            if (parameters == null)
 115            {
 0116                throw new ArgumentNullException(nameof(parameters));
 117            }
 118
 34119            using var message = CreateCreateOrUpdateRequest(policyDefinitionName, parameters);
 34120            _pipeline.Send(message, cancellationToken);
 34121            switch (message.Response.Status)
 122            {
 123                case 201:
 124                    {
 26125                        PolicyDefinition value = default;
 26126                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 26127                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 128                        {
 0129                            value = null;
 130                        }
 131                        else
 132                        {
 26133                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 134                        }
 26135                        return Response.FromValue(value, message.Response);
 136                    }
 137                default:
 8138                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 139            }
 26140        }
 141
 142        internal Core.HttpMessage CreateDeleteRequest(string policyDefinitionName)
 143        {
 244144            var message = _pipeline.CreateMessage();
 244145            var request = message.Request;
 244146            request.Method = RequestMethod.Delete;
 244147            var uri = new RawRequestUriBuilder();
 244148            uri.Reset(endpoint);
 244149            uri.AppendPath("/subscriptions/", false);
 244150            uri.AppendPath(subscriptionId, true);
 244151            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 244152            uri.AppendPath(policyDefinitionName, true);
 244153            uri.AppendQuery("api-version", "2019-09-01", true);
 244154            request.Uri = uri;
 244155            return message;
 156        }
 157
 158        /// <summary> This operation deletes the policy definition in the given subscription with the given name. </summ
 159        /// <param name="policyDefinitionName"> The name of the policy definition to delete. </param>
 160        /// <param name="cancellationToken"> The cancellation token to use. </param>
 161        public async Task<Response> DeleteAsync(string policyDefinitionName, CancellationToken cancellationToken = defau
 162        {
 122163            if (policyDefinitionName == null)
 164            {
 0165                throw new ArgumentNullException(nameof(policyDefinitionName));
 166            }
 167
 122168            using var message = CreateDeleteRequest(policyDefinitionName);
 122169            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 122170            switch (message.Response.Status)
 171            {
 172                case 200:
 173                case 204:
 122174                    return message.Response;
 175                default:
 0176                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 177            }
 122178        }
 179
 180        /// <summary> This operation deletes the policy definition in the given subscription with the given name. </summ
 181        /// <param name="policyDefinitionName"> The name of the policy definition to delete. </param>
 182        /// <param name="cancellationToken"> The cancellation token to use. </param>
 183        public Response Delete(string policyDefinitionName, CancellationToken cancellationToken = default)
 184        {
 122185            if (policyDefinitionName == null)
 186            {
 0187                throw new ArgumentNullException(nameof(policyDefinitionName));
 188            }
 189
 122190            using var message = CreateDeleteRequest(policyDefinitionName);
 122191            _pipeline.Send(message, cancellationToken);
 122192            switch (message.Response.Status)
 193            {
 194                case 200:
 195                case 204:
 122196                    return message.Response;
 197                default:
 0198                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 199            }
 122200        }
 201
 202        internal Core.HttpMessage CreateGetRequest(string policyDefinitionName)
 203        {
 56204            var message = _pipeline.CreateMessage();
 56205            var request = message.Request;
 56206            request.Method = RequestMethod.Get;
 56207            var uri = new RawRequestUriBuilder();
 56208            uri.Reset(endpoint);
 56209            uri.AppendPath("/subscriptions/", false);
 56210            uri.AppendPath(subscriptionId, true);
 56211            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 56212            uri.AppendPath(policyDefinitionName, true);
 56213            uri.AppendQuery("api-version", "2019-09-01", true);
 56214            request.Uri = uri;
 56215            return message;
 216        }
 217
 218        /// <summary> This operation retrieves the policy definition in the given subscription with the given name. </su
 219        /// <param name="policyDefinitionName"> The name of the policy definition to get. </param>
 220        /// <param name="cancellationToken"> The cancellation token to use. </param>
 221        public async Task<Response<PolicyDefinition>> GetAsync(string policyDefinitionName, CancellationToken cancellati
 222        {
 28223            if (policyDefinitionName == null)
 224            {
 0225                throw new ArgumentNullException(nameof(policyDefinitionName));
 226            }
 227
 28228            using var message = CreateGetRequest(policyDefinitionName);
 28229            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 28230            switch (message.Response.Status)
 231            {
 232                case 200:
 233                    {
 10234                        PolicyDefinition value = default;
 10235                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 10236                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 237                        {
 0238                            value = null;
 239                        }
 240                        else
 241                        {
 10242                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 243                        }
 10244                        return Response.FromValue(value, message.Response);
 245                    }
 246                default:
 18247                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 248            }
 10249        }
 250
 251        /// <summary> This operation retrieves the policy definition in the given subscription with the given name. </su
 252        /// <param name="policyDefinitionName"> The name of the policy definition to get. </param>
 253        /// <param name="cancellationToken"> The cancellation token to use. </param>
 254        public Response<PolicyDefinition> Get(string policyDefinitionName, CancellationToken cancellationToken = default
 255        {
 28256            if (policyDefinitionName == null)
 257            {
 0258                throw new ArgumentNullException(nameof(policyDefinitionName));
 259            }
 260
 28261            using var message = CreateGetRequest(policyDefinitionName);
 28262            _pipeline.Send(message, cancellationToken);
 28263            switch (message.Response.Status)
 264            {
 265                case 200:
 266                    {
 10267                        PolicyDefinition value = default;
 10268                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 10269                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 270                        {
 0271                            value = null;
 272                        }
 273                        else
 274                        {
 10275                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 276                        }
 10277                        return Response.FromValue(value, message.Response);
 278                    }
 279                default:
 18280                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 281            }
 10282        }
 283
 284        internal Core.HttpMessage CreateGetBuiltInRequest(string policyDefinitionName)
 285        {
 13208286            var message = _pipeline.CreateMessage();
 13208287            var request = message.Request;
 13208288            request.Method = RequestMethod.Get;
 13208289            var uri = new RawRequestUriBuilder();
 13208290            uri.Reset(endpoint);
 13208291            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 13208292            uri.AppendPath(policyDefinitionName, true);
 13208293            uri.AppendQuery("api-version", "2019-09-01", true);
 13208294            request.Uri = uri;
 13208295            return message;
 296        }
 297
 298        /// <summary> This operation retrieves the built-in policy definition with the given name. </summary>
 299        /// <param name="policyDefinitionName"> The name of the built-in policy definition to get. </param>
 300        /// <param name="cancellationToken"> The cancellation token to use. </param>
 301        public async Task<Response<PolicyDefinition>> GetBuiltInAsync(string policyDefinitionName, CancellationToken can
 302        {
 6604303            if (policyDefinitionName == null)
 304            {
 0305                throw new ArgumentNullException(nameof(policyDefinitionName));
 306            }
 307
 6604308            using var message = CreateGetBuiltInRequest(policyDefinitionName);
 6604309            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 6604310            switch (message.Response.Status)
 311            {
 312                case 200:
 313                    {
 6604314                        PolicyDefinition value = default;
 6604315                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 6604316                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 317                        {
 0318                            value = null;
 319                        }
 320                        else
 321                        {
 6604322                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 323                        }
 6604324                        return Response.FromValue(value, message.Response);
 325                    }
 326                default:
 0327                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 328            }
 6604329        }
 330
 331        /// <summary> This operation retrieves the built-in policy definition with the given name. </summary>
 332        /// <param name="policyDefinitionName"> The name of the built-in policy definition to get. </param>
 333        /// <param name="cancellationToken"> The cancellation token to use. </param>
 334        public Response<PolicyDefinition> GetBuiltIn(string policyDefinitionName, CancellationToken cancellationToken = 
 335        {
 6604336            if (policyDefinitionName == null)
 337            {
 0338                throw new ArgumentNullException(nameof(policyDefinitionName));
 339            }
 340
 6604341            using var message = CreateGetBuiltInRequest(policyDefinitionName);
 6604342            _pipeline.Send(message, cancellationToken);
 6604343            switch (message.Response.Status)
 344            {
 345                case 200:
 346                    {
 6604347                        PolicyDefinition value = default;
 6604348                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 6604349                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 350                        {
 0351                            value = null;
 352                        }
 353                        else
 354                        {
 6604355                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 356                        }
 6604357                        return Response.FromValue(value, message.Response);
 358                    }
 359                default:
 0360                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 361            }
 6604362        }
 363
 364        internal Core.HttpMessage CreateCreateOrUpdateAtManagementGroupRequest(string policyDefinitionName, string manag
 365        {
 0366            var message = _pipeline.CreateMessage();
 0367            var request = message.Request;
 0368            request.Method = RequestMethod.Put;
 0369            var uri = new RawRequestUriBuilder();
 0370            uri.Reset(endpoint);
 0371            uri.AppendPath("/providers/Microsoft.Management/managementgroups/", false);
 0372            uri.AppendPath(managementGroupId, true);
 0373            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 0374            uri.AppendPath(policyDefinitionName, true);
 0375            uri.AppendQuery("api-version", "2019-09-01", true);
 0376            request.Uri = uri;
 0377            request.Headers.Add("Content-Type", "application/json");
 0378            var content = new Utf8JsonRequestContent();
 0379            content.JsonWriter.WriteObjectValue(parameters);
 0380            request.Content = content;
 0381            return message;
 382        }
 383
 384        /// <summary> This operation creates or updates a policy definition in the given management group with the given
 385        /// <param name="policyDefinitionName"> The name of the policy definition to create. </param>
 386        /// <param name="managementGroupId"> The ID of the management group. </param>
 387        /// <param name="parameters"> The policy definition properties. </param>
 388        /// <param name="cancellationToken"> The cancellation token to use. </param>
 389        public async Task<Response<PolicyDefinition>> CreateOrUpdateAtManagementGroupAsync(string policyDefinitionName, 
 390        {
 0391            if (policyDefinitionName == null)
 392            {
 0393                throw new ArgumentNullException(nameof(policyDefinitionName));
 394            }
 0395            if (managementGroupId == null)
 396            {
 0397                throw new ArgumentNullException(nameof(managementGroupId));
 398            }
 0399            if (parameters == null)
 400            {
 0401                throw new ArgumentNullException(nameof(parameters));
 402            }
 403
 0404            using var message = CreateCreateOrUpdateAtManagementGroupRequest(policyDefinitionName, managementGroupId, pa
 0405            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0406            switch (message.Response.Status)
 407            {
 408                case 201:
 409                    {
 0410                        PolicyDefinition value = default;
 0411                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0412                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 413                        {
 0414                            value = null;
 415                        }
 416                        else
 417                        {
 0418                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 419                        }
 0420                        return Response.FromValue(value, message.Response);
 421                    }
 422                default:
 0423                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 424            }
 0425        }
 426
 427        /// <summary> This operation creates or updates a policy definition in the given management group with the given
 428        /// <param name="policyDefinitionName"> The name of the policy definition to create. </param>
 429        /// <param name="managementGroupId"> The ID of the management group. </param>
 430        /// <param name="parameters"> The policy definition properties. </param>
 431        /// <param name="cancellationToken"> The cancellation token to use. </param>
 432        public Response<PolicyDefinition> CreateOrUpdateAtManagementGroup(string policyDefinitionName, string management
 433        {
 0434            if (policyDefinitionName == null)
 435            {
 0436                throw new ArgumentNullException(nameof(policyDefinitionName));
 437            }
 0438            if (managementGroupId == null)
 439            {
 0440                throw new ArgumentNullException(nameof(managementGroupId));
 441            }
 0442            if (parameters == null)
 443            {
 0444                throw new ArgumentNullException(nameof(parameters));
 445            }
 446
 0447            using var message = CreateCreateOrUpdateAtManagementGroupRequest(policyDefinitionName, managementGroupId, pa
 0448            _pipeline.Send(message, cancellationToken);
 0449            switch (message.Response.Status)
 450            {
 451                case 201:
 452                    {
 0453                        PolicyDefinition value = default;
 0454                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0455                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 456                        {
 0457                            value = null;
 458                        }
 459                        else
 460                        {
 0461                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 462                        }
 0463                        return Response.FromValue(value, message.Response);
 464                    }
 465                default:
 0466                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 467            }
 0468        }
 469
 470        internal Core.HttpMessage CreateDeleteAtManagementGroupRequest(string policyDefinitionName, string managementGro
 471        {
 0472            var message = _pipeline.CreateMessage();
 0473            var request = message.Request;
 0474            request.Method = RequestMethod.Delete;
 0475            var uri = new RawRequestUriBuilder();
 0476            uri.Reset(endpoint);
 0477            uri.AppendPath("/providers/Microsoft.Management/managementgroups/", false);
 0478            uri.AppendPath(managementGroupId, true);
 0479            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 0480            uri.AppendPath(policyDefinitionName, true);
 0481            uri.AppendQuery("api-version", "2019-09-01", true);
 0482            request.Uri = uri;
 0483            return message;
 484        }
 485
 486        /// <summary> This operation deletes the policy definition in the given management group with the given name. </
 487        /// <param name="policyDefinitionName"> The name of the policy definition to delete. </param>
 488        /// <param name="managementGroupId"> The ID of the management group. </param>
 489        /// <param name="cancellationToken"> The cancellation token to use. </param>
 490        public async Task<Response> DeleteAtManagementGroupAsync(string policyDefinitionName, string managementGroupId, 
 491        {
 0492            if (policyDefinitionName == null)
 493            {
 0494                throw new ArgumentNullException(nameof(policyDefinitionName));
 495            }
 0496            if (managementGroupId == null)
 497            {
 0498                throw new ArgumentNullException(nameof(managementGroupId));
 499            }
 500
 0501            using var message = CreateDeleteAtManagementGroupRequest(policyDefinitionName, managementGroupId);
 0502            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0503            switch (message.Response.Status)
 504            {
 505                case 200:
 506                case 204:
 0507                    return message.Response;
 508                default:
 0509                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 510            }
 0511        }
 512
 513        /// <summary> This operation deletes the policy definition in the given management group with the given name. </
 514        /// <param name="policyDefinitionName"> The name of the policy definition to delete. </param>
 515        /// <param name="managementGroupId"> The ID of the management group. </param>
 516        /// <param name="cancellationToken"> The cancellation token to use. </param>
 517        public Response DeleteAtManagementGroup(string policyDefinitionName, string managementGroupId, CancellationToken
 518        {
 0519            if (policyDefinitionName == null)
 520            {
 0521                throw new ArgumentNullException(nameof(policyDefinitionName));
 522            }
 0523            if (managementGroupId == null)
 524            {
 0525                throw new ArgumentNullException(nameof(managementGroupId));
 526            }
 527
 0528            using var message = CreateDeleteAtManagementGroupRequest(policyDefinitionName, managementGroupId);
 0529            _pipeline.Send(message, cancellationToken);
 0530            switch (message.Response.Status)
 531            {
 532                case 200:
 533                case 204:
 0534                    return message.Response;
 535                default:
 0536                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 537            }
 0538        }
 539
 540        internal Core.HttpMessage CreateGetAtManagementGroupRequest(string policyDefinitionName, string managementGroupI
 541        {
 0542            var message = _pipeline.CreateMessage();
 0543            var request = message.Request;
 0544            request.Method = RequestMethod.Get;
 0545            var uri = new RawRequestUriBuilder();
 0546            uri.Reset(endpoint);
 0547            uri.AppendPath("/providers/Microsoft.Management/managementgroups/", false);
 0548            uri.AppendPath(managementGroupId, true);
 0549            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions/", false);
 0550            uri.AppendPath(policyDefinitionName, true);
 0551            uri.AppendQuery("api-version", "2019-09-01", true);
 0552            request.Uri = uri;
 0553            return message;
 554        }
 555
 556        /// <summary> This operation retrieves the policy definition in the given management group with the given name. 
 557        /// <param name="policyDefinitionName"> The name of the policy definition to get. </param>
 558        /// <param name="managementGroupId"> The ID of the management group. </param>
 559        /// <param name="cancellationToken"> The cancellation token to use. </param>
 560        public async Task<Response<PolicyDefinition>> GetAtManagementGroupAsync(string policyDefinitionName, string mana
 561        {
 0562            if (policyDefinitionName == null)
 563            {
 0564                throw new ArgumentNullException(nameof(policyDefinitionName));
 565            }
 0566            if (managementGroupId == null)
 567            {
 0568                throw new ArgumentNullException(nameof(managementGroupId));
 569            }
 570
 0571            using var message = CreateGetAtManagementGroupRequest(policyDefinitionName, managementGroupId);
 0572            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0573            switch (message.Response.Status)
 574            {
 575                case 200:
 576                    {
 0577                        PolicyDefinition value = default;
 0578                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0579                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 580                        {
 0581                            value = null;
 582                        }
 583                        else
 584                        {
 0585                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 586                        }
 0587                        return Response.FromValue(value, message.Response);
 588                    }
 589                default:
 0590                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 591            }
 0592        }
 593
 594        /// <summary> This operation retrieves the policy definition in the given management group with the given name. 
 595        /// <param name="policyDefinitionName"> The name of the policy definition to get. </param>
 596        /// <param name="managementGroupId"> The ID of the management group. </param>
 597        /// <param name="cancellationToken"> The cancellation token to use. </param>
 598        public Response<PolicyDefinition> GetAtManagementGroup(string policyDefinitionName, string managementGroupId, Ca
 599        {
 0600            if (policyDefinitionName == null)
 601            {
 0602                throw new ArgumentNullException(nameof(policyDefinitionName));
 603            }
 0604            if (managementGroupId == null)
 605            {
 0606                throw new ArgumentNullException(nameof(managementGroupId));
 607            }
 608
 0609            using var message = CreateGetAtManagementGroupRequest(policyDefinitionName, managementGroupId);
 0610            _pipeline.Send(message, cancellationToken);
 0611            switch (message.Response.Status)
 612            {
 613                case 200:
 614                    {
 0615                        PolicyDefinition value = default;
 0616                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0617                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 618                        {
 0619                            value = null;
 620                        }
 621                        else
 622                        {
 0623                            value = PolicyDefinition.DeserializePolicyDefinition(document.RootElement);
 624                        }
 0625                        return Response.FromValue(value, message.Response);
 626                    }
 627                default:
 0628                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 629            }
 0630        }
 631
 632        internal Core.HttpMessage CreateListRequest()
 633        {
 44634            var message = _pipeline.CreateMessage();
 44635            var request = message.Request;
 44636            request.Method = RequestMethod.Get;
 44637            var uri = new RawRequestUriBuilder();
 44638            uri.Reset(endpoint);
 44639            uri.AppendPath("/subscriptions/", false);
 44640            uri.AppendPath(subscriptionId, true);
 44641            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions", false);
 44642            uri.AppendQuery("api-version", "2019-09-01", true);
 44643            request.Uri = uri;
 44644            return message;
 645        }
 646
 647        /// <summary> This operation retrieves a list of all the policy definitions in a given subscription. </summary>
 648        /// <param name="cancellationToken"> The cancellation token to use. </param>
 649        public async Task<Response<PolicyDefinitionListResult>> ListAsync(CancellationToken cancellationToken = default)
 650        {
 22651            using var message = CreateListRequest();
 22652            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 22653            switch (message.Response.Status)
 654            {
 655                case 200:
 656                    {
 22657                        PolicyDefinitionListResult value = default;
 22658                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 22659                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 660                        {
 0661                            value = null;
 662                        }
 663                        else
 664                        {
 22665                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 666                        }
 22667                        return Response.FromValue(value, message.Response);
 668                    }
 669                default:
 0670                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 671            }
 22672        }
 673
 674        /// <summary> This operation retrieves a list of all the policy definitions in a given subscription. </summary>
 675        /// <param name="cancellationToken"> The cancellation token to use. </param>
 676        public Response<PolicyDefinitionListResult> List(CancellationToken cancellationToken = default)
 677        {
 22678            using var message = CreateListRequest();
 22679            _pipeline.Send(message, cancellationToken);
 22680            switch (message.Response.Status)
 681            {
 682                case 200:
 683                    {
 22684                        PolicyDefinitionListResult value = default;
 22685                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 22686                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 687                        {
 0688                            value = null;
 689                        }
 690                        else
 691                        {
 22692                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 693                        }
 22694                        return Response.FromValue(value, message.Response);
 695                    }
 696                default:
 0697                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 698            }
 22699        }
 700
 701        internal Core.HttpMessage CreateListBuiltInRequest()
 702        {
 12703            var message = _pipeline.CreateMessage();
 12704            var request = message.Request;
 12705            request.Method = RequestMethod.Get;
 12706            var uri = new RawRequestUriBuilder();
 12707            uri.Reset(endpoint);
 12708            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions", false);
 12709            uri.AppendQuery("api-version", "2019-09-01", true);
 12710            request.Uri = uri;
 12711            return message;
 712        }
 713
 714        /// <summary> This operation retrieves a list of all the built-in policy definitions. </summary>
 715        /// <param name="cancellationToken"> The cancellation token to use. </param>
 716        public async Task<Response<PolicyDefinitionListResult>> ListBuiltInAsync(CancellationToken cancellationToken = d
 717        {
 6718            using var message = CreateListBuiltInRequest();
 6719            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 6720            switch (message.Response.Status)
 721            {
 722                case 200:
 723                    {
 6724                        PolicyDefinitionListResult value = default;
 6725                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 6726                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 727                        {
 0728                            value = null;
 729                        }
 730                        else
 731                        {
 6732                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 733                        }
 6734                        return Response.FromValue(value, message.Response);
 735                    }
 736                default:
 0737                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 738            }
 6739        }
 740
 741        /// <summary> This operation retrieves a list of all the built-in policy definitions. </summary>
 742        /// <param name="cancellationToken"> The cancellation token to use. </param>
 743        public Response<PolicyDefinitionListResult> ListBuiltIn(CancellationToken cancellationToken = default)
 744        {
 6745            using var message = CreateListBuiltInRequest();
 6746            _pipeline.Send(message, cancellationToken);
 6747            switch (message.Response.Status)
 748            {
 749                case 200:
 750                    {
 6751                        PolicyDefinitionListResult value = default;
 6752                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 6753                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 754                        {
 0755                            value = null;
 756                        }
 757                        else
 758                        {
 6759                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 760                        }
 6761                        return Response.FromValue(value, message.Response);
 762                    }
 763                default:
 0764                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 765            }
 6766        }
 767
 768        internal Core.HttpMessage CreateListByManagementGroupRequest(string managementGroupId)
 769        {
 0770            var message = _pipeline.CreateMessage();
 0771            var request = message.Request;
 0772            request.Method = RequestMethod.Get;
 0773            var uri = new RawRequestUriBuilder();
 0774            uri.Reset(endpoint);
 0775            uri.AppendPath("/providers/Microsoft.Management/managementgroups/", false);
 0776            uri.AppendPath(managementGroupId, true);
 0777            uri.AppendPath("/providers/Microsoft.Authorization/policyDefinitions", false);
 0778            uri.AppendQuery("api-version", "2019-09-01", true);
 0779            request.Uri = uri;
 0780            return message;
 781        }
 782
 783        /// <summary> This operation retrieves a list of all the policy definitions in a given management group. </summa
 784        /// <param name="managementGroupId"> The ID of the management group. </param>
 785        /// <param name="cancellationToken"> The cancellation token to use. </param>
 786        public async Task<Response<PolicyDefinitionListResult>> ListByManagementGroupAsync(string managementGroupId, Can
 787        {
 0788            if (managementGroupId == null)
 789            {
 0790                throw new ArgumentNullException(nameof(managementGroupId));
 791            }
 792
 0793            using var message = CreateListByManagementGroupRequest(managementGroupId);
 0794            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0795            switch (message.Response.Status)
 796            {
 797                case 200:
 798                    {
 0799                        PolicyDefinitionListResult value = default;
 0800                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0801                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 802                        {
 0803                            value = null;
 804                        }
 805                        else
 806                        {
 0807                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 808                        }
 0809                        return Response.FromValue(value, message.Response);
 810                    }
 811                default:
 0812                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 813            }
 0814        }
 815
 816        /// <summary> This operation retrieves a list of all the policy definitions in a given management group. </summa
 817        /// <param name="managementGroupId"> The ID of the management group. </param>
 818        /// <param name="cancellationToken"> The cancellation token to use. </param>
 819        public Response<PolicyDefinitionListResult> ListByManagementGroup(string managementGroupId, CancellationToken ca
 820        {
 0821            if (managementGroupId == null)
 822            {
 0823                throw new ArgumentNullException(nameof(managementGroupId));
 824            }
 825
 0826            using var message = CreateListByManagementGroupRequest(managementGroupId);
 0827            _pipeline.Send(message, cancellationToken);
 0828            switch (message.Response.Status)
 829            {
 830                case 200:
 831                    {
 0832                        PolicyDefinitionListResult value = default;
 0833                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0834                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 835                        {
 0836                            value = null;
 837                        }
 838                        else
 839                        {
 0840                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 841                        }
 0842                        return Response.FromValue(value, message.Response);
 843                    }
 844                default:
 0845                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 846            }
 0847        }
 848
 849        internal Core.HttpMessage CreateListNextPageRequest(string nextLink)
 850        {
 0851            var message = _pipeline.CreateMessage();
 0852            var request = message.Request;
 0853            request.Method = RequestMethod.Get;
 0854            var uri = new RawRequestUriBuilder();
 0855            uri.Reset(endpoint);
 0856            uri.AppendRawNextLink(nextLink, false);
 0857            request.Uri = uri;
 0858            return message;
 859        }
 860
 861        /// <summary> This operation retrieves a list of all the policy definitions in a given subscription. </summary>
 862        /// <param name="nextLink"> The URL to the next page of results. </param>
 863        /// <param name="cancellationToken"> The cancellation token to use. </param>
 864        public async Task<Response<PolicyDefinitionListResult>> ListNextPageAsync(string nextLink, CancellationToken can
 865        {
 0866            if (nextLink == null)
 867            {
 0868                throw new ArgumentNullException(nameof(nextLink));
 869            }
 870
 0871            using var message = CreateListNextPageRequest(nextLink);
 0872            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0873            switch (message.Response.Status)
 874            {
 875                case 200:
 876                    {
 0877                        PolicyDefinitionListResult value = default;
 0878                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0879                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 880                        {
 0881                            value = null;
 882                        }
 883                        else
 884                        {
 0885                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 886                        }
 0887                        return Response.FromValue(value, message.Response);
 888                    }
 889                default:
 0890                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 891            }
 0892        }
 893
 894        /// <summary> This operation retrieves a list of all the policy definitions in a given subscription. </summary>
 895        /// <param name="nextLink"> The URL to the next page of results. </param>
 896        /// <param name="cancellationToken"> The cancellation token to use. </param>
 897        public Response<PolicyDefinitionListResult> ListNextPage(string nextLink, CancellationToken cancellationToken = 
 898        {
 0899            if (nextLink == null)
 900            {
 0901                throw new ArgumentNullException(nameof(nextLink));
 902            }
 903
 0904            using var message = CreateListNextPageRequest(nextLink);
 0905            _pipeline.Send(message, cancellationToken);
 0906            switch (message.Response.Status)
 907            {
 908                case 200:
 909                    {
 0910                        PolicyDefinitionListResult value = default;
 0911                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0912                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 913                        {
 0914                            value = null;
 915                        }
 916                        else
 917                        {
 0918                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 919                        }
 0920                        return Response.FromValue(value, message.Response);
 921                    }
 922                default:
 0923                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 924            }
 0925        }
 926
 927        internal Core.HttpMessage CreateListBuiltInNextPageRequest(string nextLink)
 928        {
 0929            var message = _pipeline.CreateMessage();
 0930            var request = message.Request;
 0931            request.Method = RequestMethod.Get;
 0932            var uri = new RawRequestUriBuilder();
 0933            uri.Reset(endpoint);
 0934            uri.AppendRawNextLink(nextLink, false);
 0935            request.Uri = uri;
 0936            return message;
 937        }
 938
 939        /// <summary> This operation retrieves a list of all the built-in policy definitions. </summary>
 940        /// <param name="nextLink"> The URL to the next page of results. </param>
 941        /// <param name="cancellationToken"> The cancellation token to use. </param>
 942        public async Task<Response<PolicyDefinitionListResult>> ListBuiltInNextPageAsync(string nextLink, CancellationTo
 943        {
 0944            if (nextLink == null)
 945            {
 0946                throw new ArgumentNullException(nameof(nextLink));
 947            }
 948
 0949            using var message = CreateListBuiltInNextPageRequest(nextLink);
 0950            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0951            switch (message.Response.Status)
 952            {
 953                case 200:
 954                    {
 0955                        PolicyDefinitionListResult value = default;
 0956                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0957                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 958                        {
 0959                            value = null;
 960                        }
 961                        else
 962                        {
 0963                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 964                        }
 0965                        return Response.FromValue(value, message.Response);
 966                    }
 967                default:
 0968                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 969            }
 0970        }
 971
 972        /// <summary> This operation retrieves a list of all the built-in policy definitions. </summary>
 973        /// <param name="nextLink"> The URL to the next page of results. </param>
 974        /// <param name="cancellationToken"> The cancellation token to use. </param>
 975        public Response<PolicyDefinitionListResult> ListBuiltInNextPage(string nextLink, CancellationToken cancellationT
 976        {
 0977            if (nextLink == null)
 978            {
 0979                throw new ArgumentNullException(nameof(nextLink));
 980            }
 981
 0982            using var message = CreateListBuiltInNextPageRequest(nextLink);
 0983            _pipeline.Send(message, cancellationToken);
 0984            switch (message.Response.Status)
 985            {
 986                case 200:
 987                    {
 0988                        PolicyDefinitionListResult value = default;
 0989                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0990                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 991                        {
 0992                            value = null;
 993                        }
 994                        else
 995                        {
 0996                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 997                        }
 0998                        return Response.FromValue(value, message.Response);
 999                    }
 1000                default:
 01001                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 1002            }
 01003        }
 1004
 1005        internal Core.HttpMessage CreateListByManagementGroupNextPageRequest(string nextLink, string managementGroupId)
 1006        {
 01007            var message = _pipeline.CreateMessage();
 01008            var request = message.Request;
 01009            request.Method = RequestMethod.Get;
 01010            var uri = new RawRequestUriBuilder();
 01011            uri.Reset(endpoint);
 01012            uri.AppendRawNextLink(nextLink, false);
 01013            request.Uri = uri;
 01014            return message;
 1015        }
 1016
 1017        /// <summary> This operation retrieves a list of all the policy definitions in a given management group. </summa
 1018        /// <param name="nextLink"> The URL to the next page of results. </param>
 1019        /// <param name="managementGroupId"> The ID of the management group. </param>
 1020        /// <param name="cancellationToken"> The cancellation token to use. </param>
 1021        public async Task<Response<PolicyDefinitionListResult>> ListByManagementGroupNextPageAsync(string nextLink, stri
 1022        {
 01023            if (nextLink == null)
 1024            {
 01025                throw new ArgumentNullException(nameof(nextLink));
 1026            }
 01027            if (managementGroupId == null)
 1028            {
 01029                throw new ArgumentNullException(nameof(managementGroupId));
 1030            }
 1031
 01032            using var message = CreateListByManagementGroupNextPageRequest(nextLink, managementGroupId);
 01033            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 01034            switch (message.Response.Status)
 1035            {
 1036                case 200:
 1037                    {
 01038                        PolicyDefinitionListResult value = default;
 01039                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 01040                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 1041                        {
 01042                            value = null;
 1043                        }
 1044                        else
 1045                        {
 01046                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 1047                        }
 01048                        return Response.FromValue(value, message.Response);
 1049                    }
 1050                default:
 01051                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 1052            }
 01053        }
 1054
 1055        /// <summary> This operation retrieves a list of all the policy definitions in a given management group. </summa
 1056        /// <param name="nextLink"> The URL to the next page of results. </param>
 1057        /// <param name="managementGroupId"> The ID of the management group. </param>
 1058        /// <param name="cancellationToken"> The cancellation token to use. </param>
 1059        public Response<PolicyDefinitionListResult> ListByManagementGroupNextPage(string nextLink, string managementGrou
 1060        {
 01061            if (nextLink == null)
 1062            {
 01063                throw new ArgumentNullException(nameof(nextLink));
 1064            }
 01065            if (managementGroupId == null)
 1066            {
 01067                throw new ArgumentNullException(nameof(managementGroupId));
 1068            }
 1069
 01070            using var message = CreateListByManagementGroupNextPageRequest(nextLink, managementGroupId);
 01071            _pipeline.Send(message, cancellationToken);
 01072            switch (message.Response.Status)
 1073            {
 1074                case 200:
 1075                    {
 01076                        PolicyDefinitionListResult value = default;
 01077                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 01078                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 1079                        {
 01080                            value = null;
 1081                        }
 1082                        else
 1083                        {
 01084                            value = PolicyDefinitionListResult.DeserializePolicyDefinitionListResult(document.RootElemen
 1085                        }
 01086                        return Response.FromValue(value, message.Response);
 1087                    }
 1088                default:
 01089                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 1090            }
 01091        }
 1092    }
 1093}