< Summary

Class:Azure.ResourceManager.Network.SecurityRulesRestOperations
Assembly:Azure.ResourceManager.Network
File(s):C:\Git\azure-sdk-for-net\sdk\network\Azure.ResourceManager.Network\src\Generated\SecurityRulesRestOperations.cs
Covered lines:155
Uncovered lines:79
Coverable lines:234
Total lines:529
Line coverage:66.2% (155 of 234)
Covered branches:42
Total branches:104
Branch coverage:40.3% (42 of 104)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-66.67%50%
Delete(...)-66.67%50%
CreateGetRequest(...)-100%100%
GetAsync()-70.59%50%
Get(...)-70.59%50%
CreateCreateOrUpdateRequest(...)-100%100%
CreateOrUpdateAsync()-64.29%50%
CreateOrUpdate(...)-64.29%50%
CreateListRequest(...)-100%100%
ListAsync()-73.33%50%
List(...)-73.33%50%
CreateListNextPageRequest(...)-0%100%
ListNextPageAsync()-0%0%
ListNextPage(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\network\Azure.ResourceManager.Network\src\Generated\SecurityRulesRestOperations.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.Network.Models;
 16
 17namespace Azure.ResourceManager.Network
 18{
 19    internal partial class SecurityRulesRestOperations
 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 SecurityRulesRestOperations. </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 subscription credentials which uniquely identify the Microsoft Azure subsc
 30        /// <param name="endpoint"> server parameter. </param>
 31        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception
 2432        public SecurityRulesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscripti
 33        {
 2434            if (subscriptionId == null)
 35            {
 036                throw new ArgumentNullException(nameof(subscriptionId));
 37            }
 2438            endpoint ??= new Uri("https://management.azure.com");
 39
 2440            this.subscriptionId = subscriptionId;
 2441            this.endpoint = endpoint;
 2442            _clientDiagnostics = clientDiagnostics;
 2443            _pipeline = pipeline;
 2444        }
 45
 46        internal HttpMessage CreateDeleteRequest(string resourceGroupName, string networkSecurityGroupName, string secur
 47        {
 848            var message = _pipeline.CreateMessage();
 849            var request = message.Request;
 850            request.Method = RequestMethod.Delete;
 851            var uri = new RawRequestUriBuilder();
 852            uri.Reset(endpoint);
 853            uri.AppendPath("/subscriptions/", false);
 854            uri.AppendPath(subscriptionId, true);
 855            uri.AppendPath("/resourceGroups/", false);
 856            uri.AppendPath(resourceGroupName, true);
 857            uri.AppendPath("/providers/Microsoft.Network/networkSecurityGroups/", false);
 858            uri.AppendPath(networkSecurityGroupName, true);
 859            uri.AppendPath("/securityRules/", false);
 860            uri.AppendPath(securityRuleName, true);
 861            uri.AppendQuery("api-version", "2020-04-01", true);
 862            request.Uri = uri;
 863            return message;
 64        }
 65
 66        /// <summary> Deletes the specified network security rule. </summary>
 67        /// <param name="resourceGroupName"> The name of the resource group. </param>
 68        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 69        /// <param name="securityRuleName"> The name of the security rule. </param>
 70        /// <param name="cancellationToken"> The cancellation token to use. </param>
 71        public async Task<Response> DeleteAsync(string resourceGroupName, string networkSecurityGroupName, string securi
 72        {
 273            if (resourceGroupName == null)
 74            {
 075                throw new ArgumentNullException(nameof(resourceGroupName));
 76            }
 277            if (networkSecurityGroupName == null)
 78            {
 079                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 80            }
 281            if (securityRuleName == null)
 82            {
 083                throw new ArgumentNullException(nameof(securityRuleName));
 84            }
 85
 286            using var message = CreateDeleteRequest(resourceGroupName, networkSecurityGroupName, securityRuleName);
 287            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 288            switch (message.Response.Status)
 89            {
 90                case 200:
 91                case 202:
 92                case 204:
 293                    return message.Response;
 94                default:
 095                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 96            }
 297        }
 98
 99        /// <summary> Deletes the specified network security rule. </summary>
 100        /// <param name="resourceGroupName"> The name of the resource group. </param>
 101        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 102        /// <param name="securityRuleName"> The name of the security rule. </param>
 103        /// <param name="cancellationToken"> The cancellation token to use. </param>
 104        public Response Delete(string resourceGroupName, string networkSecurityGroupName, string securityRuleName, Cance
 105        {
 2106            if (resourceGroupName == null)
 107            {
 0108                throw new ArgumentNullException(nameof(resourceGroupName));
 109            }
 2110            if (networkSecurityGroupName == null)
 111            {
 0112                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 113            }
 2114            if (securityRuleName == null)
 115            {
 0116                throw new ArgumentNullException(nameof(securityRuleName));
 117            }
 118
 2119            using var message = CreateDeleteRequest(resourceGroupName, networkSecurityGroupName, securityRuleName);
 2120            _pipeline.Send(message, cancellationToken);
 2121            switch (message.Response.Status)
 122            {
 123                case 200:
 124                case 202:
 125                case 204:
 2126                    return message.Response;
 127                default:
 0128                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 129            }
 2130        }
 131
 132        internal HttpMessage CreateGetRequest(string resourceGroupName, string networkSecurityGroupName, string security
 133        {
 8134            var message = _pipeline.CreateMessage();
 8135            var request = message.Request;
 8136            request.Method = RequestMethod.Get;
 8137            var uri = new RawRequestUriBuilder();
 8138            uri.Reset(endpoint);
 8139            uri.AppendPath("/subscriptions/", false);
 8140            uri.AppendPath(subscriptionId, true);
 8141            uri.AppendPath("/resourceGroups/", false);
 8142            uri.AppendPath(resourceGroupName, true);
 8143            uri.AppendPath("/providers/Microsoft.Network/networkSecurityGroups/", false);
 8144            uri.AppendPath(networkSecurityGroupName, true);
 8145            uri.AppendPath("/securityRules/", false);
 8146            uri.AppendPath(securityRuleName, true);
 8147            uri.AppendQuery("api-version", "2020-04-01", true);
 8148            request.Uri = uri;
 8149            return message;
 150        }
 151
 152        /// <summary> Get the specified network security rule. </summary>
 153        /// <param name="resourceGroupName"> The name of the resource group. </param>
 154        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 155        /// <param name="securityRuleName"> The name of the security rule. </param>
 156        /// <param name="cancellationToken"> The cancellation token to use. </param>
 157        public async Task<Response<SecurityRule>> GetAsync(string resourceGroupName, string networkSecurityGroupName, st
 158        {
 4159            if (resourceGroupName == null)
 160            {
 0161                throw new ArgumentNullException(nameof(resourceGroupName));
 162            }
 4163            if (networkSecurityGroupName == null)
 164            {
 0165                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 166            }
 4167            if (securityRuleName == null)
 168            {
 0169                throw new ArgumentNullException(nameof(securityRuleName));
 170            }
 171
 4172            using var message = CreateGetRequest(resourceGroupName, networkSecurityGroupName, securityRuleName);
 4173            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4174            switch (message.Response.Status)
 175            {
 176                case 200:
 177                    {
 4178                        SecurityRule value = default;
 4179                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4180                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 181                        {
 0182                            value = null;
 183                        }
 184                        else
 185                        {
 4186                            value = SecurityRule.DeserializeSecurityRule(document.RootElement);
 187                        }
 4188                        return Response.FromValue(value, message.Response);
 189                    }
 190                default:
 0191                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 192            }
 4193        }
 194
 195        /// <summary> Get the specified network security rule. </summary>
 196        /// <param name="resourceGroupName"> The name of the resource group. </param>
 197        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 198        /// <param name="securityRuleName"> The name of the security rule. </param>
 199        /// <param name="cancellationToken"> The cancellation token to use. </param>
 200        public Response<SecurityRule> Get(string resourceGroupName, string networkSecurityGroupName, string securityRule
 201        {
 4202            if (resourceGroupName == null)
 203            {
 0204                throw new ArgumentNullException(nameof(resourceGroupName));
 205            }
 4206            if (networkSecurityGroupName == null)
 207            {
 0208                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 209            }
 4210            if (securityRuleName == null)
 211            {
 0212                throw new ArgumentNullException(nameof(securityRuleName));
 213            }
 214
 4215            using var message = CreateGetRequest(resourceGroupName, networkSecurityGroupName, securityRuleName);
 4216            _pipeline.Send(message, cancellationToken);
 4217            switch (message.Response.Status)
 218            {
 219                case 200:
 220                    {
 4221                        SecurityRule value = default;
 4222                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4223                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 224                        {
 0225                            value = null;
 226                        }
 227                        else
 228                        {
 4229                            value = SecurityRule.DeserializeSecurityRule(document.RootElement);
 230                        }
 4231                        return Response.FromValue(value, message.Response);
 232                    }
 233                default:
 0234                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 235            }
 4236        }
 237
 238        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string networkSecurityGroupName, stri
 239        {
 8240            var message = _pipeline.CreateMessage();
 8241            var request = message.Request;
 8242            request.Method = RequestMethod.Put;
 8243            var uri = new RawRequestUriBuilder();
 8244            uri.Reset(endpoint);
 8245            uri.AppendPath("/subscriptions/", false);
 8246            uri.AppendPath(subscriptionId, true);
 8247            uri.AppendPath("/resourceGroups/", false);
 8248            uri.AppendPath(resourceGroupName, true);
 8249            uri.AppendPath("/providers/Microsoft.Network/networkSecurityGroups/", false);
 8250            uri.AppendPath(networkSecurityGroupName, true);
 8251            uri.AppendPath("/securityRules/", false);
 8252            uri.AppendPath(securityRuleName, true);
 8253            uri.AppendQuery("api-version", "2020-04-01", true);
 8254            request.Uri = uri;
 8255            request.Headers.Add("Content-Type", "application/json");
 8256            var content = new Utf8JsonRequestContent();
 8257            content.JsonWriter.WriteObjectValue(securityRuleParameters);
 8258            request.Content = content;
 8259            return message;
 260        }
 261
 262        /// <summary> Creates or updates a security rule in the specified network security group. </summary>
 263        /// <param name="resourceGroupName"> The name of the resource group. </param>
 264        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 265        /// <param name="securityRuleName"> The name of the security rule. </param>
 266        /// <param name="securityRuleParameters"> Parameters supplied to the create or update network security rule oper
 267        /// <param name="cancellationToken"> The cancellation token to use. </param>
 268        public async Task<Response> CreateOrUpdateAsync(string resourceGroupName, string networkSecurityGroupName, strin
 269        {
 2270            if (resourceGroupName == null)
 271            {
 0272                throw new ArgumentNullException(nameof(resourceGroupName));
 273            }
 2274            if (networkSecurityGroupName == null)
 275            {
 0276                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 277            }
 2278            if (securityRuleName == null)
 279            {
 0280                throw new ArgumentNullException(nameof(securityRuleName));
 281            }
 2282            if (securityRuleParameters == null)
 283            {
 0284                throw new ArgumentNullException(nameof(securityRuleParameters));
 285            }
 286
 2287            using var message = CreateCreateOrUpdateRequest(resourceGroupName, networkSecurityGroupName, securityRuleNam
 2288            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2289            switch (message.Response.Status)
 290            {
 291                case 200:
 292                case 201:
 2293                    return message.Response;
 294                default:
 0295                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 296            }
 2297        }
 298
 299        /// <summary> Creates or updates a security rule in the specified network security group. </summary>
 300        /// <param name="resourceGroupName"> The name of the resource group. </param>
 301        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 302        /// <param name="securityRuleName"> The name of the security rule. </param>
 303        /// <param name="securityRuleParameters"> Parameters supplied to the create or update network security rule oper
 304        /// <param name="cancellationToken"> The cancellation token to use. </param>
 305        public Response CreateOrUpdate(string resourceGroupName, string networkSecurityGroupName, string securityRuleNam
 306        {
 2307            if (resourceGroupName == null)
 308            {
 0309                throw new ArgumentNullException(nameof(resourceGroupName));
 310            }
 2311            if (networkSecurityGroupName == null)
 312            {
 0313                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 314            }
 2315            if (securityRuleName == null)
 316            {
 0317                throw new ArgumentNullException(nameof(securityRuleName));
 318            }
 2319            if (securityRuleParameters == null)
 320            {
 0321                throw new ArgumentNullException(nameof(securityRuleParameters));
 322            }
 323
 2324            using var message = CreateCreateOrUpdateRequest(resourceGroupName, networkSecurityGroupName, securityRuleNam
 2325            _pipeline.Send(message, cancellationToken);
 2326            switch (message.Response.Status)
 327            {
 328                case 200:
 329                case 201:
 2330                    return message.Response;
 331                default:
 0332                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 333            }
 2334        }
 335
 336        internal HttpMessage CreateListRequest(string resourceGroupName, string networkSecurityGroupName)
 337        {
 8338            var message = _pipeline.CreateMessage();
 8339            var request = message.Request;
 8340            request.Method = RequestMethod.Get;
 8341            var uri = new RawRequestUriBuilder();
 8342            uri.Reset(endpoint);
 8343            uri.AppendPath("/subscriptions/", false);
 8344            uri.AppendPath(subscriptionId, true);
 8345            uri.AppendPath("/resourceGroups/", false);
 8346            uri.AppendPath(resourceGroupName, true);
 8347            uri.AppendPath("/providers/Microsoft.Network/networkSecurityGroups/", false);
 8348            uri.AppendPath(networkSecurityGroupName, true);
 8349            uri.AppendPath("/securityRules", false);
 8350            uri.AppendQuery("api-version", "2020-04-01", true);
 8351            request.Uri = uri;
 8352            return message;
 353        }
 354
 355        /// <summary> Gets all security rules in a network security group. </summary>
 356        /// <param name="resourceGroupName"> The name of the resource group. </param>
 357        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 358        /// <param name="cancellationToken"> The cancellation token to use. </param>
 359        public async Task<Response<SecurityRuleListResult>> ListAsync(string resourceGroupName, string networkSecurityGr
 360        {
 4361            if (resourceGroupName == null)
 362            {
 0363                throw new ArgumentNullException(nameof(resourceGroupName));
 364            }
 4365            if (networkSecurityGroupName == null)
 366            {
 0367                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 368            }
 369
 4370            using var message = CreateListRequest(resourceGroupName, networkSecurityGroupName);
 4371            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4372            switch (message.Response.Status)
 373            {
 374                case 200:
 375                    {
 4376                        SecurityRuleListResult value = default;
 4377                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 4378                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 379                        {
 0380                            value = null;
 381                        }
 382                        else
 383                        {
 4384                            value = SecurityRuleListResult.DeserializeSecurityRuleListResult(document.RootElement);
 385                        }
 4386                        return Response.FromValue(value, message.Response);
 387                    }
 388                default:
 0389                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 390            }
 4391        }
 392
 393        /// <summary> Gets all security rules in a network security group. </summary>
 394        /// <param name="resourceGroupName"> The name of the resource group. </param>
 395        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 396        /// <param name="cancellationToken"> The cancellation token to use. </param>
 397        public Response<SecurityRuleListResult> List(string resourceGroupName, string networkSecurityGroupName, Cancella
 398        {
 4399            if (resourceGroupName == null)
 400            {
 0401                throw new ArgumentNullException(nameof(resourceGroupName));
 402            }
 4403            if (networkSecurityGroupName == null)
 404            {
 0405                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 406            }
 407
 4408            using var message = CreateListRequest(resourceGroupName, networkSecurityGroupName);
 4409            _pipeline.Send(message, cancellationToken);
 4410            switch (message.Response.Status)
 411            {
 412                case 200:
 413                    {
 4414                        SecurityRuleListResult value = default;
 4415                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 4416                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 417                        {
 0418                            value = null;
 419                        }
 420                        else
 421                        {
 4422                            value = SecurityRuleListResult.DeserializeSecurityRuleListResult(document.RootElement);
 423                        }
 4424                        return Response.FromValue(value, message.Response);
 425                    }
 426                default:
 0427                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 428            }
 4429        }
 430
 431        internal HttpMessage CreateListNextPageRequest(string nextLink, string resourceGroupName, string networkSecurity
 432        {
 0433            var message = _pipeline.CreateMessage();
 0434            var request = message.Request;
 0435            request.Method = RequestMethod.Get;
 0436            var uri = new RawRequestUriBuilder();
 0437            uri.Reset(endpoint);
 0438            uri.AppendRawNextLink(nextLink, false);
 0439            request.Uri = uri;
 0440            return message;
 441        }
 442
 443        /// <summary> Gets all security rules in a network security group. </summary>
 444        /// <param name="nextLink"> The URL to the next page of results. </param>
 445        /// <param name="resourceGroupName"> The name of the resource group. </param>
 446        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 447        /// <param name="cancellationToken"> The cancellation token to use. </param>
 448        public async Task<Response<SecurityRuleListResult>> ListNextPageAsync(string nextLink, string resourceGroupName,
 449        {
 0450            if (nextLink == null)
 451            {
 0452                throw new ArgumentNullException(nameof(nextLink));
 453            }
 0454            if (resourceGroupName == null)
 455            {
 0456                throw new ArgumentNullException(nameof(resourceGroupName));
 457            }
 0458            if (networkSecurityGroupName == null)
 459            {
 0460                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 461            }
 462
 0463            using var message = CreateListNextPageRequest(nextLink, resourceGroupName, networkSecurityGroupName);
 0464            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0465            switch (message.Response.Status)
 466            {
 467                case 200:
 468                    {
 0469                        SecurityRuleListResult value = default;
 0470                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0471                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 472                        {
 0473                            value = null;
 474                        }
 475                        else
 476                        {
 0477                            value = SecurityRuleListResult.DeserializeSecurityRuleListResult(document.RootElement);
 478                        }
 0479                        return Response.FromValue(value, message.Response);
 480                    }
 481                default:
 0482                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 483            }
 0484        }
 485
 486        /// <summary> Gets all security rules in a network security group. </summary>
 487        /// <param name="nextLink"> The URL to the next page of results. </param>
 488        /// <param name="resourceGroupName"> The name of the resource group. </param>
 489        /// <param name="networkSecurityGroupName"> The name of the network security group. </param>
 490        /// <param name="cancellationToken"> The cancellation token to use. </param>
 491        public Response<SecurityRuleListResult> ListNextPage(string nextLink, string resourceGroupName, string networkSe
 492        {
 0493            if (nextLink == null)
 494            {
 0495                throw new ArgumentNullException(nameof(nextLink));
 496            }
 0497            if (resourceGroupName == null)
 498            {
 0499                throw new ArgumentNullException(nameof(resourceGroupName));
 500            }
 0501            if (networkSecurityGroupName == null)
 502            {
 0503                throw new ArgumentNullException(nameof(networkSecurityGroupName));
 504            }
 505
 0506            using var message = CreateListNextPageRequest(nextLink, resourceGroupName, networkSecurityGroupName);
 0507            _pipeline.Send(message, cancellationToken);
 0508            switch (message.Response.Status)
 509            {
 510                case 200:
 511                    {
 0512                        SecurityRuleListResult value = default;
 0513                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0514                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 515                        {
 0516                            value = null;
 517                        }
 518                        else
 519                        {
 0520                            value = SecurityRuleListResult.DeserializeSecurityRuleListResult(document.RootElement);
 521                        }
 0522                        return Response.FromValue(value, message.Response);
 523                    }
 524                default:
 0525                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 526            }
 0527        }
 528    }
 529}