< Summary

Class:Azure.ResourceManager.Network.InboundNatRulesRestOperations
Assembly:Azure.ResourceManager.Network
File(s):C:\Git\azure-sdk-for-net\sdk\network\Azure.ResourceManager.Network\src\Generated\InboundNatRulesRestOperations.cs
Covered lines:156
Uncovered lines:80
Coverable lines:236
Total lines:535
Line coverage:66.1% (156 of 236)
Covered branches:43
Total branches:106
Branch coverage:40.5% (43 of 106)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateListRequest(...)-100%100%
ListAsync()-73.33%50%
List(...)-73.33%50%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-66.67%50%
Delete(...)-66.67%50%
CreateGetRequest(...)-94.44%50%
GetAsync()-70.59%50%
Get(...)-70.59%50%
CreateCreateOrUpdateRequest(...)-100%100%
CreateOrUpdateAsync()-64.29%50%
CreateOrUpdate(...)-64.29%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\InboundNatRulesRestOperations.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 InboundNatRulesRestOperations
 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 InboundNatRulesRestOperations. </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
 1632        public InboundNatRulesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscrip
 33        {
 1634            if (subscriptionId == null)
 35            {
 036                throw new ArgumentNullException(nameof(subscriptionId));
 37            }
 1638            endpoint ??= new Uri("https://management.azure.com");
 39
 1640            this.subscriptionId = subscriptionId;
 1641            this.endpoint = endpoint;
 1642            _clientDiagnostics = clientDiagnostics;
 1643            _pipeline = pipeline;
 1644        }
 45
 46        internal HttpMessage CreateListRequest(string resourceGroupName, string loadBalancerName)
 47        {
 448            var message = _pipeline.CreateMessage();
 449            var request = message.Request;
 450            request.Method = RequestMethod.Get;
 451            var uri = new RawRequestUriBuilder();
 452            uri.Reset(endpoint);
 453            uri.AppendPath("/subscriptions/", false);
 454            uri.AppendPath(subscriptionId, true);
 455            uri.AppendPath("/resourceGroups/", false);
 456            uri.AppendPath(resourceGroupName, true);
 457            uri.AppendPath("/providers/Microsoft.Network/loadBalancers/", false);
 458            uri.AppendPath(loadBalancerName, true);
 459            uri.AppendPath("/inboundNatRules", false);
 460            uri.AppendQuery("api-version", "2020-04-01", true);
 461            request.Uri = uri;
 462            return message;
 63        }
 64
 65        /// <summary> Gets all the inbound nat rules in a load balancer. </summary>
 66        /// <param name="resourceGroupName"> The name of the resource group. </param>
 67        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 68        /// <param name="cancellationToken"> The cancellation token to use. </param>
 69        public async Task<Response<InboundNatRuleListResult>> ListAsync(string resourceGroupName, string loadBalancerNam
 70        {
 271            if (resourceGroupName == null)
 72            {
 073                throw new ArgumentNullException(nameof(resourceGroupName));
 74            }
 275            if (loadBalancerName == null)
 76            {
 077                throw new ArgumentNullException(nameof(loadBalancerName));
 78            }
 79
 280            using var message = CreateListRequest(resourceGroupName, loadBalancerName);
 281            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 282            switch (message.Response.Status)
 83            {
 84                case 200:
 85                    {
 286                        InboundNatRuleListResult value = default;
 287                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 288                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 89                        {
 090                            value = null;
 91                        }
 92                        else
 93                        {
 294                            value = InboundNatRuleListResult.DeserializeInboundNatRuleListResult(document.RootElement);
 95                        }
 296                        return Response.FromValue(value, message.Response);
 97                    }
 98                default:
 099                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 100            }
 2101        }
 102
 103        /// <summary> Gets all the inbound nat rules in a load balancer. </summary>
 104        /// <param name="resourceGroupName"> The name of the resource group. </param>
 105        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 106        /// <param name="cancellationToken"> The cancellation token to use. </param>
 107        public Response<InboundNatRuleListResult> List(string resourceGroupName, string loadBalancerName, CancellationTo
 108        {
 2109            if (resourceGroupName == null)
 110            {
 0111                throw new ArgumentNullException(nameof(resourceGroupName));
 112            }
 2113            if (loadBalancerName == null)
 114            {
 0115                throw new ArgumentNullException(nameof(loadBalancerName));
 116            }
 117
 2118            using var message = CreateListRequest(resourceGroupName, loadBalancerName);
 2119            _pipeline.Send(message, cancellationToken);
 2120            switch (message.Response.Status)
 121            {
 122                case 200:
 123                    {
 2124                        InboundNatRuleListResult value = default;
 2125                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2126                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 127                        {
 0128                            value = null;
 129                        }
 130                        else
 131                        {
 2132                            value = InboundNatRuleListResult.DeserializeInboundNatRuleListResult(document.RootElement);
 133                        }
 2134                        return Response.FromValue(value, message.Response);
 135                    }
 136                default:
 0137                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 138            }
 2139        }
 140
 141        internal HttpMessage CreateDeleteRequest(string resourceGroupName, string loadBalancerName, string inboundNatRul
 142        {
 8143            var message = _pipeline.CreateMessage();
 8144            var request = message.Request;
 8145            request.Method = RequestMethod.Delete;
 8146            var uri = new RawRequestUriBuilder();
 8147            uri.Reset(endpoint);
 8148            uri.AppendPath("/subscriptions/", false);
 8149            uri.AppendPath(subscriptionId, true);
 8150            uri.AppendPath("/resourceGroups/", false);
 8151            uri.AppendPath(resourceGroupName, true);
 8152            uri.AppendPath("/providers/Microsoft.Network/loadBalancers/", false);
 8153            uri.AppendPath(loadBalancerName, true);
 8154            uri.AppendPath("/inboundNatRules/", false);
 8155            uri.AppendPath(inboundNatRuleName, true);
 8156            uri.AppendQuery("api-version", "2020-04-01", true);
 8157            request.Uri = uri;
 8158            return message;
 159        }
 160
 161        /// <summary> Deletes the specified load balancer inbound nat rule. </summary>
 162        /// <param name="resourceGroupName"> The name of the resource group. </param>
 163        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 164        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 165        /// <param name="cancellationToken"> The cancellation token to use. </param>
 166        public async Task<Response> DeleteAsync(string resourceGroupName, string loadBalancerName, string inboundNatRule
 167        {
 2168            if (resourceGroupName == null)
 169            {
 0170                throw new ArgumentNullException(nameof(resourceGroupName));
 171            }
 2172            if (loadBalancerName == null)
 173            {
 0174                throw new ArgumentNullException(nameof(loadBalancerName));
 175            }
 2176            if (inboundNatRuleName == null)
 177            {
 0178                throw new ArgumentNullException(nameof(inboundNatRuleName));
 179            }
 180
 2181            using var message = CreateDeleteRequest(resourceGroupName, loadBalancerName, inboundNatRuleName);
 2182            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2183            switch (message.Response.Status)
 184            {
 185                case 200:
 186                case 202:
 187                case 204:
 2188                    return message.Response;
 189                default:
 0190                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 191            }
 2192        }
 193
 194        /// <summary> Deletes the specified load balancer inbound nat rule. </summary>
 195        /// <param name="resourceGroupName"> The name of the resource group. </param>
 196        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 197        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 198        /// <param name="cancellationToken"> The cancellation token to use. </param>
 199        public Response Delete(string resourceGroupName, string loadBalancerName, string inboundNatRuleName, Cancellatio
 200        {
 2201            if (resourceGroupName == null)
 202            {
 0203                throw new ArgumentNullException(nameof(resourceGroupName));
 204            }
 2205            if (loadBalancerName == null)
 206            {
 0207                throw new ArgumentNullException(nameof(loadBalancerName));
 208            }
 2209            if (inboundNatRuleName == null)
 210            {
 0211                throw new ArgumentNullException(nameof(inboundNatRuleName));
 212            }
 213
 2214            using var message = CreateDeleteRequest(resourceGroupName, loadBalancerName, inboundNatRuleName);
 2215            _pipeline.Send(message, cancellationToken);
 2216            switch (message.Response.Status)
 217            {
 218                case 200:
 219                case 202:
 220                case 204:
 2221                    return message.Response;
 222                default:
 0223                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 224            }
 2225        }
 226
 227        internal HttpMessage CreateGetRequest(string resourceGroupName, string loadBalancerName, string inboundNatRuleNa
 228        {
 4229            var message = _pipeline.CreateMessage();
 4230            var request = message.Request;
 4231            request.Method = RequestMethod.Get;
 4232            var uri = new RawRequestUriBuilder();
 4233            uri.Reset(endpoint);
 4234            uri.AppendPath("/subscriptions/", false);
 4235            uri.AppendPath(subscriptionId, true);
 4236            uri.AppendPath("/resourceGroups/", false);
 4237            uri.AppendPath(resourceGroupName, true);
 4238            uri.AppendPath("/providers/Microsoft.Network/loadBalancers/", false);
 4239            uri.AppendPath(loadBalancerName, true);
 4240            uri.AppendPath("/inboundNatRules/", false);
 4241            uri.AppendPath(inboundNatRuleName, true);
 4242            uri.AppendQuery("api-version", "2020-04-01", true);
 4243            if (expand != null)
 244            {
 0245                uri.AppendQuery("$expand", expand, true);
 246            }
 4247            request.Uri = uri;
 4248            return message;
 249        }
 250
 251        /// <summary> Gets the specified load balancer inbound nat rule. </summary>
 252        /// <param name="resourceGroupName"> The name of the resource group. </param>
 253        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 254        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 255        /// <param name="expand"> Expands referenced resources. </param>
 256        /// <param name="cancellationToken"> The cancellation token to use. </param>
 257        public async Task<Response<InboundNatRule>> GetAsync(string resourceGroupName, string loadBalancerName, string i
 258        {
 2259            if (resourceGroupName == null)
 260            {
 0261                throw new ArgumentNullException(nameof(resourceGroupName));
 262            }
 2263            if (loadBalancerName == null)
 264            {
 0265                throw new ArgumentNullException(nameof(loadBalancerName));
 266            }
 2267            if (inboundNatRuleName == null)
 268            {
 0269                throw new ArgumentNullException(nameof(inboundNatRuleName));
 270            }
 271
 2272            using var message = CreateGetRequest(resourceGroupName, loadBalancerName, inboundNatRuleName, expand);
 2273            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2274            switch (message.Response.Status)
 275            {
 276                case 200:
 277                    {
 2278                        InboundNatRule value = default;
 2279                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2280                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 281                        {
 0282                            value = null;
 283                        }
 284                        else
 285                        {
 2286                            value = InboundNatRule.DeserializeInboundNatRule(document.RootElement);
 287                        }
 2288                        return Response.FromValue(value, message.Response);
 289                    }
 290                default:
 0291                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 292            }
 2293        }
 294
 295        /// <summary> Gets the specified load balancer inbound nat rule. </summary>
 296        /// <param name="resourceGroupName"> The name of the resource group. </param>
 297        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 298        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 299        /// <param name="expand"> Expands referenced resources. </param>
 300        /// <param name="cancellationToken"> The cancellation token to use. </param>
 301        public Response<InboundNatRule> Get(string resourceGroupName, string loadBalancerName, string inboundNatRuleName
 302        {
 2303            if (resourceGroupName == null)
 304            {
 0305                throw new ArgumentNullException(nameof(resourceGroupName));
 306            }
 2307            if (loadBalancerName == null)
 308            {
 0309                throw new ArgumentNullException(nameof(loadBalancerName));
 310            }
 2311            if (inboundNatRuleName == null)
 312            {
 0313                throw new ArgumentNullException(nameof(inboundNatRuleName));
 314            }
 315
 2316            using var message = CreateGetRequest(resourceGroupName, loadBalancerName, inboundNatRuleName, expand);
 2317            _pipeline.Send(message, cancellationToken);
 2318            switch (message.Response.Status)
 319            {
 320                case 200:
 321                    {
 2322                        InboundNatRule value = default;
 2323                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2324                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 325                        {
 0326                            value = null;
 327                        }
 328                        else
 329                        {
 2330                            value = InboundNatRule.DeserializeInboundNatRule(document.RootElement);
 331                        }
 2332                        return Response.FromValue(value, message.Response);
 333                    }
 334                default:
 0335                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 336            }
 2337        }
 338
 339        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string loadBalancerName, string inbou
 340        {
 8341            var message = _pipeline.CreateMessage();
 8342            var request = message.Request;
 8343            request.Method = RequestMethod.Put;
 8344            var uri = new RawRequestUriBuilder();
 8345            uri.Reset(endpoint);
 8346            uri.AppendPath("/subscriptions/", false);
 8347            uri.AppendPath(subscriptionId, true);
 8348            uri.AppendPath("/resourceGroups/", false);
 8349            uri.AppendPath(resourceGroupName, true);
 8350            uri.AppendPath("/providers/Microsoft.Network/loadBalancers/", false);
 8351            uri.AppendPath(loadBalancerName, true);
 8352            uri.AppendPath("/inboundNatRules/", false);
 8353            uri.AppendPath(inboundNatRuleName, true);
 8354            uri.AppendQuery("api-version", "2020-04-01", true);
 8355            request.Uri = uri;
 8356            request.Headers.Add("Content-Type", "application/json");
 8357            var content = new Utf8JsonRequestContent();
 8358            content.JsonWriter.WriteObjectValue(inboundNatRuleParameters);
 8359            request.Content = content;
 8360            return message;
 361        }
 362
 363        /// <summary> Creates or updates a load balancer inbound nat rule. </summary>
 364        /// <param name="resourceGroupName"> The name of the resource group. </param>
 365        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 366        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 367        /// <param name="inboundNatRuleParameters"> Parameters supplied to the create or update inbound nat rule operati
 368        /// <param name="cancellationToken"> The cancellation token to use. </param>
 369        public async Task<Response> CreateOrUpdateAsync(string resourceGroupName, string loadBalancerName, string inboun
 370        {
 2371            if (resourceGroupName == null)
 372            {
 0373                throw new ArgumentNullException(nameof(resourceGroupName));
 374            }
 2375            if (loadBalancerName == null)
 376            {
 0377                throw new ArgumentNullException(nameof(loadBalancerName));
 378            }
 2379            if (inboundNatRuleName == null)
 380            {
 0381                throw new ArgumentNullException(nameof(inboundNatRuleName));
 382            }
 2383            if (inboundNatRuleParameters == null)
 384            {
 0385                throw new ArgumentNullException(nameof(inboundNatRuleParameters));
 386            }
 387
 2388            using var message = CreateCreateOrUpdateRequest(resourceGroupName, loadBalancerName, inboundNatRuleName, inb
 2389            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2390            switch (message.Response.Status)
 391            {
 392                case 200:
 393                case 201:
 2394                    return message.Response;
 395                default:
 0396                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 397            }
 2398        }
 399
 400        /// <summary> Creates or updates a load balancer inbound nat rule. </summary>
 401        /// <param name="resourceGroupName"> The name of the resource group. </param>
 402        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 403        /// <param name="inboundNatRuleName"> The name of the inbound nat rule. </param>
 404        /// <param name="inboundNatRuleParameters"> Parameters supplied to the create or update inbound nat rule operati
 405        /// <param name="cancellationToken"> The cancellation token to use. </param>
 406        public Response CreateOrUpdate(string resourceGroupName, string loadBalancerName, string inboundNatRuleName, Inb
 407        {
 2408            if (resourceGroupName == null)
 409            {
 0410                throw new ArgumentNullException(nameof(resourceGroupName));
 411            }
 2412            if (loadBalancerName == null)
 413            {
 0414                throw new ArgumentNullException(nameof(loadBalancerName));
 415            }
 2416            if (inboundNatRuleName == null)
 417            {
 0418                throw new ArgumentNullException(nameof(inboundNatRuleName));
 419            }
 2420            if (inboundNatRuleParameters == null)
 421            {
 0422                throw new ArgumentNullException(nameof(inboundNatRuleParameters));
 423            }
 424
 2425            using var message = CreateCreateOrUpdateRequest(resourceGroupName, loadBalancerName, inboundNatRuleName, inb
 2426            _pipeline.Send(message, cancellationToken);
 2427            switch (message.Response.Status)
 428            {
 429                case 200:
 430                case 201:
 2431                    return message.Response;
 432                default:
 0433                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 434            }
 2435        }
 436
 437        internal HttpMessage CreateListNextPageRequest(string nextLink, string resourceGroupName, string loadBalancerNam
 438        {
 0439            var message = _pipeline.CreateMessage();
 0440            var request = message.Request;
 0441            request.Method = RequestMethod.Get;
 0442            var uri = new RawRequestUriBuilder();
 0443            uri.Reset(endpoint);
 0444            uri.AppendRawNextLink(nextLink, false);
 0445            request.Uri = uri;
 0446            return message;
 447        }
 448
 449        /// <summary> Gets all the inbound nat rules in a load balancer. </summary>
 450        /// <param name="nextLink"> The URL to the next page of results. </param>
 451        /// <param name="resourceGroupName"> The name of the resource group. </param>
 452        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 453        /// <param name="cancellationToken"> The cancellation token to use. </param>
 454        public async Task<Response<InboundNatRuleListResult>> ListNextPageAsync(string nextLink, string resourceGroupNam
 455        {
 0456            if (nextLink == null)
 457            {
 0458                throw new ArgumentNullException(nameof(nextLink));
 459            }
 0460            if (resourceGroupName == null)
 461            {
 0462                throw new ArgumentNullException(nameof(resourceGroupName));
 463            }
 0464            if (loadBalancerName == null)
 465            {
 0466                throw new ArgumentNullException(nameof(loadBalancerName));
 467            }
 468
 0469            using var message = CreateListNextPageRequest(nextLink, resourceGroupName, loadBalancerName);
 0470            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0471            switch (message.Response.Status)
 472            {
 473                case 200:
 474                    {
 0475                        InboundNatRuleListResult value = default;
 0476                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0477                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 478                        {
 0479                            value = null;
 480                        }
 481                        else
 482                        {
 0483                            value = InboundNatRuleListResult.DeserializeInboundNatRuleListResult(document.RootElement);
 484                        }
 0485                        return Response.FromValue(value, message.Response);
 486                    }
 487                default:
 0488                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 489            }
 0490        }
 491
 492        /// <summary> Gets all the inbound nat rules in a load balancer. </summary>
 493        /// <param name="nextLink"> The URL to the next page of results. </param>
 494        /// <param name="resourceGroupName"> The name of the resource group. </param>
 495        /// <param name="loadBalancerName"> The name of the load balancer. </param>
 496        /// <param name="cancellationToken"> The cancellation token to use. </param>
 497        public Response<InboundNatRuleListResult> ListNextPage(string nextLink, string resourceGroupName, string loadBal
 498        {
 0499            if (nextLink == null)
 500            {
 0501                throw new ArgumentNullException(nameof(nextLink));
 502            }
 0503            if (resourceGroupName == null)
 504            {
 0505                throw new ArgumentNullException(nameof(resourceGroupName));
 506            }
 0507            if (loadBalancerName == null)
 508            {
 0509                throw new ArgumentNullException(nameof(loadBalancerName));
 510            }
 511
 0512            using var message = CreateListNextPageRequest(nextLink, resourceGroupName, loadBalancerName);
 0513            _pipeline.Send(message, cancellationToken);
 0514            switch (message.Response.Status)
 515            {
 516                case 200:
 517                    {
 0518                        InboundNatRuleListResult value = default;
 0519                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0520                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 521                        {
 0522                            value = null;
 523                        }
 524                        else
 525                        {
 0526                            value = InboundNatRuleListResult.DeserializeInboundNatRuleListResult(document.RootElement);
 527                        }
 0528                        return Response.FromValue(value, message.Response);
 529                    }
 530                default:
 0531                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 532            }
 0533        }
 534    }
 535}