public async Task CreateClientAsync() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString()); Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey); #region Snippet:Azure_Search_Tests_Samples_CreateClientAsync // Get the service endpoint and API key from the environment Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create a new SearchIndexClient SearchIndexClient indexClient = new SearchIndexClient(endpoint, credential); #if !SNIPPET indexClient = InstrumentClient(new SearchIndexClient(endpoint, credential, GetSearchClientOptions())); #endif // Perform an operation Response <SearchServiceStatistics> stats = await indexClient.GetServiceStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} indexes."); #endregion Snippet:Azure_Search_Tests_Samples_CreateClientAsync Assert.AreEqual(1, stats.Value.Counters.IndexCounter.Usage); }
public async Task GetStatisticsAsync() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString()); Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey); #region Snippet:Azure_Search_Tests_Samples_GetStatisticsAsync // Create a new SearchIndexClient Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); SearchIndexClient indexClient = new SearchIndexClient(endpoint, credential); /*@@*/ indexClient = InstrumentClient(new SearchIndexClient(endpoint, credential, GetSearchClientOptions())); // Get and report the Search Service statistics Response <SearchServiceStatistics> stats = await indexClient.GetServiceStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} of {stats.Value.Counters.IndexCounter.Quota} indexes."); #endregion Snippet:Azure_Search_Tests_Samples_GetStatisticsAsync }