< Summary

Class:Azure.Iot.Hub.Service.StatisticsRestClient
Assembly:Azure.Iot.Hub.Service
File(s):C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\StatisticsRestClient.cs
Covered lines:54
Uncovered lines:5
Coverable lines:59
Total lines:152
Line coverage:91.5% (54 of 59)
Covered branches:6
Total branches:12
Branch coverage:50% (6 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateGetDeviceStatisticsRequest()-100%100%
GetDeviceStatisticsAsync()-87.5%50%
GetDeviceStatistics(...)-87.5%50%
CreateGetServiceStatisticsRequest()-100%100%
GetServiceStatisticsAsync()-87.5%50%
GetServiceStatistics(...)-87.5%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\StatisticsRestClient.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;
 15using Azure.Iot.Hub.Service.Models;
 16
 17namespace Azure.Iot.Hub.Service
 18{
 19    internal partial class StatisticsRestClient
 20    {
 21        private Uri endpoint;
 22        private string apiVersion;
 23        private ClientDiagnostics _clientDiagnostics;
 24        private HttpPipeline _pipeline;
 25
 26        /// <summary> Initializes a new instance of StatisticsRestClient. </summary>
 27        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 28        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 29        /// <param name="endpoint"> server parameter. </param>
 30        /// <param name="apiVersion"> Api Version. </param>
 31        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 7632        public StatisticsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, str
 33        {
 7634            endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net");
 7635            if (apiVersion == null)
 36            {
 037                throw new ArgumentNullException(nameof(apiVersion));
 38            }
 39
 7640            this.endpoint = endpoint;
 7641            this.apiVersion = apiVersion;
 7642            _clientDiagnostics = clientDiagnostics;
 7643            _pipeline = pipeline;
 7644        }
 45
 46        internal HttpMessage CreateGetDeviceStatisticsRequest()
 47        {
 448            var message = _pipeline.CreateMessage();
 449            var request = message.Request;
 450            request.Method = RequestMethod.Get;
 451            var uri = new RawRequestUriBuilder();
 452            uri.Reset(endpoint);
 453            uri.AppendPath("/statistics/devices", false);
 454            uri.AppendQuery("api-version", apiVersion, true);
 455            request.Uri = uri;
 456            return message;
 57        }
 58
 59        /// <summary> Gets device statistics of the IoT Hub identity registry, such as total device count. </summary>
 60        /// <param name="cancellationToken"> The cancellation token to use. </param>
 61        public async Task<Response<DevicesStatistics>> GetDeviceStatisticsAsync(CancellationToken cancellationToken = de
 62        {
 263            using var message = CreateGetDeviceStatisticsRequest();
 264            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 265            switch (message.Response.Status)
 66            {
 67                case 200:
 68                    {
 69                        DevicesStatistics value = default;
 270                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 271                        value = DevicesStatistics.DeserializeDevicesStatistics(document.RootElement);
 272                        return Response.FromValue(value, message.Response);
 73                    }
 74                default:
 075                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 76            }
 277        }
 78
 79        /// <summary> Gets device statistics of the IoT Hub identity registry, such as total device count. </summary>
 80        /// <param name="cancellationToken"> The cancellation token to use. </param>
 81        public Response<DevicesStatistics> GetDeviceStatistics(CancellationToken cancellationToken = default)
 82        {
 283            using var message = CreateGetDeviceStatisticsRequest();
 284            _pipeline.Send(message, cancellationToken);
 285            switch (message.Response.Status)
 86            {
 87                case 200:
 88                    {
 89                        DevicesStatistics value = default;
 290                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 291                        value = DevicesStatistics.DeserializeDevicesStatistics(document.RootElement);
 292                        return Response.FromValue(value, message.Response);
 93                    }
 94                default:
 095                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 96            }
 297        }
 98
 99        internal HttpMessage CreateGetServiceStatisticsRequest()
 100        {
 4101            var message = _pipeline.CreateMessage();
 4102            var request = message.Request;
 4103            request.Method = RequestMethod.Get;
 4104            var uri = new RawRequestUriBuilder();
 4105            uri.Reset(endpoint);
 4106            uri.AppendPath("/statistics/service", false);
 4107            uri.AppendQuery("api-version", apiVersion, true);
 4108            request.Uri = uri;
 4109            return message;
 110        }
 111
 112        /// <summary> Gets service statistics of the IoT Hub identity registry, such as connected device count. </summar
 113        /// <param name="cancellationToken"> The cancellation token to use. </param>
 114        public async Task<Response<ServiceStatistics>> GetServiceStatisticsAsync(CancellationToken cancellationToken = d
 115        {
 2116            using var message = CreateGetServiceStatisticsRequest();
 2117            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2118            switch (message.Response.Status)
 119            {
 120                case 200:
 121                    {
 122                        ServiceStatistics value = default;
 2123                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2124                        value = ServiceStatistics.DeserializeServiceStatistics(document.RootElement);
 2125                        return Response.FromValue(value, message.Response);
 126                    }
 127                default:
 0128                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 129            }
 2130        }
 131
 132        /// <summary> Gets service statistics of the IoT Hub identity registry, such as connected device count. </summar
 133        /// <param name="cancellationToken"> The cancellation token to use. </param>
 134        public Response<ServiceStatistics> GetServiceStatistics(CancellationToken cancellationToken = default)
 135        {
 2136            using var message = CreateGetServiceStatisticsRequest();
 2137            _pipeline.Send(message, cancellationToken);
 2138            switch (message.Response.Status)
 139            {
 140                case 200:
 141                    {
 142                        ServiceStatistics value = default;
 2143                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2144                        value = ServiceStatistics.DeserializeServiceStatistics(document.RootElement);
 2145                        return Response.FromValue(value, message.Response);
 146                    }
 147                default:
 0148                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 149            }
 2150        }
 151    }
 152}