< Summary

Class:Microsoft.Azure.Attestation.SigningCertificatesOperations
Assembly:Microsoft.Azure.Attestation
File(s):C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Generated\SigningCertificatesOperations.cs
Covered lines:48
Uncovered lines:49
Coverable lines:97
Total lines:249
Line coverage:49.4% (48 of 97)
Covered branches:24
Total branches:56
Branch coverage:42.8% (24 of 56)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
GetWithHttpMessagesAsync()-47.25%42.59%

File(s)

C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Generated\SigningCertificatesOperations.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.Attestation
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.Linq;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Threading;
 23    using System.Threading.Tasks;
 24
 25    /// <summary>
 26    /// SigningCertificatesOperations operations.
 27    /// </summary>
 28    internal partial class SigningCertificatesOperations : IServiceOperations<AttestationClient>, ISigningCertificatesOp
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the SigningCertificatesOperations class.
 32        /// </summary>
 33        /// <param name='client'>
 34        /// Reference to the service client.
 35        /// </param>
 36        /// <exception cref="System.ArgumentNullException">
 37        /// Thrown when a required parameter is null
 38        /// </exception>
 839        internal SigningCertificatesOperations(AttestationClient client)
 40        {
 841            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 845            Client = client;
 846        }
 47
 48        /// <summary>
 49        /// Gets a reference to the AttestationClient
 50        /// </summary>
 2651        public AttestationClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Retrieves the OpenID Configuration data for the Azure Attestation Service
 55        /// </summary>
 56        /// <remarks>
 57        /// Retrieves attestation signing keys in use by the attestation service
 58        /// </remarks>
 59        /// <param name='tenantBaseUrl'>
 60        /// The tenant name, for example https://mytenant.attest.azure.net.
 61        /// </param>
 62        /// <param name='customHeaders'>
 63        /// Headers that will be added to request.
 64        /// </param>
 65        /// <param name='cancellationToken'>
 66        /// The cancellation token.
 67        /// </param>
 68        /// <exception cref="CloudException">
 69        /// Thrown when the operation returned an invalid status code
 70        /// </exception>
 71        /// <exception cref="SerializationException">
 72        /// Thrown when unable to deserialize the response
 73        /// </exception>
 74        /// <exception cref="ValidationException">
 75        /// Thrown when a required parameter is null
 76        /// </exception>
 77        /// <exception cref="System.ArgumentNullException">
 78        /// Thrown when a required parameter is null
 79        /// </exception>
 80        /// <return>
 81        /// A response object containing the response body and response headers.
 82        /// </return>
 83        public async Task<AzureOperationResponse<object>> GetWithHttpMessagesAsync(string tenantBaseUrl, Dictionary<stri
 84        {
 285            if (tenantBaseUrl == null)
 86            {
 087                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 88            }
 89            // Tracing
 290            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 291            string _invocationId = null;
 292            if (_shouldTrace)
 93            {
 094                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 095                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 096                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 097                tracingParameters.Add("cancellationToken", cancellationToken);
 098                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 99            }
 100            // Construct URL
 2101            var _baseUrl = Client.BaseUri;
 2102            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certs";
 2103            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2104            List<string> _queryParameters = new List<string>();
 2105            if (_queryParameters.Count > 0)
 106            {
 0107                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 108            }
 109            // Create HTTP transport objects
 2110            var _httpRequest = new HttpRequestMessage();
 2111            HttpResponseMessage _httpResponse = null;
 2112            _httpRequest.Method = new HttpMethod("GET");
 2113            _httpRequest.RequestUri = new System.Uri(_url);
 114            // Set Headers
 2115            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 116            {
 2117                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 118            }
 2119            if (Client.AcceptLanguage != null)
 120            {
 2121                if (_httpRequest.Headers.Contains("accept-language"))
 122                {
 0123                    _httpRequest.Headers.Remove("accept-language");
 124                }
 2125                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 126            }
 127
 128
 2129            if (customHeaders != null)
 130            {
 0131                foreach(var _header in customHeaders)
 132                {
 0133                    if (_httpRequest.Headers.Contains(_header.Key))
 134                    {
 0135                        _httpRequest.Headers.Remove(_header.Key);
 136                    }
 0137                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 138                }
 139            }
 140
 141            // Serialize Request
 2142            string _requestContent = null;
 143            // Set Credentials
 2144            if (Client.Credentials != null)
 145            {
 2146                cancellationToken.ThrowIfCancellationRequested();
 2147                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 148            }
 149            // Send Request
 2150            if (_shouldTrace)
 151            {
 0152                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 153            }
 2154            cancellationToken.ThrowIfCancellationRequested();
 2155            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2156            if (_shouldTrace)
 157            {
 0158                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 159            }
 2160            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2161            cancellationToken.ThrowIfCancellationRequested();
 2162            string _responseContent = null;
 2163            if ((int)_statusCode != 200 && (int)_statusCode != 400)
 164            {
 0165                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 166                try
 167                {
 0168                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0169                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0170                    if (_errorBody != null)
 171                    {
 0172                        ex = new CloudException(_errorBody.Message);
 0173                        ex.Body = _errorBody;
 174                    }
 0175                }
 0176                catch (JsonException)
 177                {
 178                    // Ignore the exception
 0179                }
 0180                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0181                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0182                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 183                {
 0184                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 185                }
 0186                if (_shouldTrace)
 187                {
 0188                    ServiceClientTracing.Error(_invocationId, ex);
 189                }
 0190                _httpRequest.Dispose();
 0191                if (_httpResponse != null)
 192                {
 0193                    _httpResponse.Dispose();
 194                }
 0195                throw ex;
 196            }
 197            // Create Result
 2198            var _result = new AzureOperationResponse<object>();
 2199            _result.Request = _httpRequest;
 2200            _result.Response = _httpResponse;
 2201            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 202            {
 0203                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 204            }
 205            // Deserialize Response
 2206            if ((int)_statusCode == 200)
 207            {
 2208                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 209                try
 210                {
 2211                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<object>(_responseContent, Client
 2212                }
 0213                catch (JsonException ex)
 214                {
 0215                    _httpRequest.Dispose();
 0216                    if (_httpResponse != null)
 217                    {
 0218                        _httpResponse.Dispose();
 219                    }
 0220                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 221                }
 222            }
 223            // Deserialize Response
 2224            if ((int)_statusCode == 400)
 225            {
 0226                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 227                try
 228                {
 0229                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0230                }
 0231                catch (JsonException ex)
 232                {
 0233                    _httpRequest.Dispose();
 0234                    if (_httpResponse != null)
 235                    {
 0236                        _httpResponse.Dispose();
 237                    }
 0238                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 239                }
 240            }
 2241            if (_shouldTrace)
 242            {
 0243                ServiceClientTracing.Exit(_invocationId, _result);
 244            }
 2245            return _result;
 2246        }
 247
 248    }
 249}