< Summary

Class:Microsoft.Azure.CognitiveServices.Personalizer.Model
Assembly:Microsoft.Azure.CognitiveServices.Personalizer
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Personalizer\src\Generated\Model.cs
Covered lines:101
Uncovered lines:82
Coverable lines:183
Total lines:447
Line coverage:55.1% (101 of 183)
Covered branches:35
Total branches:92
Branch coverage:38% (35 of 92)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
GetWithHttpMessagesAsync()-57.14%40%
ResetWithHttpMessagesAsync()-51.72%35.71%
GetPropertiesWithHttpMessagesAsync()-53.97%37.5%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Personalizer\src\Generated\Model.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.Personalizer
 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    /// Model operations.
 27    /// </summary>
 28    public partial class Model : IServiceOperations<PersonalizerClient>, IModel
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Model 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>
 3439        public Model(PersonalizerClient client)
 40        {
 3441            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 3445            Client = client;
 3446        }
 47
 48        /// <summary>
 49        /// Gets a reference to the PersonalizerClient
 50        /// </summary>
 7251        public PersonalizerClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Get Model.
 55        /// </summary>
 56        /// <remarks>
 57        /// Get the model file generated by Personalizer service.
 58        /// </remarks>
 59        /// <param name='customHeaders'>
 60        /// Headers that will be added to request.
 61        /// </param>
 62        /// <param name='cancellationToken'>
 63        /// The cancellation token.
 64        /// </param>
 65        /// <exception cref="HttpOperationException">
 66        /// Thrown when the operation returned an invalid status code
 67        /// </exception>
 68        /// <exception cref="SerializationException">
 69        /// Thrown when unable to deserialize the response
 70        /// </exception>
 71        /// <exception cref="ValidationException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <exception cref="System.ArgumentNullException">
 75        /// Thrown when a required parameter is null
 76        /// </exception>
 77        /// <return>
 78        /// A response object containing the response body and response headers.
 79        /// </return>
 80        public async Task<HttpOperationResponse<Stream>> GetWithHttpMessagesAsync(Dictionary<string, List<string>> custo
 81        {
 282            if (Client.Endpoint == null)
 83            {
 084                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 85            }
 86            // Tracing
 287            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 288            string _invocationId = null;
 289            if (_shouldTrace)
 90            {
 091                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 092                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 093                tracingParameters.Add("cancellationToken", cancellationToken);
 094                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 95            }
 96            // Construct URL
 297            var _baseUrl = Client.BaseUri;
 298            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model";
 299            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 100            // Create HTTP transport objects
 2101            var _httpRequest = new HttpRequestMessage();
 2102            HttpResponseMessage _httpResponse = null;
 2103            _httpRequest.Method = new HttpMethod("GET");
 2104            _httpRequest.RequestUri = new System.Uri(_url);
 105            // Set Headers
 106
 107
 2108            if (customHeaders != null)
 109            {
 0110                foreach(var _header in customHeaders)
 111                {
 0112                    if (_httpRequest.Headers.Contains(_header.Key))
 113                    {
 0114                        _httpRequest.Headers.Remove(_header.Key);
 115                    }
 0116                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 117                }
 118            }
 119
 120            // Serialize Request
 2121            string _requestContent = null;
 122            // Set Credentials
 2123            if (Client.Credentials != null)
 124            {
 2125                cancellationToken.ThrowIfCancellationRequested();
 2126                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 127            }
 128            // Send Request
 2129            if (_shouldTrace)
 130            {
 0131                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 132            }
 2133            cancellationToken.ThrowIfCancellationRequested();
 2134            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 2135            if (_shouldTrace)
 136            {
 0137                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 138            }
 2139            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2140            cancellationToken.ThrowIfCancellationRequested();
 2141            string _responseContent = null;
 2142            if ((int)_statusCode != 200)
 143            {
 0144                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 0145                if (_httpResponse.Content != null) {
 0146                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 147                }
 148                else {
 0149                    _responseContent = string.Empty;
 150                }
 0151                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0152                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0153                if (_shouldTrace)
 154                {
 0155                    ServiceClientTracing.Error(_invocationId, ex);
 156                }
 0157                _httpRequest.Dispose();
 0158                if (_httpResponse != null)
 159                {
 0160                    _httpResponse.Dispose();
 161                }
 0162                throw ex;
 163            }
 164            // Create Result
 2165            var _result = new HttpOperationResponse<Stream>();
 2166            _result.Request = _httpRequest;
 2167            _result.Response = _httpResponse;
 168            // Deserialize Response
 2169            if ((int)_statusCode == 200)
 170            {
 2171                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 172            }
 2173            if (_shouldTrace)
 174            {
 0175                ServiceClientTracing.Exit(_invocationId, _result);
 176            }
 2177            return _result;
 2178        }
 179
 180        /// <summary>
 181        /// Reset Model.
 182        /// </summary>
 183        /// <remarks>
 184        /// Resets the model file generated by Personalizer service.
 185        /// </remarks>
 186        /// <param name='customHeaders'>
 187        /// Headers that will be added to request.
 188        /// </param>
 189        /// <param name='cancellationToken'>
 190        /// The cancellation token.
 191        /// </param>
 192        /// <exception cref="ErrorResponseException">
 193        /// Thrown when the operation returned an invalid status code
 194        /// </exception>
 195        /// <exception cref="ValidationException">
 196        /// Thrown when a required parameter is null
 197        /// </exception>
 198        /// <exception cref="System.ArgumentNullException">
 199        /// Thrown when a required parameter is null
 200        /// </exception>
 201        /// <return>
 202        /// A response object containing the response body and response headers.
 203        /// </return>
 204        public async Task<HttpOperationResponse> ResetWithHttpMessagesAsync(Dictionary<string, List<string>> customHeade
 205        {
 2206            if (Client.Endpoint == null)
 207            {
 0208                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 209            }
 210            // Tracing
 2211            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2212            string _invocationId = null;
 2213            if (_shouldTrace)
 214            {
 0215                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0216                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0217                tracingParameters.Add("cancellationToken", cancellationToken);
 0218                ServiceClientTracing.Enter(_invocationId, this, "Reset", tracingParameters);
 219            }
 220            // Construct URL
 2221            var _baseUrl = Client.BaseUri;
 2222            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model";
 2223            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 224            // Create HTTP transport objects
 2225            var _httpRequest = new HttpRequestMessage();
 2226            HttpResponseMessage _httpResponse = null;
 2227            _httpRequest.Method = new HttpMethod("DELETE");
 2228            _httpRequest.RequestUri = new System.Uri(_url);
 229            // Set Headers
 230
 231
 2232            if (customHeaders != null)
 233            {
 0234                foreach(var _header in customHeaders)
 235                {
 0236                    if (_httpRequest.Headers.Contains(_header.Key))
 237                    {
 0238                        _httpRequest.Headers.Remove(_header.Key);
 239                    }
 0240                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 241                }
 242            }
 243
 244            // Serialize Request
 2245            string _requestContent = null;
 246            // Set Credentials
 2247            if (Client.Credentials != null)
 248            {
 2249                cancellationToken.ThrowIfCancellationRequested();
 2250                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 251            }
 252            // Send Request
 2253            if (_shouldTrace)
 254            {
 0255                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 256            }
 2257            cancellationToken.ThrowIfCancellationRequested();
 2258            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2259            if (_shouldTrace)
 260            {
 0261                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 262            }
 2263            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2264            cancellationToken.ThrowIfCancellationRequested();
 2265            string _responseContent = null;
 2266            if ((int)_statusCode != 204)
 267            {
 0268                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 269                try
 270                {
 0271                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0272                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0273                    if (_errorBody != null)
 274                    {
 0275                        ex.Body = _errorBody;
 276                    }
 0277                }
 0278                catch (JsonException)
 279                {
 280                    // Ignore the exception
 0281                }
 0282                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0283                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0284                if (_shouldTrace)
 285                {
 0286                    ServiceClientTracing.Error(_invocationId, ex);
 287                }
 0288                _httpRequest.Dispose();
 0289                if (_httpResponse != null)
 290                {
 0291                    _httpResponse.Dispose();
 292                }
 0293                throw ex;
 294            }
 295            // Create Result
 2296            var _result = new HttpOperationResponse();
 2297            _result.Request = _httpRequest;
 2298            _result.Response = _httpResponse;
 2299            if (_shouldTrace)
 300            {
 0301                ServiceClientTracing.Exit(_invocationId, _result);
 302            }
 2303            return _result;
 2304        }
 305
 306        /// <summary>
 307        /// Get Model Properties.
 308        /// </summary>
 309        /// <remarks>
 310        /// Get properties of the model file generated by Personalizer service.
 311        /// </remarks>
 312        /// <param name='customHeaders'>
 313        /// Headers that will be added to request.
 314        /// </param>
 315        /// <param name='cancellationToken'>
 316        /// The cancellation token.
 317        /// </param>
 318        /// <exception cref="HttpOperationException">
 319        /// Thrown when the operation returned an invalid status code
 320        /// </exception>
 321        /// <exception cref="SerializationException">
 322        /// Thrown when unable to deserialize the response
 323        /// </exception>
 324        /// <exception cref="ValidationException">
 325        /// Thrown when a required parameter is null
 326        /// </exception>
 327        /// <exception cref="System.ArgumentNullException">
 328        /// Thrown when a required parameter is null
 329        /// </exception>
 330        /// <return>
 331        /// A response object containing the response body and response headers.
 332        /// </return>
 333        public async Task<HttpOperationResponse<ModelProperties>> GetPropertiesWithHttpMessagesAsync(Dictionary<string, 
 334        {
 2335            if (Client.Endpoint == null)
 336            {
 0337                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 338            }
 339            // Tracing
 2340            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2341            string _invocationId = null;
 2342            if (_shouldTrace)
 343            {
 0344                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0345                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0346                tracingParameters.Add("cancellationToken", cancellationToken);
 0347                ServiceClientTracing.Enter(_invocationId, this, "GetProperties", tracingParameters);
 348            }
 349            // Construct URL
 2350            var _baseUrl = Client.BaseUri;
 2351            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model/properties";
 2352            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 353            // Create HTTP transport objects
 2354            var _httpRequest = new HttpRequestMessage();
 2355            HttpResponseMessage _httpResponse = null;
 2356            _httpRequest.Method = new HttpMethod("GET");
 2357            _httpRequest.RequestUri = new System.Uri(_url);
 358            // Set Headers
 359
 360
 2361            if (customHeaders != null)
 362            {
 0363                foreach(var _header in customHeaders)
 364                {
 0365                    if (_httpRequest.Headers.Contains(_header.Key))
 366                    {
 0367                        _httpRequest.Headers.Remove(_header.Key);
 368                    }
 0369                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 370                }
 371            }
 372
 373            // Serialize Request
 2374            string _requestContent = null;
 375            // Set Credentials
 2376            if (Client.Credentials != null)
 377            {
 2378                cancellationToken.ThrowIfCancellationRequested();
 2379                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 380            }
 381            // Send Request
 2382            if (_shouldTrace)
 383            {
 0384                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 385            }
 2386            cancellationToken.ThrowIfCancellationRequested();
 2387            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2388            if (_shouldTrace)
 389            {
 0390                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 391            }
 2392            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2393            cancellationToken.ThrowIfCancellationRequested();
 2394            string _responseContent = null;
 2395            if ((int)_statusCode != 200)
 396            {
 0397                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 0398                if (_httpResponse.Content != null) {
 0399                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 400                }
 401                else {
 0402                    _responseContent = string.Empty;
 403                }
 0404                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0405                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0406                if (_shouldTrace)
 407                {
 0408                    ServiceClientTracing.Error(_invocationId, ex);
 409                }
 0410                _httpRequest.Dispose();
 0411                if (_httpResponse != null)
 412                {
 0413                    _httpResponse.Dispose();
 414                }
 0415                throw ex;
 416            }
 417            // Create Result
 2418            var _result = new HttpOperationResponse<ModelProperties>();
 2419            _result.Request = _httpRequest;
 2420            _result.Response = _httpResponse;
 421            // Deserialize Response
 2422            if ((int)_statusCode == 200)
 423            {
 2424                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 425                try
 426                {
 2427                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ModelProperties>(_responseConten
 2428                }
 0429                catch (JsonException ex)
 430                {
 0431                    _httpRequest.Dispose();
 0432                    if (_httpResponse != null)
 433                    {
 0434                        _httpResponse.Dispose();
 435                    }
 0436                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 437                }
 438            }
 2439            if (_shouldTrace)
 440            {
 0441                ServiceClientTracing.Exit(_invocationId, _result);
 442            }
 2443            return _result;
 2444        }
 445
 446    }
 447}