public async Task GetDocumentDict() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = resources.GetQueryClient(); Response <SearchDocument> response = await client.GetDocumentAsync("3"); Assert.AreEqual(200, response.GetRawResponse().Status); Assert.AreEqual("3", response.Value["hotelId"]); }
public async Task ThrowsWhenNotFound() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = resources.GetQueryClient(); RequestFailedException ex = await CatchAsync <RequestFailedException>( async() => await client.GetDocumentAsync("ThisDocumentDoesNotExist")); Assert.AreEqual(404, ex.Status); }
public async Task ThrowsWhenMalformed() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = resources.GetQueryClient(); RequestFailedException ex = await CatchAsync <RequestFailedException>( async() => await client.GetDocumentAsync( "3", new GetDocumentOptions() { SelectedFields = new[] { "ThisFieldDoesNotExist" } })); Assert.AreEqual(400, ex.Status); StringAssert.StartsWith("Invalid expression: Could not find a property named 'ThisFieldDoesNotExist' on type 'search.document'.", ex.Message); }
public async Task Troubleshooting() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchIndexClient client = resources.GetQueryClient(); #region Snippet:Azure_Search_Tests_Samples_Readme_Troubleshooting try { //@@ return client.GetDocument<Hotel>("12345"); /*@@*/ await client.GetDocumentAsync <Hotel>("12345"); } catch (RequestFailedException ex) when(ex.Status == 404) { Console.WriteLine("We couldn't find the hotel you are looking for!"); Console.WriteLine("Please try selecting another."); } #endregion Snippet:Azure_Search_Tests_Samples_Readme_Troubleshooting }
public async Task Structs() { await using SearchResources resources = await SearchResources.CreateWithEmptyHotelsIndexAsync(this); SimpleStructHotel document = new SimpleStructHotel { HotelId = "4", HotelName = "Value Inn" }; await resources.GetIndexClient().IndexDocumentsAsync( IndexDocumentsBatch.Upload(new[] { document })); await resources.WaitForIndexingAsync(); SearchIndexClient client = resources.GetQueryClient(); Response <SimpleStructHotel> response = await client.GetDocumentAsync <SimpleStructHotel>(document.HotelId); Assert.AreEqual(document, response.Value); }