< Summary

Class:Azure.DigitalTwins.Core.EventRoutesRestClient
Assembly:Azure.DigitalTwins.Core
File(s):C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\src\Generated\EventRoutesRestClient.cs
Covered lines:111
Uncovered lines:42
Coverable lines:153
Total lines:419
Line coverage:72.5% (111 of 153)
Covered branches:25
Total branches:50
Branch coverage:50% (25 of 50)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateListRequest(...)-90.91%75%
ListAsync()-87.5%50%
List(...)-87.5%50%
CreateGetByIdRequest(...)-100%100%
GetByIdAsync()-90%75%
GetById(...)-90%75%
CreateAddRequest(...)-100%100%
AddAsync()-87.5%75%
Add(...)-87.5%75%
CreateDeleteRequest(...)-100%100%
DeleteAsync()-75%50%
Delete(...)-75%50%
CreateListNextPageRequest(...)-0%0%
ListNextPageAsync()-0%0%
ListNextPage(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\src\Generated\EventRoutesRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15
 16namespace Azure.DigitalTwins.Core
 17{
 18    internal partial class EventRoutesRestClient
 19    {
 20        private Uri endpoint;
 21        private string apiVersion;
 22        private ClientDiagnostics _clientDiagnostics;
 23        private HttpPipeline _pipeline;
 24
 25        /// <summary> Initializes a new instance of EventRoutesRestClient. </summary>
 26        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 27        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 28        /// <param name="endpoint"> server parameter. </param>
 29        /// <param name="apiVersion"> Api Version. </param>
 30        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 6031        public EventRoutesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, st
 32        {
 6033            endpoint ??= new Uri("https://digitaltwins-name.digitaltwins.azure.net");
 6034            if (apiVersion == null)
 35            {
 036                throw new ArgumentNullException(nameof(apiVersion));
 37            }
 38
 6039            this.endpoint = endpoint;
 6040            this.apiVersion = apiVersion;
 6041            _clientDiagnostics = clientDiagnostics;
 6042            _pipeline = pipeline;
 6043        }
 44
 45        internal HttpMessage CreateListRequest(EventRoutesListOptions eventRoutesListOptions)
 46        {
 447            var message = _pipeline.CreateMessage();
 448            var request = message.Request;
 449            request.Method = RequestMethod.Get;
 450            var uri = new RawRequestUriBuilder();
 451            uri.Reset(endpoint);
 452            uri.AppendPath("/eventroutes", false);
 453            uri.AppendQuery("api-version", apiVersion, true);
 454            request.Uri = uri;
 455            if (eventRoutesListOptions?.MaxItemCount != null)
 56            {
 057                request.Headers.Add("x-ms-max-item-count", eventRoutesListOptions.MaxItemCount.Value);
 58            }
 459            return message;
 60        }
 61
 62        /// <summary>
 63        /// Retrieves all event routes.
 64        /// Status codes:
 65        /// 200 (OK): Success.
 66        /// 400 (Bad Request): The request is invalid.
 67        /// </summary>
 68        /// <param name="eventRoutesListOptions"> Parameter group. </param>
 69        /// <param name="cancellationToken"> The cancellation token to use. </param>
 70        public async Task<Response<EventRouteCollection>> ListAsync(EventRoutesListOptions eventRoutesListOptions = null
 71        {
 272            using var message = CreateListRequest(eventRoutesListOptions);
 273            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 274            switch (message.Response.Status)
 75            {
 76                case 200:
 77                    {
 78                        EventRouteCollection value = default;
 279                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 280                        value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement);
 281                        return Response.FromValue(value, message.Response);
 82                    }
 83                default:
 084                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 85            }
 286        }
 87
 88        /// <summary>
 89        /// Retrieves all event routes.
 90        /// Status codes:
 91        /// 200 (OK): Success.
 92        /// 400 (Bad Request): The request is invalid.
 93        /// </summary>
 94        /// <param name="eventRoutesListOptions"> Parameter group. </param>
 95        /// <param name="cancellationToken"> The cancellation token to use. </param>
 96        public Response<EventRouteCollection> List(EventRoutesListOptions eventRoutesListOptions = null, CancellationTok
 97        {
 298            using var message = CreateListRequest(eventRoutesListOptions);
 299            _pipeline.Send(message, cancellationToken);
 2100            switch (message.Response.Status)
 101            {
 102                case 200:
 103                    {
 104                        EventRouteCollection value = default;
 2105                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2106                        value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement);
 2107                        return Response.FromValue(value, message.Response);
 108                    }
 109                default:
 0110                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 111            }
 2112        }
 113
 114        internal HttpMessage CreateGetByIdRequest(string id)
 115        {
 12116            var message = _pipeline.CreateMessage();
 12117            var request = message.Request;
 12118            request.Method = RequestMethod.Get;
 12119            var uri = new RawRequestUriBuilder();
 12120            uri.Reset(endpoint);
 12121            uri.AppendPath("/eventroutes/", false);
 12122            uri.AppendPath(id, true);
 12123            uri.AppendQuery("api-version", apiVersion, true);
 12124            request.Uri = uri;
 12125            return message;
 126        }
 127
 128        /// <summary>
 129        /// Retrieves an event route.
 130        /// Status codes:
 131        /// 200 (OK): Success.
 132        /// 404 (Not Found): There is no event route with the provided id.
 133        /// </summary>
 134        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 135        /// <param name="cancellationToken"> The cancellation token to use. </param>
 136        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 137        public async Task<Response<EventRoute>> GetByIdAsync(string id, CancellationToken cancellationToken = default)
 138        {
 6139            if (id == null)
 140            {
 0141                throw new ArgumentNullException(nameof(id));
 142            }
 143
 6144            using var message = CreateGetByIdRequest(id);
 6145            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 6146            switch (message.Response.Status)
 147            {
 148                case 200:
 149                    {
 150                        EventRoute value = default;
 2151                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2152                        value = EventRoute.DeserializeEventRoute(document.RootElement);
 2153                        return Response.FromValue(value, message.Response);
 154                    }
 155                default:
 4156                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 157            }
 2158        }
 159
 160        /// <summary>
 161        /// Retrieves an event route.
 162        /// Status codes:
 163        /// 200 (OK): Success.
 164        /// 404 (Not Found): There is no event route with the provided id.
 165        /// </summary>
 166        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 167        /// <param name="cancellationToken"> The cancellation token to use. </param>
 168        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 169        public Response<EventRoute> GetById(string id, CancellationToken cancellationToken = default)
 170        {
 6171            if (id == null)
 172            {
 0173                throw new ArgumentNullException(nameof(id));
 174            }
 175
 6176            using var message = CreateGetByIdRequest(id);
 6177            _pipeline.Send(message, cancellationToken);
 6178            switch (message.Response.Status)
 179            {
 180                case 200:
 181                    {
 182                        EventRoute value = default;
 2183                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2184                        value = EventRoute.DeserializeEventRoute(document.RootElement);
 2185                        return Response.FromValue(value, message.Response);
 186                    }
 187                default:
 4188                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 189            }
 2190        }
 191
 192        internal HttpMessage CreateAddRequest(string id, EventRoute eventRoute)
 193        {
 12194            var message = _pipeline.CreateMessage();
 12195            var request = message.Request;
 12196            request.Method = RequestMethod.Put;
 12197            var uri = new RawRequestUriBuilder();
 12198            uri.Reset(endpoint);
 12199            uri.AppendPath("/eventroutes/", false);
 12200            uri.AppendPath(id, true);
 12201            uri.AppendQuery("api-version", apiVersion, true);
 12202            request.Uri = uri;
 12203            request.Headers.Add("Content-Type", "application/json");
 12204            if (eventRoute != null)
 205            {
 12206                var content = new Utf8JsonRequestContent();
 12207                content.JsonWriter.WriteObjectValue(eventRoute);
 12208                request.Content = content;
 209            }
 12210            return message;
 211        }
 212
 213        /// <summary>
 214        /// Adds or replaces an event route.
 215        /// Status codes:
 216        /// 200 (OK): Success.
 217        /// 400 (Bad Request): The request is invalid.
 218        /// </summary>
 219        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 220        /// <param name="eventRoute"> The event route data. </param>
 221        /// <param name="cancellationToken"> The cancellation token to use. </param>
 222        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 223        public async Task<Response> AddAsync(string id, EventRoute eventRoute = null, CancellationToken cancellationToke
 224        {
 6225            if (id == null)
 226            {
 0227                throw new ArgumentNullException(nameof(id));
 228            }
 229
 6230            using var message = CreateAddRequest(id, eventRoute);
 6231            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 6232            switch (message.Response.Status)
 233            {
 234                case 204:
 4235                    return message.Response;
 236                default:
 2237                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 238            }
 4239        }
 240
 241        /// <summary>
 242        /// Adds or replaces an event route.
 243        /// Status codes:
 244        /// 200 (OK): Success.
 245        /// 400 (Bad Request): The request is invalid.
 246        /// </summary>
 247        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 248        /// <param name="eventRoute"> The event route data. </param>
 249        /// <param name="cancellationToken"> The cancellation token to use. </param>
 250        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 251        public Response Add(string id, EventRoute eventRoute = null, CancellationToken cancellationToken = default)
 252        {
 6253            if (id == null)
 254            {
 0255                throw new ArgumentNullException(nameof(id));
 256            }
 257
 6258            using var message = CreateAddRequest(id, eventRoute);
 6259            _pipeline.Send(message, cancellationToken);
 6260            switch (message.Response.Status)
 261            {
 262                case 204:
 4263                    return message.Response;
 264                default:
 2265                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 266            }
 4267        }
 268
 269        internal HttpMessage CreateDeleteRequest(string id)
 270        {
 8271            var message = _pipeline.CreateMessage();
 8272            var request = message.Request;
 8273            request.Method = RequestMethod.Delete;
 8274            var uri = new RawRequestUriBuilder();
 8275            uri.Reset(endpoint);
 8276            uri.AppendPath("/eventroutes/", false);
 8277            uri.AppendPath(id, true);
 8278            uri.AppendQuery("api-version", apiVersion, true);
 8279            request.Uri = uri;
 8280            return message;
 281        }
 282
 283        /// <summary>
 284        /// Deletes an event route.
 285        /// Status codes:
 286        /// 200 (OK): Success.
 287        /// 404 (Not Found): There is no event route with the provided id.
 288        /// </summary>
 289        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 290        /// <param name="cancellationToken"> The cancellation token to use. </param>
 291        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 292        public async Task<Response> DeleteAsync(string id, CancellationToken cancellationToken = default)
 293        {
 4294            if (id == null)
 295            {
 0296                throw new ArgumentNullException(nameof(id));
 297            }
 298
 4299            using var message = CreateDeleteRequest(id);
 4300            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 4301            switch (message.Response.Status)
 302            {
 303                case 204:
 4304                    return message.Response;
 305                default:
 0306                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 307            }
 4308        }
 309
 310        /// <summary>
 311        /// Deletes an event route.
 312        /// Status codes:
 313        /// 200 (OK): Success.
 314        /// 404 (Not Found): There is no event route with the provided id.
 315        /// </summary>
 316        /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para
 317        /// <param name="cancellationToken"> The cancellation token to use. </param>
 318        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 319        public Response Delete(string id, CancellationToken cancellationToken = default)
 320        {
 4321            if (id == null)
 322            {
 0323                throw new ArgumentNullException(nameof(id));
 324            }
 325
 4326            using var message = CreateDeleteRequest(id);
 4327            _pipeline.Send(message, cancellationToken);
 4328            switch (message.Response.Status)
 329            {
 330                case 204:
 4331                    return message.Response;
 332                default:
 0333                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 334            }
 4335        }
 336
 337        internal HttpMessage CreateListNextPageRequest(string nextLink, EventRoutesListOptions eventRoutesListOptions)
 338        {
 0339            var message = _pipeline.CreateMessage();
 0340            var request = message.Request;
 0341            request.Method = RequestMethod.Get;
 0342            var uri = new RawRequestUriBuilder();
 0343            uri.Reset(endpoint);
 0344            uri.AppendRawNextLink(nextLink, false);
 0345            request.Uri = uri;
 0346            if (eventRoutesListOptions?.MaxItemCount != null)
 347            {
 0348                request.Headers.Add("x-ms-max-item-count", eventRoutesListOptions.MaxItemCount.Value);
 349            }
 0350            return message;
 351        }
 352
 353        /// <summary>
 354        /// Retrieves all event routes.
 355        /// Status codes:
 356        /// 200 (OK): Success.
 357        /// 400 (Bad Request): The request is invalid.
 358        /// </summary>
 359        /// <param name="nextLink"> The URL to the next page of results. </param>
 360        /// <param name="eventRoutesListOptions"> Parameter group. </param>
 361        /// <param name="cancellationToken"> The cancellation token to use. </param>
 362        /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception>
 363        public async Task<Response<EventRouteCollection>> ListNextPageAsync(string nextLink, EventRoutesListOptions even
 364        {
 0365            if (nextLink == null)
 366            {
 0367                throw new ArgumentNullException(nameof(nextLink));
 368            }
 369
 0370            using var message = CreateListNextPageRequest(nextLink, eventRoutesListOptions);
 0371            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0372            switch (message.Response.Status)
 373            {
 374                case 200:
 375                    {
 376                        EventRouteCollection value = default;
 0377                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0378                        value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement);
 0379                        return Response.FromValue(value, message.Response);
 380                    }
 381                default:
 0382                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 383            }
 0384        }
 385
 386        /// <summary>
 387        /// Retrieves all event routes.
 388        /// Status codes:
 389        /// 200 (OK): Success.
 390        /// 400 (Bad Request): The request is invalid.
 391        /// </summary>
 392        /// <param name="nextLink"> The URL to the next page of results. </param>
 393        /// <param name="eventRoutesListOptions"> Parameter group. </param>
 394        /// <param name="cancellationToken"> The cancellation token to use. </param>
 395        /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception>
 396        public Response<EventRouteCollection> ListNextPage(string nextLink, EventRoutesListOptions eventRoutesListOption
 397        {
 0398            if (nextLink == null)
 399            {
 0400                throw new ArgumentNullException(nameof(nextLink));
 401            }
 402
 0403            using var message = CreateListNextPageRequest(nextLink, eventRoutesListOptions);
 0404            _pipeline.Send(message, cancellationToken);
 0405            switch (message.Response.Status)
 406            {
 407                case 200:
 408                    {
 409                        EventRouteCollection value = default;
 0410                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0411                        value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement);
 0412                        return Response.FromValue(value, message.Response);
 413                    }
 414                default:
 0415                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 416            }
 0417        }
 418    }
 419}