< Summary

Class:Microsoft.Azure.ContainerRegistry.V2SupportOperations
Assembly:Microsoft.Azure.ContainerRegistry
File(s):C:\Git\azure-sdk-for-net\sdk\containerregistry\Microsoft.Azure.ContainerRegistry\src\Generated\V2SupportOperations.cs
Covered lines:4
Uncovered lines:71
Coverable lines:75
Total lines:199
Line coverage:5.3% (4 of 75)
Covered branches:1
Total branches:44
Branch coverage:2.2% (1 of 44)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-0%100%
CheckWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\containerregistry\Microsoft.Azure.ContainerRegistry\src\Generated\V2SupportOperations.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.ContainerRegistry
 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    /// V2SupportOperations operations.
 27    /// </summary>
 28    internal partial class V2SupportOperations : IServiceOperations<AzureContainerRegistryClient>, IV2SupportOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the V2SupportOperations 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>
 6039        internal V2SupportOperations(AzureContainerRegistryClient client)
 40        {
 6041            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 6045            Client = client;
 6046        }
 47
 48        /// <summary>
 49        /// Gets a reference to the AzureContainerRegistryClient
 50        /// </summary>
 051        public AzureContainerRegistryClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Tells whether this Docker Registry instance supports Docker Registry HTTP
 55        /// API v2
 56        /// </summary>
 57        /// <param name='customHeaders'>
 58        /// Headers that will be added to request.
 59        /// </param>
 60        /// <param name='cancellationToken'>
 61        /// The cancellation token.
 62        /// </param>
 63        /// <exception cref="AcrErrorsException">
 64        /// Thrown when the operation returned an invalid status code
 65        /// </exception>
 66        /// <exception cref="ValidationException">
 67        /// Thrown when a required parameter is null
 68        /// </exception>
 69        /// <exception cref="System.ArgumentNullException">
 70        /// Thrown when a required parameter is null
 71        /// </exception>
 72        /// <return>
 73        /// A response object containing the response body and response headers.
 74        /// </return>
 75        public async Task<AzureOperationResponse> CheckWithHttpMessagesAsync(Dictionary<string, List<string>> customHead
 76        {
 077            if (Client.LoginUri == null)
 78            {
 079                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 80            }
 81            // Tracing
 082            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 083            string _invocationId = null;
 084            if (_shouldTrace)
 85            {
 086                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 087                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 088                tracingParameters.Add("cancellationToken", cancellationToken);
 089                ServiceClientTracing.Enter(_invocationId, this, "Check", tracingParameters);
 90            }
 91            // Construct URL
 092            var _baseUrl = Client.BaseUri;
 093            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/";
 094            _url = _url.Replace("{url}", Client.LoginUri);
 095            List<string> _queryParameters = new List<string>();
 096            if (_queryParameters.Count > 0)
 97            {
 098                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 99            }
 100            // Create HTTP transport objects
 0101            var _httpRequest = new HttpRequestMessage();
 0102            HttpResponseMessage _httpResponse = null;
 0103            _httpRequest.Method = new HttpMethod("GET");
 0104            _httpRequest.RequestUri = new System.Uri(_url);
 105            // Set Headers
 0106            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 107            {
 0108                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 109            }
 0110            if (Client.AcceptLanguage != null)
 111            {
 0112                if (_httpRequest.Headers.Contains("accept-language"))
 113                {
 0114                    _httpRequest.Headers.Remove("accept-language");
 115                }
 0116                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 117            }
 118
 119
 0120            if (customHeaders != null)
 121            {
 0122                foreach(var _header in customHeaders)
 123                {
 0124                    if (_httpRequest.Headers.Contains(_header.Key))
 125                    {
 0126                        _httpRequest.Headers.Remove(_header.Key);
 127                    }
 0128                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 129                }
 130            }
 131
 132            // Serialize Request
 0133            string _requestContent = null;
 134            // Set Credentials
 0135            if (Client.Credentials != null)
 136            {
 0137                cancellationToken.ThrowIfCancellationRequested();
 0138                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 139            }
 140            // Send Request
 0141            if (_shouldTrace)
 142            {
 0143                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 144            }
 0145            cancellationToken.ThrowIfCancellationRequested();
 0146            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0147            if (_shouldTrace)
 148            {
 0149                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 150            }
 0151            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0152            cancellationToken.ThrowIfCancellationRequested();
 0153            string _responseContent = null;
 0154            if ((int)_statusCode != 200)
 155            {
 0156                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 157                try
 158                {
 0159                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0160                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 0161                    if (_errorBody != null)
 162                    {
 0163                        ex.Body = _errorBody;
 164                    }
 0165                }
 0166                catch (JsonException)
 167                {
 168                    // Ignore the exception
 0169                }
 0170                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0171                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0172                if (_shouldTrace)
 173                {
 0174                    ServiceClientTracing.Error(_invocationId, ex);
 175                }
 0176                _httpRequest.Dispose();
 0177                if (_httpResponse != null)
 178                {
 0179                    _httpResponse.Dispose();
 180                }
 0181                throw ex;
 182            }
 183            // Create Result
 0184            var _result = new AzureOperationResponse();
 0185            _result.Request = _httpRequest;
 0186            _result.Response = _httpResponse;
 0187            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 188            {
 0189                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 190            }
 0191            if (_shouldTrace)
 192            {
 0193                ServiceClientTracing.Exit(_invocationId, _result);
 194            }
 0195            return _result;
 0196        }
 197
 198    }
 199}