< Summary

Class:Microsoft.Azure.Attestation.MetadataConfigurationOperations
Assembly:Microsoft.Azure.Attestation
File(s):C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Generated\MetadataConfigurationOperations.cs
Covered lines:48
Uncovered lines:49
Coverable lines:97
Total lines:250
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\MetadataConfigurationOperations.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    /// MetadataConfigurationOperations operations.
 27    /// </summary>
 28    internal partial class MetadataConfigurationOperations : IServiceOperations<AttestationClient>, IMetadataConfigurati
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the MetadataConfigurationOperations 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 MetadataConfigurationOperations(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 metadata about the attestation signing keys in use by the
 58        /// attestation service
 59        /// </remarks>
 60        /// <param name='tenantBaseUrl'>
 61        /// The tenant name, for example https://mytenant.attest.azure.net.
 62        /// </param>
 63        /// <param name='customHeaders'>
 64        /// Headers that will be added to request.
 65        /// </param>
 66        /// <param name='cancellationToken'>
 67        /// The cancellation token.
 68        /// </param>
 69        /// <exception cref="CloudException">
 70        /// Thrown when the operation returned an invalid status code
 71        /// </exception>
 72        /// <exception cref="SerializationException">
 73        /// Thrown when unable to deserialize the response
 74        /// </exception>
 75        /// <exception cref="ValidationException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <exception cref="System.ArgumentNullException">
 79        /// Thrown when a required parameter is null
 80        /// </exception>
 81        /// <return>
 82        /// A response object containing the response body and response headers.
 83        /// </return>
 84        public async Task<AzureOperationResponse<object>> GetWithHttpMessagesAsync(string tenantBaseUrl, Dictionary<stri
 85        {
 286            if (tenantBaseUrl == null)
 87            {
 088                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 89            }
 90            // Tracing
 291            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 292            string _invocationId = null;
 293            if (_shouldTrace)
 94            {
 095                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 096                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 097                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 098                tracingParameters.Add("cancellationToken", cancellationToken);
 099                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 100            }
 101            // Construct URL
 2102            var _baseUrl = Client.BaseUri;
 2103            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + ".well-known/openid-configuration";
 2104            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2105            List<string> _queryParameters = new List<string>();
 2106            if (_queryParameters.Count > 0)
 107            {
 0108                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 109            }
 110            // Create HTTP transport objects
 2111            var _httpRequest = new HttpRequestMessage();
 2112            HttpResponseMessage _httpResponse = null;
 2113            _httpRequest.Method = new HttpMethod("GET");
 2114            _httpRequest.RequestUri = new System.Uri(_url);
 115            // Set Headers
 2116            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 117            {
 2118                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 119            }
 2120            if (Client.AcceptLanguage != null)
 121            {
 2122                if (_httpRequest.Headers.Contains("accept-language"))
 123                {
 0124                    _httpRequest.Headers.Remove("accept-language");
 125                }
 2126                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 127            }
 128
 129
 2130            if (customHeaders != null)
 131            {
 0132                foreach(var _header in customHeaders)
 133                {
 0134                    if (_httpRequest.Headers.Contains(_header.Key))
 135                    {
 0136                        _httpRequest.Headers.Remove(_header.Key);
 137                    }
 0138                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 139                }
 140            }
 141
 142            // Serialize Request
 2143            string _requestContent = null;
 144            // Set Credentials
 2145            if (Client.Credentials != null)
 146            {
 2147                cancellationToken.ThrowIfCancellationRequested();
 2148                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 149            }
 150            // Send Request
 2151            if (_shouldTrace)
 152            {
 0153                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 154            }
 2155            cancellationToken.ThrowIfCancellationRequested();
 2156            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2157            if (_shouldTrace)
 158            {
 0159                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 160            }
 2161            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2162            cancellationToken.ThrowIfCancellationRequested();
 2163            string _responseContent = null;
 2164            if ((int)_statusCode != 200 && (int)_statusCode != 400)
 165            {
 0166                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 167                try
 168                {
 0169                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0170                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0171                    if (_errorBody != null)
 172                    {
 0173                        ex = new CloudException(_errorBody.Message);
 0174                        ex.Body = _errorBody;
 175                    }
 0176                }
 0177                catch (JsonException)
 178                {
 179                    // Ignore the exception
 0180                }
 0181                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0182                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0183                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 184                {
 0185                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 186                }
 0187                if (_shouldTrace)
 188                {
 0189                    ServiceClientTracing.Error(_invocationId, ex);
 190                }
 0191                _httpRequest.Dispose();
 0192                if (_httpResponse != null)
 193                {
 0194                    _httpResponse.Dispose();
 195                }
 0196                throw ex;
 197            }
 198            // Create Result
 2199            var _result = new AzureOperationResponse<object>();
 2200            _result.Request = _httpRequest;
 2201            _result.Response = _httpResponse;
 2202            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 203            {
 0204                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 205            }
 206            // Deserialize Response
 2207            if ((int)_statusCode == 200)
 208            {
 2209                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 210                try
 211                {
 2212                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<object>(_responseContent, Client
 2213                }
 0214                catch (JsonException ex)
 215                {
 0216                    _httpRequest.Dispose();
 0217                    if (_httpResponse != null)
 218                    {
 0219                        _httpResponse.Dispose();
 220                    }
 0221                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 222                }
 223            }
 224            // Deserialize Response
 2225            if ((int)_statusCode == 400)
 226            {
 0227                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 228                try
 229                {
 0230                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0231                }
 0232                catch (JsonException ex)
 233                {
 0234                    _httpRequest.Dispose();
 0235                    if (_httpResponse != null)
 236                    {
 0237                        _httpResponse.Dispose();
 238                    }
 0239                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 240                }
 241            }
 2242            if (_shouldTrace)
 243            {
 0244                ServiceClientTracing.Exit(_invocationId, _result);
 245            }
 2246            return _result;
 2247        }
 248
 249    }
 250}