< Summary

Class:Azure.Template.ServiceRestClient
Assembly:Azure.Template
File(s):C:\Git\azure-sdk-for-net\sdk\template\Azure.Template\src\Generated\ServiceRestClient.cs
Covered lines:34
Uncovered lines:6
Coverable lines:40
Total lines:117
Line coverage:85% (34 of 40)
Covered branches:6
Total branches:12
Branch coverage:50% (6 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
CreateGetSecretRequest(...)-100%100%
GetSecretAsync()-80%50%
GetSecret(...)-80%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\template\Azure.Template\src\Generated\ServiceRestClient.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.Template.Models;
 16
 17namespace Azure.Template
 18{
 19    internal partial class ServiceRestClient
 20    {
 21        private string vaultBaseUrl;
 22        private string apiVersion;
 23        private ClientDiagnostics _clientDiagnostics;
 24        private HttpPipeline _pipeline;
 25
 26        /// <summary> Initializes a new instance of ServiceRestClient. </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="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 30        /// <param name="apiVersion"> Api Version. </param>
 31        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="apiVersion"/> is
 432        public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl, string
 33        {
 434            if (vaultBaseUrl == null)
 35            {
 036                throw new ArgumentNullException(nameof(vaultBaseUrl));
 37            }
 438            if (apiVersion == null)
 39            {
 040                throw new ArgumentNullException(nameof(apiVersion));
 41            }
 42
 443            this.vaultBaseUrl = vaultBaseUrl;
 444            this.apiVersion = apiVersion;
 445            _clientDiagnostics = clientDiagnostics;
 446            _pipeline = pipeline;
 447        }
 48
 49        internal HttpMessage CreateGetSecretRequest(string secretName)
 50        {
 451            var message = _pipeline.CreateMessage();
 452            var request = message.Request;
 453            request.Method = RequestMethod.Get;
 454            var uri = new RawRequestUriBuilder();
 455            uri.AppendRaw(vaultBaseUrl, false);
 456            uri.AppendPath("/secrets/", false);
 457            uri.AppendPath(secretName, true);
 458            uri.AppendQuery("api-version", apiVersion, true);
 459            request.Uri = uri;
 460            return message;
 61        }
 62
 63        /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t
 64        /// <param name="secretName"> The name of the secret. </param>
 65        /// <param name="cancellationToken"> The cancellation token to use. </param>
 66        /// <exception cref="ArgumentNullException"> <paramref name="secretName"/> is null. </exception>
 67        public async Task<Response<SecretBundle>> GetSecretAsync(string secretName, CancellationToken cancellationToken 
 68        {
 269            if (secretName == null)
 70            {
 071                throw new ArgumentNullException(nameof(secretName));
 72            }
 73
 274            using var message = CreateGetSecretRequest(secretName);
 275            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 276            switch (message.Response.Status)
 77            {
 78                case 200:
 79                    {
 80                        SecretBundle value = default;
 281                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 282                        value = SecretBundle.DeserializeSecretBundle(document.RootElement);
 283                        return Response.FromValue(value, message.Response);
 84                    }
 85                default:
 086                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 87            }
 288        }
 89
 90        /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t
 91        /// <param name="secretName"> The name of the secret. </param>
 92        /// <param name="cancellationToken"> The cancellation token to use. </param>
 93        /// <exception cref="ArgumentNullException"> <paramref name="secretName"/> is null. </exception>
 94        public Response<SecretBundle> GetSecret(string secretName, CancellationToken cancellationToken = default)
 95        {
 296            if (secretName == null)
 97            {
 098                throw new ArgumentNullException(nameof(secretName));
 99            }
 100
 2101            using var message = CreateGetSecretRequest(secretName);
 2102            _pipeline.Send(message, cancellationToken);
 2103            switch (message.Response.Status)
 104            {
 105                case 200:
 106                    {
 107                        SecretBundle value = default;
 2108                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2109                        value = SecretBundle.DeserializeSecretBundle(document.RootElement);
 2110                        return Response.FromValue(value, message.Response);
 111                    }
 112                default:
 0113                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 114            }
 2115        }
 116    }
 117}