public async Task HandleErrors() { 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_HandleErrors Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); SearchApiKeyCredential credential = new SearchApiKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create an invalid SearchIndexClientClient string fakeIndexName = "doesnotexist"; SearchIndexClient index = new SearchIndexClient(endpoint, fakeIndexName, credential); /*@@*/ index = InstrumentClient(new SearchIndexClient(endpoint, fakeIndexName, credential, GetSearchClientOptions())); try { //@@ index.GetCount(); /*@@*/ await index.GetDocumentCountAsync(); } catch (RequestFailedException ex) when(ex.Status == 404) { Console.WriteLine("Index wasn't found."); } #endregion Snippet:Azure_Search_Tests_Samples_HandleErrors }
public async Task GetDocumentCount() { await using SearchResources search = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = search.GetIndexClient(); Response <long> response = await client.GetDocumentCountAsync(); Assert.AreEqual(200, response.GetRawResponse().Status); Assert.AreEqual(SearchResources.TestDocuments.Length, response.Value); }
public async Task ClientRequestIdRountrips() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = resources.GetIndexClient(); Guid id = Recording.Random.NewGuid(); Response <long> response = await client.GetDocumentCountAsync( new SearchRequestOptions { ClientRequestId = id }); // TODO: #10604 - C# generator doesn't properly support ClientRequestId yet // (Assertion is here to remind us to fix this when we do - just // change to AreEqual and re-record) Assert.AreNotEqual(id.ToString(), response.GetRawResponse().ClientRequestId); }
public async Task IndexSharesPipeline() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); TestPipelinePolicy custom = new TestPipelinePolicy(); Assert.AreEqual(0, custom.RequestCount); SearchClientOptions options = new SearchClientOptions(ServiceVersion); options.AddPolicy(custom, HttpPipelinePosition.PerCall); SearchServiceClient client = resources.GetServiceClient(options); SearchIndexClient index = client.GetSearchIndexClient(resources.IndexName); _ = await index.GetDocumentCountAsync(); Assert.AreEqual(1, custom.RequestCount); }
public async Task GetCountAsync() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString()); Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey); Environment.SetEnvironmentVariable("SEARCH_INDEX", resources.IndexName); #region Snippet:Azure_Search_Tests_Samples_GetCountAsync // Create a SearchIndexClient Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); SearchApiKeyCredential credential = new SearchApiKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); string indexName = Environment.GetEnvironmentVariable("SEARCH_INDEX"); SearchIndexClient index = new SearchIndexClient(endpoint, indexName, credential); /*@@*/ index = InstrumentClient(new SearchIndexClient(endpoint, indexName, credential, GetSearchClientOptions())); // Get and report the number of documents in the index Response <long> count = await index.GetDocumentCountAsync(); Console.WriteLine($"Search index {indexName} has {count.Value} documents."); #endregion Snippet:Azure_Search_Tests_Samples_GetCountAsync }