< Summary

Class:Microsoft.Azure.CognitiveServices.Personalizer.Log
Assembly:Microsoft.Azure.CognitiveServices.Personalizer
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Personalizer\src\Generated\Log.cs
Covered lines:69
Uncovered lines:58
Coverable lines:127
Total lines:320
Line coverage:54.3% (69 of 127)
Covered branches:23
Total branches:62
Branch coverage:37% (23 of 62)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
DeleteWithHttpMessagesAsync()-55.56%35.71%
GetPropertiesWithHttpMessagesAsync()-50.75%37.5%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Personalizer\src\Generated\Log.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    /// Log operations.
 27    /// </summary>
 28    public partial class Log : IServiceOperations<PersonalizerClient>, ILog
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Log 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 Log(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>
 6051        public PersonalizerClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Deletes Logs.
 55        /// </summary>
 56        /// <remarks>
 57        /// Delete all generated logs.
 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="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> DeleteWithHttpMessagesAsync(Dictionary<string, List<string>> customHead
 78        {
 279            if (Client.Endpoint == null)
 80            {
 081                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 82            }
 83            // Tracing
 284            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 285            string _invocationId = null;
 286            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, "Delete", tracingParameters);
 92            }
 93            // Construct URL
 294            var _baseUrl = Client.BaseUri;
 295            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "logs";
 296            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 97            // Create HTTP transport objects
 298            var _httpRequest = new HttpRequestMessage();
 299            HttpResponseMessage _httpResponse = null;
 2100            _httpRequest.Method = new HttpMethod("DELETE");
 2101            _httpRequest.RequestUri = new System.Uri(_url);
 102            // Set Headers
 103
 104
 2105            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
 2118            string _requestContent = null;
 119            // Set Credentials
 2120            if (Client.Credentials != null)
 121            {
 2122                cancellationToken.ThrowIfCancellationRequested();
 2123                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 124            }
 125            // Send Request
 2126            if (_shouldTrace)
 127            {
 0128                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 129            }
 2130            cancellationToken.ThrowIfCancellationRequested();
 2131            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2132            if (_shouldTrace)
 133            {
 0134                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 135            }
 2136            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2137            cancellationToken.ThrowIfCancellationRequested();
 2138            string _responseContent = null;
 2139            if ((int)_statusCode != 204)
 140            {
 0141                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 0142                if (_httpResponse.Content != null) {
 0143                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 144                }
 145                else {
 0146                    _responseContent = string.Empty;
 147                }
 0148                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0149                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0150                if (_shouldTrace)
 151                {
 0152                    ServiceClientTracing.Error(_invocationId, ex);
 153                }
 0154                _httpRequest.Dispose();
 0155                if (_httpResponse != null)
 156                {
 0157                    _httpResponse.Dispose();
 158                }
 0159                throw ex;
 160            }
 161            // Create Result
 2162            var _result = new HttpOperationResponse();
 2163            _result.Request = _httpRequest;
 2164            _result.Response = _httpResponse;
 2165            if (_shouldTrace)
 166            {
 0167                ServiceClientTracing.Exit(_invocationId, _result);
 168            }
 2169            return _result;
 2170        }
 171
 172        /// <summary>
 173        /// Get Log Properties.
 174        /// </summary>
 175        /// <remarks>
 176        /// Get properties of generated logs.
 177        /// </remarks>
 178        /// <param name='customHeaders'>
 179        /// Headers that will be added to request.
 180        /// </param>
 181        /// <param name='cancellationToken'>
 182        /// The cancellation token.
 183        /// </param>
 184        /// <exception cref="ErrorResponseException">
 185        /// Thrown when the operation returned an invalid status code
 186        /// </exception>
 187        /// <exception cref="SerializationException">
 188        /// Thrown when unable to deserialize the response
 189        /// </exception>
 190        /// <exception cref="ValidationException">
 191        /// Thrown when a required parameter is null
 192        /// </exception>
 193        /// <exception cref="System.ArgumentNullException">
 194        /// Thrown when a required parameter is null
 195        /// </exception>
 196        /// <return>
 197        /// A response object containing the response body and response headers.
 198        /// </return>
 199        public async Task<HttpOperationResponse<LogsProperties>> GetPropertiesWithHttpMessagesAsync(Dictionary<string, L
 200        {
 2201            if (Client.Endpoint == null)
 202            {
 0203                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 204            }
 205            // Tracing
 2206            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2207            string _invocationId = null;
 2208            if (_shouldTrace)
 209            {
 0210                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0211                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0212                tracingParameters.Add("cancellationToken", cancellationToken);
 0213                ServiceClientTracing.Enter(_invocationId, this, "GetProperties", tracingParameters);
 214            }
 215            // Construct URL
 2216            var _baseUrl = Client.BaseUri;
 2217            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "logs/properties";
 2218            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 219            // Create HTTP transport objects
 2220            var _httpRequest = new HttpRequestMessage();
 2221            HttpResponseMessage _httpResponse = null;
 2222            _httpRequest.Method = new HttpMethod("GET");
 2223            _httpRequest.RequestUri = new System.Uri(_url);
 224            // Set Headers
 225
 226
 2227            if (customHeaders != null)
 228            {
 0229                foreach(var _header in customHeaders)
 230                {
 0231                    if (_httpRequest.Headers.Contains(_header.Key))
 232                    {
 0233                        _httpRequest.Headers.Remove(_header.Key);
 234                    }
 0235                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 236                }
 237            }
 238
 239            // Serialize Request
 2240            string _requestContent = null;
 241            // Set Credentials
 2242            if (Client.Credentials != null)
 243            {
 2244                cancellationToken.ThrowIfCancellationRequested();
 2245                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 246            }
 247            // Send Request
 2248            if (_shouldTrace)
 249            {
 0250                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 251            }
 2252            cancellationToken.ThrowIfCancellationRequested();
 2253            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2254            if (_shouldTrace)
 255            {
 0256                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 257            }
 2258            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2259            cancellationToken.ThrowIfCancellationRequested();
 2260            string _responseContent = null;
 2261            if ((int)_statusCode != 200)
 262            {
 0263                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 264                try
 265                {
 0266                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0267                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0268                    if (_errorBody != null)
 269                    {
 0270                        ex.Body = _errorBody;
 271                    }
 0272                }
 0273                catch (JsonException)
 274                {
 275                    // Ignore the exception
 0276                }
 0277                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0278                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0279                if (_shouldTrace)
 280                {
 0281                    ServiceClientTracing.Error(_invocationId, ex);
 282                }
 0283                _httpRequest.Dispose();
 0284                if (_httpResponse != null)
 285                {
 0286                    _httpResponse.Dispose();
 287                }
 0288                throw ex;
 289            }
 290            // Create Result
 2291            var _result = new HttpOperationResponse<LogsProperties>();
 2292            _result.Request = _httpRequest;
 2293            _result.Response = _httpResponse;
 294            // Deserialize Response
 2295            if ((int)_statusCode == 200)
 296            {
 2297                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 298                try
 299                {
 2300                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LogsProperties>(_responseContent
 2301                }
 0302                catch (JsonException ex)
 303                {
 0304                    _httpRequest.Dispose();
 0305                    if (_httpResponse != null)
 306                    {
 0307                        _httpResponse.Dispose();
 308                    }
 0309                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 310                }
 311            }
 2312            if (_shouldTrace)
 313            {
 0314                ServiceClientTracing.Exit(_invocationId, _result);
 315            }
 2316            return _result;
 2317        }
 318
 319    }
 320}