< Summary

Class:Azure.DigitalTwins.Core.QueryRestClient
Assembly:Azure.DigitalTwins.Core
File(s):C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\src\Generated\QueryRestClient.cs
Covered lines:39
Uncovered lines:5
Coverable lines:44
Total lines:127
Line coverage:88.6% (39 of 44)
Covered branches:6
Total branches:12
Branch coverage:50% (6 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateQueryTwinsRequest(...)-100%100%
QueryTwinsAsync()-81.82%50%
QueryTwins(...)-81.82%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\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.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure.Core;
 13using Azure.Core.Pipeline;
 14
 15namespace Azure.DigitalTwins.Core
 16{
 17    internal partial class QueryRestClient
 18    {
 19        private Uri endpoint;
 20        private string apiVersion;
 21        private ClientDiagnostics _clientDiagnostics;
 22        private HttpPipeline _pipeline;
 23
 24        /// <summary> Initializes a new instance of QueryRestClient. </summary>
 25        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 26        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 27        /// <param name="endpoint"> server parameter. </param>
 28        /// <param name="apiVersion"> Api Version. </param>
 29        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 6030        public QueryRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string a
 31        {
 6032            endpoint ??= new Uri("https://digitaltwins-name.digitaltwins.azure.net");
 6033            if (apiVersion == null)
 34            {
 035                throw new ArgumentNullException(nameof(apiVersion));
 36            }
 37
 6038            this.endpoint = endpoint;
 6039            this.apiVersion = apiVersion;
 6040            _clientDiagnostics = clientDiagnostics;
 6041            _pipeline = pipeline;
 6042        }
 43
 44        internal HttpMessage CreateQueryTwinsRequest(QuerySpecification querySpecification)
 45        {
 446            var message = _pipeline.CreateMessage();
 447            var request = message.Request;
 448            request.Method = RequestMethod.Post;
 449            var uri = new RawRequestUriBuilder();
 450            uri.Reset(endpoint);
 451            uri.AppendPath("/query", false);
 452            uri.AppendQuery("api-version", apiVersion, true);
 453            request.Uri = uri;
 454            request.Headers.Add("Content-Type", "application/json");
 455            var content = new Utf8JsonRequestContent();
 456            content.JsonWriter.WriteObjectValue(querySpecification);
 457            request.Content = content;
 458            return message;
 59        }
 60
 61        /// <summary>
 62        /// Executes a query that allows traversing relationships and filtering by property values.
 63        /// Status codes:
 64        /// 200 (OK): Success.
 65        /// 400 (Bad Request): The request is invalid.
 66        /// </summary>
 67        /// <param name="querySpecification"> The query specification to execute. </param>
 68        /// <param name="cancellationToken"> The cancellation token to use. </param>
 69        /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception>
 70        public async Task<ResponseWithHeaders<QueryResult, QueryQueryTwinsHeaders>> QueryTwinsAsync(QuerySpecification q
 71        {
 272            if (querySpecification == null)
 73            {
 074                throw new ArgumentNullException(nameof(querySpecification));
 75            }
 76
 277            using var message = CreateQueryTwinsRequest(querySpecification);
 278            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 279            var headers = new QueryQueryTwinsHeaders(message.Response);
 280            switch (message.Response.Status)
 81            {
 82                case 200:
 83                    {
 84                        QueryResult value = default;
 285                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 286                        value = QueryResult.DeserializeQueryResult(document.RootElement);
 287                        return ResponseWithHeaders.FromValue(value, headers, message.Response);
 88                    }
 89                default:
 090                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 91            }
 292        }
 93
 94        /// <summary>
 95        /// Executes a query that allows traversing relationships and filtering by property values.
 96        /// Status codes:
 97        /// 200 (OK): Success.
 98        /// 400 (Bad Request): The request is invalid.
 99        /// </summary>
 100        /// <param name="querySpecification"> The query specification to execute. </param>
 101        /// <param name="cancellationToken"> The cancellation token to use. </param>
 102        /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception>
 103        public ResponseWithHeaders<QueryResult, QueryQueryTwinsHeaders> QueryTwins(QuerySpecification querySpecification
 104        {
 2105            if (querySpecification == null)
 106            {
 0107                throw new ArgumentNullException(nameof(querySpecification));
 108            }
 109
 2110            using var message = CreateQueryTwinsRequest(querySpecification);
 2111            _pipeline.Send(message, cancellationToken);
 2112            var headers = new QueryQueryTwinsHeaders(message.Response);
 2113            switch (message.Response.Status)
 114            {
 115                case 200:
 116                    {
 117                        QueryResult value = default;
 2118                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2119                        value = QueryResult.DeserializeQueryResult(document.RootElement);
 2120                        return ResponseWithHeaders.FromValue(value, headers, message.Response);
 121                    }
 122                default:
 0123                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 124            }
 2125        }
 126    }
 127}