< Summary

Class:Microsoft.Azure.Management.Search.Operations
Assembly:Microsoft.Azure.Management.Search
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\src\Generated\Operations.cs
Covered lines:4
Uncovered lines:84
Coverable lines:88
Total lines:228
Line coverage:4.5% (4 of 88)
Covered branches:1
Total branches:52
Branch coverage:1.9% (1 of 52)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\src\Generated\Operations.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.Management.Search
 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    /// Operations operations.
 27    /// </summary>
 28    internal partial class Operations : IServiceOperations<SearchManagementClient>, IOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Operations 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>
 120439        internal Operations(SearchManagementClient client)
 40        {
 120441            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 120445            Client = client;
 120446        }
 47
 48        /// <summary>
 49        /// Gets a reference to the SearchManagementClient
 50        /// </summary>
 051        public SearchManagementClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Lists all of the available REST API operations of the Microsoft.Search
 55        /// provider.
 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="CloudException">
 64        /// Thrown when the operation returned an invalid status code
 65        /// </exception>
 66        /// <exception cref="SerializationException">
 67        /// Thrown when unable to deserialize the response
 68        /// </exception>
 69        /// <exception cref="ValidationException">
 70        /// Thrown when a required parameter is null
 71        /// </exception>
 72        /// <exception cref="System.ArgumentNullException">
 73        /// Thrown when a required parameter is null
 74        /// </exception>
 75        /// <return>
 76        /// A response object containing the response body and response headers.
 77        /// </return>
 78        public async Task<AzureOperationResponse<IEnumerable<Operation>>> ListWithHttpMessagesAsync(Dictionary<string, L
 79        {
 080            if (Client.ApiVersion == null)
 81            {
 082                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 83            }
 84            // Tracing
 085            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 086            string _invocationId = null;
 087            if (_shouldTrace)
 88            {
 089                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 090                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 091                tracingParameters.Add("cancellationToken", cancellationToken);
 092                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 93            }
 94            // Construct URL
 095            var _baseUrl = Client.BaseUri.AbsoluteUri;
 096            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "providers/Microso
 097            List<string> _queryParameters = new List<string>();
 098            if (Client.ApiVersion != null)
 99            {
 0100                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 101            }
 0102            if (_queryParameters.Count > 0)
 103            {
 0104                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 105            }
 106            // Create HTTP transport objects
 0107            var _httpRequest = new HttpRequestMessage();
 0108            HttpResponseMessage _httpResponse = null;
 0109            _httpRequest.Method = new HttpMethod("GET");
 0110            _httpRequest.RequestUri = new System.Uri(_url);
 111            // Set Headers
 0112            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 113            {
 0114                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 115            }
 0116            if (Client.AcceptLanguage != null)
 117            {
 0118                if (_httpRequest.Headers.Contains("accept-language"))
 119                {
 0120                    _httpRequest.Headers.Remove("accept-language");
 121                }
 0122                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 123            }
 124
 125
 0126            if (customHeaders != null)
 127            {
 0128                foreach(var _header in customHeaders)
 129                {
 0130                    if (_httpRequest.Headers.Contains(_header.Key))
 131                    {
 0132                        _httpRequest.Headers.Remove(_header.Key);
 133                    }
 0134                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 135                }
 136            }
 137
 138            // Serialize Request
 0139            string _requestContent = null;
 140            // Set Credentials
 0141            if (Client.Credentials != null)
 142            {
 0143                cancellationToken.ThrowIfCancellationRequested();
 0144                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 145            }
 146            // Send Request
 0147            if (_shouldTrace)
 148            {
 0149                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 150            }
 0151            cancellationToken.ThrowIfCancellationRequested();
 0152            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0153            if (_shouldTrace)
 154            {
 0155                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 156            }
 0157            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0158            cancellationToken.ThrowIfCancellationRequested();
 0159            string _responseContent = null;
 0160            if ((int)_statusCode != 200)
 161            {
 0162                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 163                try
 164                {
 0165                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0166                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0167                    if (_errorBody != null)
 168                    {
 0169                        ex = new CloudException(_errorBody.Message);
 0170                        ex.Body = _errorBody;
 171                    }
 0172                }
 0173                catch (JsonException)
 174                {
 175                    // Ignore the exception
 0176                }
 0177                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0178                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0179                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 180                {
 0181                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 182                }
 0183                if (_shouldTrace)
 184                {
 0185                    ServiceClientTracing.Error(_invocationId, ex);
 186                }
 0187                _httpRequest.Dispose();
 0188                if (_httpResponse != null)
 189                {
 0190                    _httpResponse.Dispose();
 191                }
 0192                throw ex;
 193            }
 194            // Create Result
 0195            var _result = new AzureOperationResponse<IEnumerable<Operation>>();
 0196            _result.Request = _httpRequest;
 0197            _result.Response = _httpResponse;
 0198            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 199            {
 0200                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 201            }
 202            // Deserialize Response
 0203            if ((int)_statusCode == 200)
 204            {
 0205                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 206                try
 207                {
 0208                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<Operation>>(_responseConten
 0209                }
 0210                catch (JsonException ex)
 211                {
 0212                    _httpRequest.Dispose();
 0213                    if (_httpResponse != null)
 214                    {
 0215                        _httpResponse.Dispose();
 216                    }
 0217                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 218                }
 219            }
 0220            if (_shouldTrace)
 221            {
 0222                ServiceClientTracing.Exit(_invocationId, _result);
 223            }
 0224            return _result;
 0225        }
 226
 227    }
 228}