< Summary

Class:Microsoft.Extensions.Azure.SearchClientBuilderExtensions
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\SearchClientBuilderExtensions.cs
Covered lines:0
Uncovered lines:6
Coverable lines:6
Total lines:110
Line coverage:0% (0 of 6)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
AddSearchClient(...)-0%100%
AddSearchClient(...)-0%100%
AddSearchIndexClient(...)-0%100%
AddSearchIndexClient(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\SearchClientBuilderExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure;
 6using Azure.Core.Extensions;
 7using Azure.Search.Documents;
 8using Azure.Search.Documents.Indexes;
 9
 10namespace Microsoft.Extensions.Azure
 11{
 12    /// <summary>
 13    /// Extension methods to add <see cref="SearchClient"/> to the Azure client
 14    /// builder.
 15    /// </summary>
 16    public static class SearchClientBuilderExtensions
 17    {
 18        /// <summary>
 19        /// Registers a <see cref="SearchClient"/> instance with the provided
 20        /// <paramref name="endpoint"/>, <paramref name="indexName"/>, and
 21        /// <paramref name="credential"/>.
 22        /// </summary>
 23        /// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
 24        /// <param name="builder">The client factory builder.</param>
 25        /// <param name="endpoint">
 26        /// Required.  The URI endpoint of the Search Service.  This is likely
 27        /// to be similar to "https://{search_service}.search.windows.net".
 28        /// The URI must use HTTPS.
 29        /// </param>
 30        /// <param name="indexName">
 31        /// Required.  The name of the Search Index.
 32        /// </param>
 33        /// <param name="credential">
 34        /// Required.  The API key credential used to authenticate requests
 35        /// against the search service.  You need to use an admin key to
 36        /// modify the documents in a Search Index.  See
 37        /// <see href="https://docs.microsoft.com/azure/search/search-security-api-keys">Create and manage api-keys for 
 38        /// for more information about API keys in Azure Cognitive Search.
 39        /// </param>
 40        /// <returns>An Azure client builder.</returns>
 41        public static IAzureClientBuilder<SearchClient, SearchClientOptions> AddSearchClient<TBuilder>(
 42            this TBuilder builder,
 43            Uri endpoint,
 44            string indexName,
 45            AzureKeyCredential credential)
 46            where TBuilder : IAzureClientFactoryBuilder =>
 047            builder.RegisterClientFactory<SearchClient, SearchClientOptions>(
 048                options => new SearchClient(endpoint, indexName, credential, options));
 49
 50        /// <summary>
 51        /// Registers a <see cref="SearchClient"/> instance with connection
 52        /// options loaded from the provided <paramref name="configuration"/>
 53        /// instance.
 54        /// </summary>
 55        /// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
 56        /// <typeparam name="TConfiguration">Type of the configuration.</typeparam>
 57        /// <param name="builder">The client factory builder.</param>
 58        /// <param name="configuration">The client configuration.</param>
 59        /// <returns>An Azure client builder.</returns>
 60        public static IAzureClientBuilder<SearchClient, SearchClientOptions> AddSearchClient<TBuilder, TConfiguration>(
 61            this TBuilder builder,
 62            TConfiguration configuration)
 63            where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> =>
 064            builder.RegisterClientFactory<SearchClient, SearchClientOptions>(configuration);
 65
 66
 67        /// <summary>
 68        /// Registers a <see cref="SearchIndexClient"/> instance with the
 69        /// provided <paramref name="endpoint"/> and <paramref name="credential"/>.
 70        /// </summary>
 71        /// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
 72        /// <param name="builder">The client factory builder.</param>
 73        /// <param name="endpoint">
 74        /// Required.  The URI endpoint of the Search Service.  This is likely
 75        /// to be similar to "https://{search_service}.search.windows.net".
 76        /// The URI must use HTTPS.
 77        /// </param>
 78        /// <param name="credential">
 79        /// Required.  The API key credential used to authenticate requests
 80        /// against the search service.  You need to use an admin key to
 81        /// modify the documents in a Search Index.  See
 82        /// <see href="https://docs.microsoft.com/azure/search/search-security-api-keys">Create and manage api-keys for 
 83        /// for more information about API keys in Azure Cognitive Search.
 84        /// </param>
 85        /// <returns>An Azure client builder.</returns>
 86        public static IAzureClientBuilder<SearchIndexClient, SearchClientOptions> AddSearchIndexClient<TBuilder>(
 87            this TBuilder builder,
 88            Uri endpoint,
 89            AzureKeyCredential credential)
 90            where TBuilder : IAzureClientFactoryBuilder =>
 091            builder.RegisterClientFactory<SearchIndexClient, SearchClientOptions>(
 092                options => new SearchIndexClient(endpoint, credential, options));
 93
 94        /// <summary>
 95        /// Registers a <see cref="SearchIndexClient"/> instance with connection
 96        /// options loaded from the provided <paramref name="configuration"/>
 97        /// instance.
 98        /// </summary>
 99        /// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
 100        /// <typeparam name="TConfiguration">Type of the configuration.</typeparam>
 101        /// <param name="builder">The client factory builder.</param>
 102        /// <param name="configuration">The client configuration.</param>
 103        /// <returns>An Azure client builder.</returns>
 104        public static IAzureClientBuilder<SearchIndexClient, SearchClientOptions> AddSearchIndexClient<TBuilder, TConfig
 105            this TBuilder builder,
 106            TConfiguration configuration)
 107            where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> =>
 0108            builder.RegisterClientFactory<SearchIndexClient, SearchClientOptions>(configuration);
 109    }
 110}