< Summary

Class:Microsoft.Azure.Search.SearchIndexClient
Assembly:Microsoft.Azure.Search.Data
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\SearchIndexClient.Customization.cs
C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Generated\SearchIndexClient.cs
Covered lines:92
Uncovered lines:18
Coverable lines:110
Total lines:379
Line coverage:83.6% (92 of 110)
Covered branches:7
Total branches:14
Branch coverage:50% (7 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Documents()-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
get_SearchCredentials()-100%100%
get_UseHttpGetForQueries()-100%100%
TargetDifferentIndex(...)-0%100%
CustomInitialize()-100%100%
ValidateSearchServiceAndIndexNames(...)-100%100%
ThrowIfNullOrEmptyIndexName(...)-100%100%
Initialize(...)-100%100%
get_BaseUri()-100%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_Credentials()-100%100%
get_ApiVersion()-100%100%
get_SearchServiceName()-100%100%
get_SearchDnsSuffix()-100%100%
get_IndexName()-100%100%
get_AcceptLanguage()-100%100%
get_LongRunningOperationRetryTimeout()-0%100%
get_GenerateClientRequestId()-100%100%
get_DocumentsProxy()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
.ctor(...)-0%0%
.ctor(...)-42.86%25%
Initialize()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\SearchIndexClient.Customization.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.Search
 6{
 7    using System;
 8    using System.Net.Http;
 9    using Microsoft.Azure.Search.Common;
 10    using Microsoft.Rest;
 11
 12    public partial class SearchIndexClient
 13    {
 14        /// <summary>
 15        /// Gets the IDocumentsOperations.
 16        /// </summary>
 157417        public virtual IDocumentsOperations Documents { get; private set; }
 18
 19        /// <summary>
 20        /// Initializes a new instance of the SearchIndexClient class.
 21        /// </summary>
 22        /// <param name='searchServiceName'>Required. The name of the search service.</param>
 23        /// <param name='indexName'>Required. The name of the search index.</param>
 24        /// <param name='credentials'>Required. The credentials used to authenticate to a search service.
 25        /// <see href="https://docs.microsoft.com/rest/api/searchservice/" />
 26        /// </param>
 27        public SearchIndexClient(string searchServiceName, string indexName, SearchCredentials credentials)
 1428            : this()
 29        {
 1430            Initialize(searchServiceName, indexName, credentials);
 231        }
 32
 33        /// <summary>
 34        /// Initializes a new instance of the SearchIndexClient class.
 35        /// </summary>
 36        /// <param name='searchServiceName'>Required. The name of the search service.</param>
 37        /// <param name='indexName'>Required. The name of the search index.</param>
 38        /// <param name='credentials'>Required. The credentials used to authenticate to a search service.
 39        /// <see href="https://docs.microsoft.com/rest/api/searchservice/" />
 40        /// </param>
 41        /// <param name='rootHandler'>
 42        /// Optional. The http client handler used to handle http transport.
 43        /// </param>
 44        /// <param name='handlers'>
 45        /// Optional. The set of delegating handlers to insert in the http
 46        /// client pipeline.
 47        /// </param>
 48        public SearchIndexClient(
 49            string searchServiceName,
 50            string indexName,
 51            SearchCredentials credentials,
 52            HttpClientHandler rootHandler,
 53            params DelegatingHandler[] handlers)
 2054            : this(rootHandler, handlers)
 55        {
 2056            Initialize(searchServiceName, indexName, credentials);
 857        }
 58
 59        /// <summary>
 60        /// Gets the credentials used to authenticate to a search service. This can be either a query API key or an admi
 61        /// </summary>
 62        /// <remarks>
 63        /// See <see href="https://docs.microsoft.com/azure/search/search-security-api-keys">Create and manage api-keys 
 64        /// </remarks>
 465        public SearchCredentials SearchCredentials => (SearchCredentials)Credentials;
 66
 67        /// <summary>
 68        /// Indicates whether the index client should use HTTP GET for making Search, Suggest, and Autocomplete requests
 69        /// Azure Cognitive Search REST API. The default is <c>false</c>, which indicates that HTTP POST will be used.
 70        /// </summary>
 52471        public bool UseHttpGetForQueries { get; set; }
 72
 73        /// <summary>
 74        /// Changes the BaseUri of this client to target a different index in the same Azure Cognitive Search service. T
 75        /// must guarantee that no other threads are using the client before calling it.
 76        /// </summary>
 77        /// <param name="newIndexName">The name of the index to which all subsequent requests should be sent.</param>
 78        [Obsolete("This method is deprecated. Please set the IndexName property instead.")]
 79        public void TargetDifferentIndex(string newIndexName)
 80        {
 081            ThrowIfNullOrEmptyIndexName(newIndexName, nameof(newIndexName));
 082            IndexName = newIndexName;
 083        }
 84
 85        partial void CustomInitialize()
 86        {
 68887            Documents = new DocumentsOperations(this);
 68888        }
 89
 90        private static void ValidateSearchServiceAndIndexNames(string searchServiceName, string indexName)
 91        {
 3092            Throw.IfNullOrEmptySearchServiceName(searchServiceName);
 2293            ThrowIfNullOrEmptyIndexName(indexName, nameof(indexName));
 94
 1495            Uri uri = TypeConversion.TryParseUri($"https://{searchServiceName}.search.windows.net/indexes('{indexName}')
 96
 1497            if (uri == null)
 98            {
 499                throw new ArgumentException(
 4100                    $"Either the search service name '{searchServiceName}' or the index name '{indexName}' is invalid. N
 4101                    nameof(searchServiceName));
 102            }
 10103        }
 104
 105        private static void ThrowIfNullOrEmptyIndexName(string name, string paramName) =>
 22106            Throw.IfArgumentNullOrEmpty(
 22107                name,
 22108                paramName,
 22109                "Invalid index name. Name cannot be null or an empty string.");
 110
 111        private void Initialize(string searchServiceName, string indexName, SearchCredentials credentials)
 112        {
 34113            Throw.IfArgumentNull(credentials, nameof(credentials));
 30114            ValidateSearchServiceAndIndexNames(searchServiceName, indexName);
 115
 10116            SearchServiceName = searchServiceName;
 10117            IndexName = indexName;
 118
 10119            Credentials = credentials;
 10120            Credentials.InitializeServiceClient(this);
 10121        }
 122    }
 123}

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Generated\SearchIndexClient.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.Search
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Microsoft.Rest.Serialization;
 16    using Models;
 17    using Newtonsoft.Json;
 18    using System.Collections;
 19    using System.Collections.Generic;
 20    using System.Linq;
 21    using System.Net;
 22    using System.Net.Http;
 23
 24    /// <summary>
 25    /// Client that can be used to query an index and upload, merge, or delete
 26    /// documents.
 27    /// </summary>
 28    public partial class SearchIndexClient : ServiceClient<SearchIndexClient>, ISearchIndexClient, IAzureClient
 29    {
 30        /// <summary>
 31        /// The base URI of the service.
 32        /// </summary>
 154233        internal string BaseUri {get; set;}
 34
 35        /// <summary>
 36        /// Gets or sets json serialization settings.
 37        /// </summary>
 161638        public JsonSerializerSettings SerializationSettings { get; private set; }
 39
 40        /// <summary>
 41        /// Gets or sets json deserialization settings.
 42        /// </summary>
 229643        public JsonSerializerSettings DeserializationSettings { get; private set; }
 44
 45        /// <summary>
 46        /// Credentials needed for the client to connect to Azure.
 47        /// </summary>
 374648        public ServiceClientCredentials Credentials { get; private set; }
 49
 50        /// <summary>
 51        /// Client Api Version.
 52        /// </summary>
 328253        public string ApiVersion { get; private set; }
 54
 55        /// <summary>
 56        /// The name of the search service.
 57        /// </summary>
 237258        public string SearchServiceName { get; set; }
 59
 60        /// <summary>
 61        /// The DNS suffix of the search service. The default is search.windows.net.
 62        /// </summary>
 305863        public string SearchDnsSuffix { get; set; }
 64
 65        /// <summary>
 66        /// The name of the index.
 67        /// </summary>
 237868        public string IndexName { get; set; }
 69
 70        /// <summary>
 71        /// The preferred language for the response.
 72        /// </summary>
 246073        public string AcceptLanguage { get; set; }
 74
 75        /// <summary>
 76        /// The retry timeout in seconds for Long Running Operations. Default value is
 77        /// 30.
 78        /// </summary>
 079        public int? LongRunningOperationRetryTimeout { get; set; }
 80
 81        /// <summary>
 82        /// Whether a unique x-ms-client-request-id should be generated. When set to
 83        /// true a unique x-ms-client-request-id value is generated and included in
 84        /// each request. Default is true.
 85        /// </summary>
 246086        public bool? GenerateClientRequestId { get; set; }
 87
 88        /// <summary>
 89        /// Gets the IDocumentsProxyOperations.
 90        /// </summary>
 157491        internal IDocumentsProxyOperations DocumentsProxy { get; private set; }
 92
 93        /// <summary>
 94        /// Initializes a new instance of the SearchIndexClient class.
 95        /// </summary>
 96        /// <param name='httpClient'>
 97        /// HttpClient to be used
 98        /// </param>
 99        /// <param name='disposeHttpClient'>
 100        /// True: will dispose the provided httpClient on calling SearchIndexClient.Dispose(). False: will not dispose p
 0101        protected SearchIndexClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient)
 102        {
 0103            Initialize();
 0104        }
 105
 106        /// <summary>
 107        /// Initializes a new instance of the SearchIndexClient class.
 108        /// </summary>
 109        /// <param name='handlers'>
 110        /// Optional. The delegating handlers to add to the http client pipeline.
 111        /// </param>
 666112        protected SearchIndexClient(params DelegatingHandler[] handlers) : base(handlers)
 113        {
 666114            Initialize();
 666115        }
 116
 117        /// <summary>
 118        /// Initializes a new instance of the SearchIndexClient class.
 119        /// </summary>
 120        /// <param name='rootHandler'>
 121        /// Optional. The http client handler used to handle http transport.
 122        /// </param>
 123        /// <param name='handlers'>
 124        /// Optional. The delegating handlers to add to the http client pipeline.
 125        /// </param>
 22126        protected SearchIndexClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandl
 127        {
 22128            Initialize();
 22129        }
 130
 131        /// <summary>
 132        /// Initializes a new instance of the SearchIndexClient class.
 133        /// </summary>
 134        /// <param name='credentials'>
 135        /// Required. Credentials needed for the client to connect to Azure.
 136        /// </param>
 137        /// <param name='handlers'>
 138        /// Optional. The delegating handlers to add to the http client pipeline.
 139        /// </param>
 140        /// <exception cref="System.ArgumentNullException">
 141        /// Thrown when a required parameter is null
 142        /// </exception>
 652143        public SearchIndexClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handl
 144        {
 652145            if (credentials == null)
 146            {
 2147                throw new System.ArgumentNullException("credentials");
 148            }
 650149            Credentials = credentials;
 650150            if (Credentials != null)
 151            {
 650152                Credentials.InitializeServiceClient(this);
 153            }
 650154        }
 155
 156        /// <summary>
 157        /// Initializes a new instance of the SearchIndexClient class.
 158        /// </summary>
 159        /// <param name='credentials'>
 160        /// Required. Credentials needed for the client to connect to Azure.
 161        /// </param>
 162        /// <param name='httpClient'>
 163        /// HttpClient to be used
 164        /// </param>
 165        /// <param name='disposeHttpClient'>
 166        /// True: will dispose the provided httpClient on calling SearchIndexClient.Dispose(). False: will not dispose p
 167        /// <exception cref="System.ArgumentNullException">
 168        /// Thrown when a required parameter is null
 169        /// </exception>
 0170        public SearchIndexClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : 
 171        {
 0172            if (credentials == null)
 173            {
 0174                throw new System.ArgumentNullException("credentials");
 175            }
 0176            Credentials = credentials;
 0177            if (Credentials != null)
 178            {
 0179                Credentials.InitializeServiceClient(this);
 180            }
 0181        }
 182
 183        /// <summary>
 184        /// Initializes a new instance of the SearchIndexClient class.
 185        /// </summary>
 186        /// <param name='credentials'>
 187        /// Required. Credentials needed for the client to connect to Azure.
 188        /// </param>
 189        /// <param name='rootHandler'>
 190        /// Optional. The http client handler used to handle http transport.
 191        /// </param>
 192        /// <param name='handlers'>
 193        /// Optional. The delegating handlers to add to the http client pipeline.
 194        /// </param>
 195        /// <exception cref="System.ArgumentNullException">
 196        /// Thrown when a required parameter is null
 197        /// </exception>
 2198        public SearchIndexClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingH
 199        {
 2200            if (credentials == null)
 201            {
 2202                throw new System.ArgumentNullException("credentials");
 203            }
 0204            Credentials = credentials;
 0205            if (Credentials != null)
 206            {
 0207                Credentials.InitializeServiceClient(this);
 208            }
 0209        }
 210
 211        /// <summary>
 212        /// An optional partial-method to perform custom initialization.
 213        /// </summary>
 214        partial void CustomInitialize();
 215        /// <summary>
 216        /// Initializes client properties.
 217        /// </summary>
 218        private void Initialize()
 219        {
 688220            DocumentsProxy = new DocumentsProxyOperations(this);
 688221            BaseUri = "https://{searchServiceName}.{searchDnsSuffix}/indexes('{indexName}')";
 688222            ApiVersion = "2019-05-06";
 688223            SearchDnsSuffix = "search.windows.net";
 688224            AcceptLanguage = "en-US";
 688225            LongRunningOperationRetryTimeout = 30;
 688226            GenerateClientRequestId = true;
 688227            SerializationSettings = new JsonSerializerSettings
 688228            {
 688229                Formatting = Newtonsoft.Json.Formatting.Indented,
 688230                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 688231                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 688232                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 688233                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 688234                ContractResolver = new ReadOnlyJsonContractResolver(),
 688235                Converters = new List<JsonConverter>
 688236                    {
 688237                        new Iso8601TimeSpanConverter()
 688238                    }
 688239            };
 688240            DeserializationSettings = new JsonSerializerSettings
 688241            {
 688242                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 688243                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 688244                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 688245                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 688246                ContractResolver = new ReadOnlyJsonContractResolver(),
 688247                Converters = new List<JsonConverter>
 688248                    {
 688249                        new Iso8601TimeSpanConverter()
 688250                    }
 688251            };
 688252            CustomInitialize();
 688253            DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 688254        }
 255    }
 256}