< Summary

Class:Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.Alterations
Assembly:Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\Alterations.cs
Covered lines:0
Uncovered lines:140
Coverable lines:140
Total lines:339
Line coverage:0% (0 of 140)
Covered branches:0
Total branches:68
Branch coverage:0% (0 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_Client()-0%100%
GetWithHttpMessagesAsync()-0%0%
ReplaceWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\Alterations.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.CognitiveServices.Knowledge.QnAMaker
 12{
 13    using Microsoft.Rest;
 14    using Models;
 15    using Newtonsoft.Json;
 16    using System.Collections;
 17    using System.Collections.Generic;
 18    using System.IO;
 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    /// Alterations operations.
 27    /// </summary>
 28    public partial class Alterations : IServiceOperations<QnAMakerClient>, IAlterations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Alterations 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>
 039        public Alterations(QnAMakerClient client)
 40        {
 041            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 045            Client = client;
 046        }
 47
 48        /// <summary>
 49        /// Gets a reference to the QnAMakerClient
 50        /// </summary>
 051        public QnAMakerClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Download alterations from runtime.
 55        /// </summary>
 56        /// <param name='customHeaders'>
 57        /// Headers that will be added to request.
 58        /// </param>
 59        /// <param name='cancellationToken'>
 60        /// The cancellation token.
 61        /// </param>
 62        /// <exception cref="ErrorResponseException">
 63        /// Thrown when the operation returned an invalid status code
 64        /// </exception>
 65        /// <exception cref="SerializationException">
 66        /// Thrown when unable to deserialize the response
 67        /// </exception>
 68        /// <exception cref="ValidationException">
 69        /// Thrown when a required parameter is null
 70        /// </exception>
 71        /// <exception cref="System.ArgumentNullException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <return>
 75        /// A response object containing the response body and response headers.
 76        /// </return>
 77        public async Task<HttpOperationResponse<WordAlterationsDTO>> GetWithHttpMessagesAsync(Dictionary<string, List<st
 78        {
 079            if (Client.Endpoint == null)
 80            {
 081                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 82            }
 83            // Tracing
 084            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 085            string _invocationId = null;
 086            if (_shouldTrace)
 87            {
 088                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 089                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 090                tracingParameters.Add("cancellationToken", cancellationToken);
 091                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 92            }
 93            // Construct URL
 094            var _baseUrl = Client.BaseUri;
 095            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "alterations";
 096            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 97            // Create HTTP transport objects
 098            var _httpRequest = new HttpRequestMessage();
 099            HttpResponseMessage _httpResponse = null;
 0100            _httpRequest.Method = new HttpMethod("GET");
 0101            _httpRequest.RequestUri = new System.Uri(_url);
 102            // Set Headers
 103
 104
 0105            if (customHeaders != null)
 106            {
 0107                foreach(var _header in customHeaders)
 108                {
 0109                    if (_httpRequest.Headers.Contains(_header.Key))
 110                    {
 0111                        _httpRequest.Headers.Remove(_header.Key);
 112                    }
 0113                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 114                }
 115            }
 116
 117            // Serialize Request
 0118            string _requestContent = null;
 119            // Set Credentials
 0120            if (Client.Credentials != null)
 121            {
 0122                cancellationToken.ThrowIfCancellationRequested();
 0123                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 124            }
 125            // Send Request
 0126            if (_shouldTrace)
 127            {
 0128                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 129            }
 0130            cancellationToken.ThrowIfCancellationRequested();
 0131            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0132            if (_shouldTrace)
 133            {
 0134                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 135            }
 0136            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0137            cancellationToken.ThrowIfCancellationRequested();
 0138            string _responseContent = null;
 0139            if ((int)_statusCode != 200)
 140            {
 0141                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 142                try
 143                {
 0144                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0145                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0146                    if (_errorBody != null)
 147                    {
 0148                        ex.Body = _errorBody;
 149                    }
 0150                }
 0151                catch (JsonException)
 152                {
 153                    // Ignore the exception
 0154                }
 0155                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0156                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0157                if (_shouldTrace)
 158                {
 0159                    ServiceClientTracing.Error(_invocationId, ex);
 160                }
 0161                _httpRequest.Dispose();
 0162                if (_httpResponse != null)
 163                {
 0164                    _httpResponse.Dispose();
 165                }
 0166                throw ex;
 167            }
 168            // Create Result
 0169            var _result = new HttpOperationResponse<WordAlterationsDTO>();
 0170            _result.Request = _httpRequest;
 0171            _result.Response = _httpResponse;
 172            // Deserialize Response
 0173            if ((int)_statusCode == 200)
 174            {
 0175                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 176                try
 177                {
 0178                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<WordAlterationsDTO>(_responseCon
 0179                }
 0180                catch (JsonException ex)
 181                {
 0182                    _httpRequest.Dispose();
 0183                    if (_httpResponse != null)
 184                    {
 0185                        _httpResponse.Dispose();
 186                    }
 0187                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 188                }
 189            }
 0190            if (_shouldTrace)
 191            {
 0192                ServiceClientTracing.Exit(_invocationId, _result);
 193            }
 0194            return _result;
 0195        }
 196
 197        /// <summary>
 198        /// Replace alterations data.
 199        /// </summary>
 200        /// <param name='wordAlterations'>
 201        /// New alterations data.
 202        /// </param>
 203        /// <param name='customHeaders'>
 204        /// Headers that will be added to request.
 205        /// </param>
 206        /// <param name='cancellationToken'>
 207        /// The cancellation token.
 208        /// </param>
 209        /// <exception cref="ErrorResponseException">
 210        /// Thrown when the operation returned an invalid status code
 211        /// </exception>
 212        /// <exception cref="ValidationException">
 213        /// Thrown when a required parameter is null
 214        /// </exception>
 215        /// <exception cref="System.ArgumentNullException">
 216        /// Thrown when a required parameter is null
 217        /// </exception>
 218        /// <return>
 219        /// A response object containing the response body and response headers.
 220        /// </return>
 221        public async Task<HttpOperationResponse> ReplaceWithHttpMessagesAsync(WordAlterationsDTO wordAlterations, Dictio
 222        {
 0223            if (Client.Endpoint == null)
 224            {
 0225                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 226            }
 0227            if (wordAlterations == null)
 228            {
 0229                throw new ValidationException(ValidationRules.CannotBeNull, "wordAlterations");
 230            }
 0231            if (wordAlterations != null)
 232            {
 0233                wordAlterations.Validate();
 234            }
 235            // Tracing
 0236            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0237            string _invocationId = null;
 0238            if (_shouldTrace)
 239            {
 0240                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0241                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0242                tracingParameters.Add("wordAlterations", wordAlterations);
 0243                tracingParameters.Add("cancellationToken", cancellationToken);
 0244                ServiceClientTracing.Enter(_invocationId, this, "Replace", tracingParameters);
 245            }
 246            // Construct URL
 0247            var _baseUrl = Client.BaseUri;
 0248            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "alterations";
 0249            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 250            // Create HTTP transport objects
 0251            var _httpRequest = new HttpRequestMessage();
 0252            HttpResponseMessage _httpResponse = null;
 0253            _httpRequest.Method = new HttpMethod("PUT");
 0254            _httpRequest.RequestUri = new System.Uri(_url);
 255            // Set Headers
 256
 257
 0258            if (customHeaders != null)
 259            {
 0260                foreach(var _header in customHeaders)
 261                {
 0262                    if (_httpRequest.Headers.Contains(_header.Key))
 263                    {
 0264                        _httpRequest.Headers.Remove(_header.Key);
 265                    }
 0266                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 267                }
 268            }
 269
 270            // Serialize Request
 0271            string _requestContent = null;
 0272            if(wordAlterations != null)
 273            {
 0274                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(wordAlterations, Client.Serializati
 0275                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0276                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 277            }
 278            // Set Credentials
 0279            if (Client.Credentials != null)
 280            {
 0281                cancellationToken.ThrowIfCancellationRequested();
 0282                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 283            }
 284            // Send Request
 0285            if (_shouldTrace)
 286            {
 0287                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 288            }
 0289            cancellationToken.ThrowIfCancellationRequested();
 0290            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0291            if (_shouldTrace)
 292            {
 0293                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 294            }
 0295            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0296            cancellationToken.ThrowIfCancellationRequested();
 0297            string _responseContent = null;
 0298            if ((int)_statusCode != 204)
 299            {
 0300                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 301                try
 302                {
 0303                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0304                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0305                    if (_errorBody != null)
 306                    {
 0307                        ex.Body = _errorBody;
 308                    }
 0309                }
 0310                catch (JsonException)
 311                {
 312                    // Ignore the exception
 0313                }
 0314                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0315                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0316                if (_shouldTrace)
 317                {
 0318                    ServiceClientTracing.Error(_invocationId, ex);
 319                }
 0320                _httpRequest.Dispose();
 0321                if (_httpResponse != null)
 322                {
 0323                    _httpResponse.Dispose();
 324                }
 0325                throw ex;
 326            }
 327            // Create Result
 0328            var _result = new HttpOperationResponse();
 0329            _result.Request = _httpRequest;
 0330            _result.Response = _httpResponse;
 0331            if (_shouldTrace)
 332            {
 0333                ServiceClientTracing.Exit(_invocationId, _result);
 334            }
 0335            return _result;
 0336        }
 337
 338    }
 339}