< Summary

Class:Azure.Iot.Hub.Service.QueryRestClient
Assembly:Azure.Iot.Hub.Service
File(s):C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\QueryRestClient.cs
Covered lines:47
Uncovered lines:7
Coverable lines:54
Total lines:141
Line coverage:87% (47 of 54)
Covered branches:12
Total branches:20
Branch coverage:60% (12 of 20)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateGetTwinsRequest(...)-88.24%50%
GetTwinsAsync()-85.71%66.67%
GetTwins(...)-85.71%66.67%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\QueryRestClient.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.Collections.Generic;
 10using System.Text.Json;
 11using System.Threading;
 12using System.Threading.Tasks;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Iot.Hub.Service.Models;
 16
 17namespace Azure.Iot.Hub.Service
 18{
 19    internal partial class QueryRestClient
 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 QueryRestClient. </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 QueryRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string a
 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 CreateGetTwinsRequest(QuerySpecification querySpecification, string xMsContinuation, string
 47        {
 1448            var message = _pipeline.CreateMessage();
 1449            var request = message.Request;
 1450            request.Method = RequestMethod.Post;
 1451            var uri = new RawRequestUriBuilder();
 1452            uri.Reset(endpoint);
 1453            uri.AppendPath("/devices/query", false);
 1454            uri.AppendQuery("api-version", apiVersion, true);
 1455            request.Uri = uri;
 1456            if (xMsContinuation != null)
 57            {
 058                request.Headers.Add("x-ms-continuation", xMsContinuation);
 59            }
 1460            if (xMsMaxItemCount != null)
 61            {
 062                request.Headers.Add("x-ms-max-item-count", xMsMaxItemCount);
 63            }
 1464            request.Headers.Add("Content-Type", "application/json");
 1465            var content = new Utf8JsonRequestContent();
 1466            content.JsonWriter.WriteObjectValue(querySpecification);
 1467            request.Content = content;
 1468            return message;
 69        }
 70
 71        /// <summary> Query an IoT Hub to retrieve information regarding device twins using a SQL-like language. See htt
 72        /// <param name="querySpecification"> The query string. See https://docs.microsoft.com/azure/iot-hub/iot-hub-dev
 73        /// <param name="xMsContinuation"> The continuation token used to get the next page of results. </param>
 74        /// <param name="xMsMaxItemCount"> The maximum number of items returned per page. The service may use a differen
 75        /// <param name="cancellationToken"> The cancellation token to use. </param>
 76        /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception>
 77        public async Task<ResponseWithHeaders<IReadOnlyList<TwinData>, QueryGetTwinsHeaders>> GetTwinsAsync(QuerySpecifi
 78        {
 679            if (querySpecification == null)
 80            {
 081                throw new ArgumentNullException(nameof(querySpecification));
 82            }
 83
 684            using var message = CreateGetTwinsRequest(querySpecification, xMsContinuation, xMsMaxItemCount);
 685            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 686            var headers = new QueryGetTwinsHeaders(message.Response);
 687            switch (message.Response.Status)
 88            {
 89                case 200:
 90                    {
 91                        IReadOnlyList<TwinData> value = default;
 692                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 693                        List<TwinData> array = new List<TwinData>();
 17294                        foreach (var item in document.RootElement.EnumerateArray())
 95                        {
 8096                            array.Add(TwinData.DeserializeTwinData(item));
 97                        }
 698                        value = array;
 699                        return ResponseWithHeaders.FromValue(value, headers, message.Response);
 100                    }
 101                default:
 0102                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 103            }
 6104        }
 105
 106        /// <summary> Query an IoT Hub to retrieve information regarding device twins using a SQL-like language. See htt
 107        /// <param name="querySpecification"> The query string. See https://docs.microsoft.com/azure/iot-hub/iot-hub-dev
 108        /// <param name="xMsContinuation"> The continuation token used to get the next page of results. </param>
 109        /// <param name="xMsMaxItemCount"> The maximum number of items returned per page. The service may use a differen
 110        /// <param name="cancellationToken"> The cancellation token to use. </param>
 111        /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception>
 112        public ResponseWithHeaders<IReadOnlyList<TwinData>, QueryGetTwinsHeaders> GetTwins(QuerySpecification querySpeci
 113        {
 8114            if (querySpecification == null)
 115            {
 0116                throw new ArgumentNullException(nameof(querySpecification));
 117            }
 118
 8119            using var message = CreateGetTwinsRequest(querySpecification, xMsContinuation, xMsMaxItemCount);
 8120            _pipeline.Send(message, cancellationToken);
 8121            var headers = new QueryGetTwinsHeaders(message.Response);
 8122            switch (message.Response.Status)
 123            {
 124                case 200:
 125                    {
 126                        IReadOnlyList<TwinData> value = default;
 8127                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 8128                        List<TwinData> array = new List<TwinData>();
 292129                        foreach (var item in document.RootElement.EnumerateArray())
 130                        {
 138131                            array.Add(TwinData.DeserializeTwinData(item));
 132                        }
 8133                        value = array;
 8134                        return ResponseWithHeaders.FromValue(value, headers, message.Response);
 135                    }
 136                default:
 0137                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 138            }
 8139        }
 140    }
 141}