< Summary

Class:Microsoft.Azure.Management.Search.AdminKeysOperations
Assembly:Microsoft.Azure.Management.Search
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\src\Generated\AdminKeysOperations.cs
Covered lines:59
Uncovered lines:151
Coverable lines:210
Total lines:494
Line coverage:28% (59 of 210)
Covered branches:32
Total branches:126
Branch coverage:25.3% (32 of 126)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\src\Generated\AdminKeysOperations.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    /// AdminKeysOperations operations.
 27    /// </summary>
 28    internal partial class AdminKeysOperations : IServiceOperations<SearchManagementClient>, IAdminKeysOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the AdminKeysOperations 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 AdminKeysOperations(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>
 963251        public SearchManagementClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Gets the primary and secondary admin API keys for the specified Azure
 55        /// Cognitive Search service.
 56        /// <see href="https://aka.ms/search-manage" />
 57        /// </summary>
 58        /// <param name='resourceGroupName'>
 59        /// The name of the resource group within the current subscription. You can
 60        /// obtain this value from the Azure Resource Manager API or the portal.
 61        /// </param>
 62        /// <param name='searchServiceName'>
 63        /// The name of the Azure Cognitive Search service associated with the
 64        /// specified resource group.
 65        /// </param>
 66        /// <param name='searchManagementRequestOptions'>
 67        /// Additional parameters for the operation
 68        /// </param>
 69        /// <param name='customHeaders'>
 70        /// Headers that will be added to request.
 71        /// </param>
 72        /// <param name='cancellationToken'>
 73        /// The cancellation token.
 74        /// </param>
 75        /// <exception cref="CloudException">
 76        /// Thrown when the operation returned an invalid status code
 77        /// </exception>
 78        /// <exception cref="SerializationException">
 79        /// Thrown when unable to deserialize the response
 80        /// </exception>
 81        /// <exception cref="ValidationException">
 82        /// Thrown when a required parameter is null
 83        /// </exception>
 84        /// <exception cref="System.ArgumentNullException">
 85        /// Thrown when a required parameter is null
 86        /// </exception>
 87        /// <return>
 88        /// A response object containing the response body and response headers.
 89        /// </return>
 90        public async Task<AzureOperationResponse<AdminKeyResult>> GetWithHttpMessagesAsync(string resourceGroupName, str
 91        {
 60292            if (resourceGroupName == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName");
 95            }
 60296            if (searchServiceName == null)
 97            {
 098                throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName");
 99            }
 602100            if (Client.ApiVersion == null)
 101            {
 0102                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 103            }
 602104            if (Client.SubscriptionId == null)
 105            {
 0106                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
 107            }
 602108            System.Guid? clientRequestId = default(System.Guid?);
 602109            if (searchManagementRequestOptions != null)
 110            {
 0111                clientRequestId = searchManagementRequestOptions.ClientRequestId;
 112            }
 113            // Tracing
 602114            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 602115            string _invocationId = null;
 602116            if (_shouldTrace)
 117            {
 0118                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0119                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0120                tracingParameters.Add("resourceGroupName", resourceGroupName);
 0121                tracingParameters.Add("searchServiceName", searchServiceName);
 0122                tracingParameters.Add("clientRequestId", clientRequestId);
 0123                tracingParameters.Add("cancellationToken", cancellationToken);
 0124                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 125            }
 126            // Construct URL
 602127            var _baseUrl = Client.BaseUri.AbsoluteUri;
 602128            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su
 602129            _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName));
 602130            _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName));
 602131            _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId));
 602132            List<string> _queryParameters = new List<string>();
 602133            if (Client.ApiVersion != null)
 134            {
 602135                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 136            }
 602137            if (_queryParameters.Count > 0)
 138            {
 602139                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 140            }
 141            // Create HTTP transport objects
 602142            var _httpRequest = new HttpRequestMessage();
 602143            HttpResponseMessage _httpResponse = null;
 602144            _httpRequest.Method = new HttpMethod("POST");
 602145            _httpRequest.RequestUri = new System.Uri(_url);
 146            // Set Headers
 602147            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 148            {
 602149                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 150            }
 602151            if (Client.AcceptLanguage != null)
 152            {
 602153                if (_httpRequest.Headers.Contains("accept-language"))
 154                {
 0155                    _httpRequest.Headers.Remove("accept-language");
 156                }
 602157                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 158            }
 602159            if (clientRequestId != null)
 160            {
 0161                if (_httpRequest.Headers.Contains("x-ms-client-request-id"))
 162                {
 0163                    _httpRequest.Headers.Remove("x-ms-client-request-id");
 164                }
 0165                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver
 166            }
 167
 168
 602169            if (customHeaders != null)
 170            {
 0171                foreach(var _header in customHeaders)
 172                {
 0173                    if (_httpRequest.Headers.Contains(_header.Key))
 174                    {
 0175                        _httpRequest.Headers.Remove(_header.Key);
 176                    }
 0177                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 178                }
 179            }
 180
 181            // Serialize Request
 602182            string _requestContent = null;
 183            // Set Credentials
 602184            if (Client.Credentials != null)
 185            {
 602186                cancellationToken.ThrowIfCancellationRequested();
 602187                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 188            }
 189            // Send Request
 602190            if (_shouldTrace)
 191            {
 0192                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 193            }
 602194            cancellationToken.ThrowIfCancellationRequested();
 602195            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 602196            if (_shouldTrace)
 197            {
 0198                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 199            }
 602200            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 602201            cancellationToken.ThrowIfCancellationRequested();
 602202            string _responseContent = null;
 602203            if ((int)_statusCode != 200)
 204            {
 0205                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 206                try
 207                {
 0208                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0209                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0210                    if (_errorBody != null)
 211                    {
 0212                        ex = new CloudException(_errorBody.Message);
 0213                        ex.Body = _errorBody;
 214                    }
 0215                }
 0216                catch (JsonException)
 217                {
 218                    // Ignore the exception
 0219                }
 0220                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0221                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0222                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 223                {
 0224                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 225                }
 0226                if (_shouldTrace)
 227                {
 0228                    ServiceClientTracing.Error(_invocationId, ex);
 229                }
 0230                _httpRequest.Dispose();
 0231                if (_httpResponse != null)
 232                {
 0233                    _httpResponse.Dispose();
 234                }
 0235                throw ex;
 236            }
 237            // Create Result
 602238            var _result = new AzureOperationResponse<AdminKeyResult>();
 602239            _result.Request = _httpRequest;
 602240            _result.Response = _httpResponse;
 602241            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 242            {
 602243                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 244            }
 245            // Deserialize Response
 602246            if ((int)_statusCode == 200)
 247            {
 602248                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 249                try
 250                {
 602251                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AdminKeyResult>(_responseContent
 602252                }
 0253                catch (JsonException ex)
 254                {
 0255                    _httpRequest.Dispose();
 0256                    if (_httpResponse != null)
 257                    {
 0258                        _httpResponse.Dispose();
 259                    }
 0260                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 261                }
 262            }
 602263            if (_shouldTrace)
 264            {
 0265                ServiceClientTracing.Exit(_invocationId, _result);
 266            }
 602267            return _result;
 602268        }
 269
 270        /// <summary>
 271        /// Regenerates either the primary or secondary admin API key. You can only
 272        /// regenerate one key at a time.
 273        /// <see href="https://aka.ms/search-manage" />
 274        /// </summary>
 275        /// <param name='resourceGroupName'>
 276        /// The name of the resource group within the current subscription. You can
 277        /// obtain this value from the Azure Resource Manager API or the portal.
 278        /// </param>
 279        /// <param name='searchServiceName'>
 280        /// The name of the Azure Cognitive Search service associated with the
 281        /// specified resource group.
 282        /// </param>
 283        /// <param name='keyKind'>
 284        /// Specifies which key to regenerate. Valid values include 'primary' and
 285        /// 'secondary'. Possible values include: 'primary', 'secondary'
 286        /// </param>
 287        /// <param name='searchManagementRequestOptions'>
 288        /// Additional parameters for the operation
 289        /// </param>
 290        /// <param name='customHeaders'>
 291        /// Headers that will be added to request.
 292        /// </param>
 293        /// <param name='cancellationToken'>
 294        /// The cancellation token.
 295        /// </param>
 296        /// <exception cref="CloudException">
 297        /// Thrown when the operation returned an invalid status code
 298        /// </exception>
 299        /// <exception cref="SerializationException">
 300        /// Thrown when unable to deserialize the response
 301        /// </exception>
 302        /// <exception cref="ValidationException">
 303        /// Thrown when a required parameter is null
 304        /// </exception>
 305        /// <exception cref="System.ArgumentNullException">
 306        /// Thrown when a required parameter is null
 307        /// </exception>
 308        /// <return>
 309        /// A response object containing the response body and response headers.
 310        /// </return>
 311        public async Task<AzureOperationResponse<AdminKeyResult>> RegenerateWithHttpMessagesAsync(string resourceGroupNa
 312        {
 0313            if (resourceGroupName == null)
 314            {
 0315                throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName");
 316            }
 0317            if (searchServiceName == null)
 318            {
 0319                throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName");
 320            }
 0321            if (Client.ApiVersion == null)
 322            {
 0323                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 324            }
 0325            if (Client.SubscriptionId == null)
 326            {
 0327                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
 328            }
 0329            System.Guid? clientRequestId = default(System.Guid?);
 0330            if (searchManagementRequestOptions != null)
 331            {
 0332                clientRequestId = searchManagementRequestOptions.ClientRequestId;
 333            }
 334            // Tracing
 0335            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0336            string _invocationId = null;
 0337            if (_shouldTrace)
 338            {
 0339                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0340                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0341                tracingParameters.Add("resourceGroupName", resourceGroupName);
 0342                tracingParameters.Add("searchServiceName", searchServiceName);
 0343                tracingParameters.Add("keyKind", keyKind);
 0344                tracingParameters.Add("clientRequestId", clientRequestId);
 0345                tracingParameters.Add("cancellationToken", cancellationToken);
 0346                ServiceClientTracing.Enter(_invocationId, this, "Regenerate", tracingParameters);
 347            }
 348            // Construct URL
 0349            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0350            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su
 0351            _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName));
 0352            _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName));
 0353            _url = _url.Replace("{keyKind}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj
 0354            _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId));
 0355            List<string> _queryParameters = new List<string>();
 0356            if (Client.ApiVersion != null)
 357            {
 0358                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 359            }
 0360            if (_queryParameters.Count > 0)
 361            {
 0362                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 363            }
 364            // Create HTTP transport objects
 0365            var _httpRequest = new HttpRequestMessage();
 0366            HttpResponseMessage _httpResponse = null;
 0367            _httpRequest.Method = new HttpMethod("POST");
 0368            _httpRequest.RequestUri = new System.Uri(_url);
 369            // Set Headers
 0370            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 371            {
 0372                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 373            }
 0374            if (Client.AcceptLanguage != null)
 375            {
 0376                if (_httpRequest.Headers.Contains("accept-language"))
 377                {
 0378                    _httpRequest.Headers.Remove("accept-language");
 379                }
 0380                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 381            }
 0382            if (clientRequestId != null)
 383            {
 0384                if (_httpRequest.Headers.Contains("x-ms-client-request-id"))
 385                {
 0386                    _httpRequest.Headers.Remove("x-ms-client-request-id");
 387                }
 0388                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver
 389            }
 390
 391
 0392            if (customHeaders != null)
 393            {
 0394                foreach(var _header in customHeaders)
 395                {
 0396                    if (_httpRequest.Headers.Contains(_header.Key))
 397                    {
 0398                        _httpRequest.Headers.Remove(_header.Key);
 399                    }
 0400                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 401                }
 402            }
 403
 404            // Serialize Request
 0405            string _requestContent = null;
 406            // Set Credentials
 0407            if (Client.Credentials != null)
 408            {
 0409                cancellationToken.ThrowIfCancellationRequested();
 0410                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 411            }
 412            // Send Request
 0413            if (_shouldTrace)
 414            {
 0415                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 416            }
 0417            cancellationToken.ThrowIfCancellationRequested();
 0418            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0419            if (_shouldTrace)
 420            {
 0421                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 422            }
 0423            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0424            cancellationToken.ThrowIfCancellationRequested();
 0425            string _responseContent = null;
 0426            if ((int)_statusCode != 200)
 427            {
 0428                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 429                try
 430                {
 0431                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0432                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0433                    if (_errorBody != null)
 434                    {
 0435                        ex = new CloudException(_errorBody.Message);
 0436                        ex.Body = _errorBody;
 437                    }
 0438                }
 0439                catch (JsonException)
 440                {
 441                    // Ignore the exception
 0442                }
 0443                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0444                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0445                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 446                {
 0447                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 448                }
 0449                if (_shouldTrace)
 450                {
 0451                    ServiceClientTracing.Error(_invocationId, ex);
 452                }
 0453                _httpRequest.Dispose();
 0454                if (_httpResponse != null)
 455                {
 0456                    _httpResponse.Dispose();
 457                }
 0458                throw ex;
 459            }
 460            // Create Result
 0461            var _result = new AzureOperationResponse<AdminKeyResult>();
 0462            _result.Request = _httpRequest;
 0463            _result.Response = _httpResponse;
 0464            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 465            {
 0466                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 467            }
 468            // Deserialize Response
 0469            if ((int)_statusCode == 200)
 470            {
 0471                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 472                try
 473                {
 0474                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AdminKeyResult>(_responseContent
 0475                }
 0476                catch (JsonException ex)
 477                {
 0478                    _httpRequest.Dispose();
 0479                    if (_httpResponse != null)
 480                    {
 0481                        _httpResponse.Dispose();
 482                    }
 0483                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 484                }
 485            }
 0486            if (_shouldTrace)
 487            {
 0488                ServiceClientTracing.Exit(_invocationId, _result);
 489            }
 0490            return _result;
 0491        }
 492
 493    }
 494}