< Summary

Class:Microsoft.Azure.Graph.RBAC.DomainsOperations
Assembly:Microsoft.Azure.Graph.RBAC
File(s):C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\DomainsOperations.cs
Covered lines:4
Uncovered lines:181
Coverable lines:185
Total lines:432
Line coverage:2.1% (4 of 185)
Covered branches:1
Total branches:112
Branch coverage:0.8% (1 of 112)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\DomainsOperations.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.Graph.RBAC
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Microsoft.Rest.Azure.OData;
 16    using Models;
 17    using Newtonsoft.Json;
 18    using System.Collections;
 19    using System.Collections.Generic;
 20    using System.Linq;
 21    using System.Net;
 22    using System.Net.Http;
 23    using System.Threading;
 24    using System.Threading.Tasks;
 25
 26    /// <summary>
 27    /// DomainsOperations operations.
 28    /// </summary>
 29    internal partial class DomainsOperations : IServiceOperations<GraphRbacManagementClient>, IDomainsOperations
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the DomainsOperations class.
 33        /// </summary>
 34        /// <param name='client'>
 35        /// Reference to the service client.
 36        /// </param>
 37        /// <exception cref="System.ArgumentNullException">
 38        /// Thrown when a required parameter is null
 39        /// </exception>
 4640        internal DomainsOperations(GraphRbacManagementClient client)
 41        {
 4642            if (client == null)
 43            {
 044                throw new System.ArgumentNullException("client");
 45            }
 4646            Client = client;
 4647        }
 48
 49        /// <summary>
 50        /// Gets a reference to the GraphRbacManagementClient
 51        /// </summary>
 052        public GraphRbacManagementClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Gets a list of domains for the current tenant.
 56        /// </summary>
 57        /// <param name='odataQuery'>
 58        /// OData parameters to apply to the operation.
 59        /// </param>
 60        /// <param name='customHeaders'>
 61        /// Headers that will be added to request.
 62        /// </param>
 63        /// <param name='cancellationToken'>
 64        /// The cancellation token.
 65        /// </param>
 66        /// <exception cref="CloudException">
 67        /// Thrown when the operation returned an invalid status code
 68        /// </exception>
 69        /// <exception cref="SerializationException">
 70        /// Thrown when unable to deserialize the response
 71        /// </exception>
 72        /// <exception cref="ValidationException">
 73        /// Thrown when a required parameter is null
 74        /// </exception>
 75        /// <exception cref="System.ArgumentNullException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <return>
 79        /// A response object containing the response body and response headers.
 80        /// </return>
 81        public async Task<AzureOperationResponse<IEnumerable<Domain>>> ListWithHttpMessagesAsync(ODataQuery<User> odataQ
 82        {
 083            if (Client.ApiVersion == null)
 84            {
 085                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 86            }
 087            if (Client.TenantID == null)
 88            {
 089                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 90            }
 91            // Tracing
 092            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 093            string _invocationId = null;
 094            if (_shouldTrace)
 95            {
 096                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 097                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 098                tracingParameters.Add("odataQuery", odataQuery);
 099                tracingParameters.Add("cancellationToken", cancellationToken);
 0100                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 101            }
 102            // Construct URL
 0103            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0104            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/domain
 0105            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0106            List<string> _queryParameters = new List<string>();
 0107            if (odataQuery != null)
 108            {
 0109                var _odataFilter = odataQuery.ToString();
 0110                if (!string.IsNullOrEmpty(_odataFilter))
 111                {
 0112                    _queryParameters.Add(_odataFilter);
 113                }
 114            }
 0115            if (Client.ApiVersion != null)
 116            {
 0117                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 118            }
 0119            if (_queryParameters.Count > 0)
 120            {
 0121                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 122            }
 123            // Create HTTP transport objects
 0124            var _httpRequest = new HttpRequestMessage();
 0125            HttpResponseMessage _httpResponse = null;
 0126            _httpRequest.Method = new HttpMethod("GET");
 0127            _httpRequest.RequestUri = new System.Uri(_url);
 128            // Set Headers
 0129            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 130            {
 0131                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 132            }
 0133            if (Client.AcceptLanguage != null)
 134            {
 0135                if (_httpRequest.Headers.Contains("accept-language"))
 136                {
 0137                    _httpRequest.Headers.Remove("accept-language");
 138                }
 0139                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 140            }
 141
 142
 0143            if (customHeaders != null)
 144            {
 0145                foreach(var _header in customHeaders)
 146                {
 0147                    if (_httpRequest.Headers.Contains(_header.Key))
 148                    {
 0149                        _httpRequest.Headers.Remove(_header.Key);
 150                    }
 0151                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 152                }
 153            }
 154
 155            // Serialize Request
 0156            string _requestContent = null;
 157            // Set Credentials
 0158            if (Client.Credentials != null)
 159            {
 0160                cancellationToken.ThrowIfCancellationRequested();
 0161                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 162            }
 163            // Send Request
 0164            if (_shouldTrace)
 165            {
 0166                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 167            }
 0168            cancellationToken.ThrowIfCancellationRequested();
 0169            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0170            if (_shouldTrace)
 171            {
 0172                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 173            }
 0174            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0175            cancellationToken.ThrowIfCancellationRequested();
 0176            string _responseContent = null;
 0177            if ((int)_statusCode != 200)
 178            {
 0179                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 180                try
 181                {
 0182                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0183                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0184                    if (_errorBody != null)
 185                    {
 0186                        ex = new CloudException(_errorBody.Message);
 0187                        ex.Body = _errorBody;
 188                    }
 0189                }
 0190                catch (JsonException)
 191                {
 192                    // Ignore the exception
 0193                }
 0194                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0195                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0196                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 197                {
 0198                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 199                }
 0200                if (_shouldTrace)
 201                {
 0202                    ServiceClientTracing.Error(_invocationId, ex);
 203                }
 0204                _httpRequest.Dispose();
 0205                if (_httpResponse != null)
 206                {
 0207                    _httpResponse.Dispose();
 208                }
 0209                throw ex;
 210            }
 211            // Create Result
 0212            var _result = new AzureOperationResponse<IEnumerable<Domain>>();
 0213            _result.Request = _httpRequest;
 0214            _result.Response = _httpResponse;
 0215            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 216            {
 0217                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 218            }
 219            // Deserialize Response
 0220            if ((int)_statusCode == 200)
 221            {
 0222                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 223                try
 224                {
 0225                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<Domain>>(_responseContent,
 0226                }
 0227                catch (JsonException ex)
 228                {
 0229                    _httpRequest.Dispose();
 0230                    if (_httpResponse != null)
 231                    {
 0232                        _httpResponse.Dispose();
 233                    }
 0234                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 235                }
 236            }
 0237            if (_shouldTrace)
 238            {
 0239                ServiceClientTracing.Exit(_invocationId, _result);
 240            }
 0241            return _result;
 0242        }
 243
 244        /// <summary>
 245        /// Gets a specific domain in the current tenant.
 246        /// </summary>
 247        /// <param name='domainName'>
 248        /// name of the domain.
 249        /// </param>
 250        /// <param name='customHeaders'>
 251        /// Headers that will be added to request.
 252        /// </param>
 253        /// <param name='cancellationToken'>
 254        /// The cancellation token.
 255        /// </param>
 256        /// <exception cref="CloudException">
 257        /// Thrown when the operation returned an invalid status code
 258        /// </exception>
 259        /// <exception cref="SerializationException">
 260        /// Thrown when unable to deserialize the response
 261        /// </exception>
 262        /// <exception cref="ValidationException">
 263        /// Thrown when a required parameter is null
 264        /// </exception>
 265        /// <exception cref="System.ArgumentNullException">
 266        /// Thrown when a required parameter is null
 267        /// </exception>
 268        /// <return>
 269        /// A response object containing the response body and response headers.
 270        /// </return>
 271        public async Task<AzureOperationResponse<Domain>> GetWithHttpMessagesAsync(string domainName, Dictionary<string,
 272        {
 0273            if (domainName == null)
 274            {
 0275                throw new ValidationException(ValidationRules.CannotBeNull, "domainName");
 276            }
 0277            if (Client.ApiVersion == null)
 278            {
 0279                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 280            }
 0281            if (Client.TenantID == null)
 282            {
 0283                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 284            }
 285            // Tracing
 0286            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0287            string _invocationId = null;
 0288            if (_shouldTrace)
 289            {
 0290                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0291                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0292                tracingParameters.Add("domainName", domainName);
 0293                tracingParameters.Add("cancellationToken", cancellationToken);
 0294                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 295            }
 296            // Construct URL
 0297            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0298            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/domain
 0299            _url = _url.Replace("{domainName}", System.Uri.EscapeDataString(domainName));
 0300            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0301            List<string> _queryParameters = new List<string>();
 0302            if (Client.ApiVersion != null)
 303            {
 0304                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 305            }
 0306            if (_queryParameters.Count > 0)
 307            {
 0308                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 309            }
 310            // Create HTTP transport objects
 0311            var _httpRequest = new HttpRequestMessage();
 0312            HttpResponseMessage _httpResponse = null;
 0313            _httpRequest.Method = new HttpMethod("GET");
 0314            _httpRequest.RequestUri = new System.Uri(_url);
 315            // Set Headers
 0316            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 317            {
 0318                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 319            }
 0320            if (Client.AcceptLanguage != null)
 321            {
 0322                if (_httpRequest.Headers.Contains("accept-language"))
 323                {
 0324                    _httpRequest.Headers.Remove("accept-language");
 325                }
 0326                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 327            }
 328
 329
 0330            if (customHeaders != null)
 331            {
 0332                foreach(var _header in customHeaders)
 333                {
 0334                    if (_httpRequest.Headers.Contains(_header.Key))
 335                    {
 0336                        _httpRequest.Headers.Remove(_header.Key);
 337                    }
 0338                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 339                }
 340            }
 341
 342            // Serialize Request
 0343            string _requestContent = null;
 344            // Set Credentials
 0345            if (Client.Credentials != null)
 346            {
 0347                cancellationToken.ThrowIfCancellationRequested();
 0348                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 349            }
 350            // Send Request
 0351            if (_shouldTrace)
 352            {
 0353                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 354            }
 0355            cancellationToken.ThrowIfCancellationRequested();
 0356            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0357            if (_shouldTrace)
 358            {
 0359                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 360            }
 0361            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0362            cancellationToken.ThrowIfCancellationRequested();
 0363            string _responseContent = null;
 0364            if ((int)_statusCode != 200)
 365            {
 0366                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 367                try
 368                {
 0369                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0370                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0371                    if (_errorBody != null)
 372                    {
 0373                        ex = new CloudException(_errorBody.Message);
 0374                        ex.Body = _errorBody;
 375                    }
 0376                }
 0377                catch (JsonException)
 378                {
 379                    // Ignore the exception
 0380                }
 0381                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0382                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0383                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 384                {
 0385                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 386                }
 0387                if (_shouldTrace)
 388                {
 0389                    ServiceClientTracing.Error(_invocationId, ex);
 390                }
 0391                _httpRequest.Dispose();
 0392                if (_httpResponse != null)
 393                {
 0394                    _httpResponse.Dispose();
 395                }
 0396                throw ex;
 397            }
 398            // Create Result
 0399            var _result = new AzureOperationResponse<Domain>();
 0400            _result.Request = _httpRequest;
 0401            _result.Response = _httpResponse;
 0402            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 403            {
 0404                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 405            }
 406            // Deserialize Response
 0407            if ((int)_statusCode == 200)
 408            {
 0409                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 410                try
 411                {
 0412                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Domain>(_responseContent, Client
 0413                }
 0414                catch (JsonException ex)
 415                {
 0416                    _httpRequest.Dispose();
 0417                    if (_httpResponse != null)
 418                    {
 0419                        _httpResponse.Dispose();
 420                    }
 0421                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 422                }
 423            }
 0424            if (_shouldTrace)
 425            {
 0426                ServiceClientTracing.Exit(_invocationId, _result);
 427            }
 0428            return _result;
 0429        }
 430
 431    }
 432}