< Summary

Class:Azure.Search.Documents.ServiceRestClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\ServiceRestClient.cs
Covered lines:34
Uncovered lines:5
Coverable lines:39
Total lines:110
Line coverage:87.1% (34 of 39)
Covered branches:5
Total branches:10
Branch coverage:50% (5 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-81.82%50%
CreateGetServiceStatisticsRequest()-91.67%50%
GetServiceStatisticsAsync()-87.5%50%
GetServiceStatistics(...)-87.5%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\ServiceRestClient.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.Search.Documents.Indexes.Models;
 16
 17namespace Azure.Search.Documents
 18{
 19    internal partial class ServiceRestClient
 20    {
 21        private string endpoint;
 22        private Guid? xMsClientRequestId;
 23        private string apiVersion;
 24        private ClientDiagnostics _clientDiagnostics;
 25        private HttpPipeline _pipeline;
 26
 27        /// <summary> Initializes a new instance of ServiceRestClient. </summary>
 28        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 29        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 30        /// <param name="endpoint"> The endpoint URL of the search service. </param>
 31        /// <param name="xMsClientRequestId"> The tracking ID sent with the request to help with debugging. </param>
 32        /// <param name="apiVersion"> Api Version. </param>
 33        /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="apiVersion"/> is nul
 634        public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMsC
 35        {
 636            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 640            if (apiVersion == null)
 41            {
 042                throw new ArgumentNullException(nameof(apiVersion));
 43            }
 44
 645            this.endpoint = endpoint;
 646            this.xMsClientRequestId = xMsClientRequestId;
 647            this.apiVersion = apiVersion;
 648            _clientDiagnostics = clientDiagnostics;
 649            _pipeline = pipeline;
 650        }
 51
 52        internal HttpMessage CreateGetServiceStatisticsRequest()
 53        {
 654            var message = _pipeline.CreateMessage();
 655            var request = message.Request;
 656            request.Method = RequestMethod.Get;
 657            var uri = new RawRequestUriBuilder();
 658            uri.AppendRaw(endpoint, false);
 659            uri.AppendPath("/servicestats", false);
 660            uri.AppendQuery("api-version", apiVersion, true);
 661            request.Uri = uri;
 662            if (xMsClientRequestId != null)
 63            {
 064                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 65            }
 666            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 667            return message;
 68        }
 69
 70        /// <summary> Gets service level statistics for a search service. </summary>
 71        /// <param name="cancellationToken"> The cancellation token to use. </param>
 72        public async Task<Response<SearchServiceStatistics>> GetServiceStatisticsAsync(CancellationToken cancellationTok
 73        {
 374            using var message = CreateGetServiceStatisticsRequest();
 375            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 376            switch (message.Response.Status)
 77            {
 78                case 200:
 79                    {
 80                        SearchServiceStatistics value = default;
 381                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 382                        value = SearchServiceStatistics.DeserializeSearchServiceStatistics(document.RootElement);
 383                        return Response.FromValue(value, message.Response);
 84                    }
 85                default:
 086                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 87            }
 388        }
 89
 90        /// <summary> Gets service level statistics for a search service. </summary>
 91        /// <param name="cancellationToken"> The cancellation token to use. </param>
 92        public Response<SearchServiceStatistics> GetServiceStatistics(CancellationToken cancellationToken = default)
 93        {
 394            using var message = CreateGetServiceStatisticsRequest();
 395            _pipeline.Send(message, cancellationToken);
 396            switch (message.Response.Status)
 97            {
 98                case 200:
 99                    {
 100                        SearchServiceStatistics value = default;
 3101                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 3102                        value = SearchServiceStatistics.DeserializeSearchServiceStatistics(document.RootElement);
 3103                        return Response.FromValue(value, message.Response);
 104                    }
 105                default:
 0106                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 107            }
 3108        }
 109    }
 110}