public void GetDynamicDocumentCannotAlwaysDetermineCorrectType() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var indexedDoc = new Document() { { "hotelId", "1" }, { "baseRate", Double.NaN }, { "hotelName", "2015-02-11T12:58:00Z" } }; var expectedDoc = new Document() { { "hotelId", "1" }, { "baseRate", "NaN" }, { "hotelName", new DateTimeOffset(2015, 2, 11, 12, 58, 0, TimeSpan.Zero) } }; var batch = new IndexBatch(new[] { new IndexAction(indexedDoc) }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse getResponse = client.Documents.Get("1", indexedDoc.Keys); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); SearchAssert.DocumentsEqual(expectedDoc, getResponse.Document); }); }
protected void TestCanSuggestDynamicDocuments() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new[] { "hotelId" } }; DocumentSuggestResponse response = client.Documents.Suggest("good", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Null(response.Coverage); Assert.NotNull(response.Results); Document[] expectedDocs = Data.TestDocuments .Where(h => h.HotelId == "4" || h.HotelId == "5") .OrderBy(h => h.HotelId) .Select(h => h.AsDocument()) .ToArray(); Assert.Equal(expectedDocs.Length, response.Results.Count); for (int i = 0; i < expectedDocs.Length; i++) { SearchAssert.DocumentsEqual(expectedDocs[i], response.Results[i].Document); Assert.Equal(expectedDocs[i]["description"], response.Results[i].Text); } }
public void CanSearchStaticallyTypedDocuments() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClientForQuery(); DocumentSearchResponse <Hotel> response = client.Documents.Search <Hotel>("*"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Null(response.ContinuationToken); Assert.Null(response.Count); Assert.Null(response.Coverage); Assert.Null(response.Facets); Assert.NotNull(response.Results); Assert.Equal(Data.TestDocuments.Length, response.Results.Count); for (int i = 0; i < response.Results.Count; i++) { Assert.Equal(1, response.Results[i].Score); Assert.Null(response.Results[i].Highlights); } SearchAssert.SequenceEqual(response.Results.Select(r => r.Document), Data.TestDocuments); }); }
public void CanGetDynamicDocumentWithNullOrEmptyValues() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var expectedDoc = new Document() { { "hotelId", "1" }, { "baseRate", null }, { "hotelName", null }, { "tags", new string[0] }, { "parkingIncluded", null }, { "lastRenovationDate", null }, { "rating", null }, { "location", null } }; var batch = new IndexBatch(new[] { new IndexAction(expectedDoc) }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse getResponse = client.Documents.Get("1", expectedDoc.Keys); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); SearchAssert.DocumentsEqual(expectedDoc, getResponse.Document); }); }
public void CanGetDynamicDocument() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var expectedDoc = new Document() { { "hotelId", "1" }, { "baseRate", 199.0 }, { "description", "Best hotel in town" }, { "descriptionFr", "Meilleur hôtel en ville" }, { "hotelName", "Fancy Stay" }, { "category", "Luxury" }, { "tags", new[] { "pool", "view", "wifi", "concierge" } }, { "parkingIncluded", false }, { "smokingAllowed", false }, { "lastRenovationDate", new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)) }, { "rating", 5L }, { "location", GeographyPoint.Create(47.678581, -122.131577) } }; var batch = new IndexBatch(new[] { new IndexAction(expectedDoc) }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse getResponse = client.Documents.Get("1"); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); SearchAssert.DocumentsEqual(expectedDoc, getResponse.Document); }); }
public void GetDocumentThrowsWhenRequestIsMalformed() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var indexedDoc = new Hotel() { HotelId = "3", BaseRate = 279.99, Description = "Surprisingly expensive" }; var batch = IndexBatch.Upload(new[] { indexedDoc }); client.Documents.Index(batch); string[] selectedFields = new[] { "hotelId", "ThisFieldDoesNotExist" }; SearchAssert.ThrowsCloudException( () => client.Documents.Get("3", selectedFields), HttpStatusCode.BadRequest, "Invalid expression: Could not find a property named 'ThisFieldDoesNotExist' on type 'search.document'."); }); }
protected void TestCanSuggestStaticallyTypedDocuments() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new[] { "hotelId" } }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("good", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Null(response.Coverage); Assert.NotNull(response.Results); IEnumerable <Hotel> expectedDocs = Data.TestDocuments.Where(h => h.HotelId == "4" || h.HotelId == "5").OrderBy(h => h.HotelId); SearchAssert.SequenceEqual( expectedDocs, response.Results.Select(r => r.Document)); SearchAssert.SequenceEqual( expectedDocs.Select(h => h.Description), response.Results.Select(r => r.Text)); }
public void CountWillNotDeadlock() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); SearchAssert.DoesNotUseSynchronizationContext(() => client.Documents.Count()); }); }
public void GetIndexerThrowsOnNotFound() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); SearchAssert.ThrowsCloudException(() => searchClient.Indexers.Get("thisindexerdoesnotexist"), HttpStatusCode.NotFound); }); }
public void GetDocumentThrowsWhenDocumentNotFound() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); SearchAssert.ThrowsCloudException(() => client.Documents.Get("ThisDocumentDoesNotExist"), HttpStatusCode.NotFound); }); }
protected void TestAutocompleteThrowsWhenRequestIsMalformed() { SearchIndexClient client = GetClientForQuery(); SearchAssert.ThrowsCloudException( () => client.Documents.Autocomplete("very po", string.Empty), HttpStatusCode.BadRequest, "Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\r\nParameter name: suggestions"); }
private void AssertKeySequenceEqual(DocumentSuggestResponse <Hotel> response, params string[] expectedKeys) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); IEnumerable <string> actualKeys = response.Results.Select(r => r.Document.HotelId); SearchAssert.SequenceEqual(expectedKeys, actualKeys); }
protected void TestSuggestThrowsWhenGivenBadSuggesterName() { SearchIndexClient client = GetClient(); SearchAssert.ThrowsCloudException( () => client.Documents.Suggest("hotel", "Suggester does not exist", new SuggestParameters()), HttpStatusCode.BadRequest, "The specified suggester name 'Suggester does not exist' does not exist in this index definition."); }
public void GetSynonymMapThrowsOnNotFound() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); SearchAssert.ThrowsCloudException( () => searchClient.SynonymMaps.Get("thisSynonymMapdoesnotexist"), HttpStatusCode.NotFound); }); }
public void GetDataSourceThrowsOnNotFound() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); SearchAssert.ThrowsCloudException( () => searchClient.DataSources.Get("thisdatasourcedoesnotexist"), HttpStatusCode.NotFound); }); }
private static void AssertIsPartialFailure( IndexBatchException e, IndexBatch <Hotel> batch, params string[] failedKeys) { Assert.Equal((HttpStatusCode)207, e.Response.StatusCode); Assert.Equal((HttpStatusCode)207, e.IndexResponse.StatusCode); IndexBatch <Hotel> retryBatch = e.FindFailedActionsToRetry(batch, a => a.HotelId); Assert.Equal(failedKeys.Length, retryBatch.Actions.Count()); SearchAssert.SequenceEqual(failedKeys, retryBatch.Actions.Select(a => a.Document.HotelId)); }
protected void TestAutcompleteThrowsWhenGivenBadSuggesterName() { SearchIndexClient client = GetClientForQuery(); var autocompleteParameters = new AutocompleteParameters() { AutocompleteMode = AutocompleteMode.OneTerm }; SearchAssert.ThrowsCloudException( () => client.Documents.Autocomplete("very po", "Invalid suggester", autocompleteParameters), HttpStatusCode.BadRequest, "The specified suggester name 'Invalid suggester' does not exist in this index definition.\r\nParameter name: name"); }
public void IndexingWillNotDeadlock() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var batch = IndexBatch.Upload(new[] { new Hotel() { HotelId = "12" } }); SearchAssert.DoesNotUseSynchronizationContext(() => client.Documents.Index(batch)); }); }
internal static void CreateOrUpdateIfNotExistsFailsOnExistingResource <T>( Func <T, SearchRequestOptions, AccessCondition, T> createOrUpdateFunc, Func <T> newResourceDefinition, Func <T, T> mutateResourceDefinition) where T : IResourceWithETag { Func <T, AccessCondition, T> createOrUpdate = (a, b) => createOrUpdateFunc(a, null, b); var createdResource = createOrUpdate(newResourceDefinition(), AccessCondition.GenerateEmptyCondition()); var mutatedResource = mutateResourceDefinition(createdResource); SearchAssert.ThrowsCloudException( () => createOrUpdate(mutatedResource, AccessCondition.GenerateIfNotExistsCondition()), e => e.IsAccessConditionFailed()); }
protected void TestSearchThrowsWhenRequestIsMalformed() { SearchIndexClient client = GetClient(); var invalidParameters = new SearchParameters() { Filter = "This is not a valid filter." }; SearchAssert.ThrowsCloudException( () => client.Documents.Search("*", invalidParameters), HttpStatusCode.BadRequest, "Invalid expression: Syntax error at position 7 in 'This is not a valid filter.'"); }
protected void TestSearchThrowsWhenSpecialCharInRegexIsUnescaped() { SearchIndexClient client = GetClient(); var searchParameters = new SearchParameters() { QueryType = QueryType.Full }; SearchAssert.ThrowsCloudException( () => client.Documents.Search(@"/.*/.*/", searchParameters), HttpStatusCode.BadRequest, "Failed to parse query string at line 1, column 8."); }
protected void TestSuggestThrowsWhenRequestIsMalformed() { SearchIndexClient client = GetClient(); var invalidParameters = new SuggestParameters() { OrderBy = new[] { "This is not a valid orderby." } }; SearchAssert.ThrowsCloudException( () => client.Documents.Suggest("hotel", "sg", invalidParameters), HttpStatusCode.BadRequest, "Invalid expression: Syntax error at position 7 in 'This is not a valid orderby.'"); }
public void AutocompleteWillNotDeadlock() { Run(() => { void TestAutocomplete(bool useHttpGet) { SearchIndexClient client = Data.GetSearchIndexClientForQuery(useHttpGet: useHttpGet); SearchAssert.DoesNotUseSynchronizationContext(() => client.Documents.Autocomplete("mo", "sg")); } TestAutocomplete(true); TestAutocomplete(false); }); }
public void IndexWithInvalidDocumentThrowsException() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var batch = IndexBatch.Upload(new[] { new Document() }); SearchAssert.ThrowsCloudException( () => client.Documents.Index(batch), HttpStatusCode.BadRequest, "The request is invalid. Details: actions : 0: Document key cannot be missing or empty."); }); }
public void SuggestWillNotDeadlock() { Run(() => { void TestSuggest(bool useHttpGet) { SearchIndexClient client = Data.GetSearchIndexClientForQuery(useHttpGet: useHttpGet); SearchAssert.DoesNotUseSynchronizationContext(() => client.Documents.Suggest("best", "sg")); } TestSuggest(true); TestSuggest(false); }); }
private static void AssertIsPartialFailure( IndexBatchException e, IndexBatch batch, params string[] failedKeys) { Assert.Equal((HttpStatusCode)207, e.Response.StatusCode); Assert.Equal((HttpStatusCode)207, e.IndexResponse.StatusCode); const string KeyFieldName = "hotelId"; IndexBatch retryBatch = e.FindFailedActionsToRetry(batch, KeyFieldName); Assert.Equal(failedKeys.Length, retryBatch.Actions.Count()); SearchAssert.SequenceEqual(failedKeys, retryBatch.Actions.Select(a => a.Document[KeyFieldName].ToString())); }
public void CreateDataSourceFailsWithUsefulMessageOnUserError() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); DataSource dataSource = CreateTestDataSource(); dataSource.Type = "thistypedoesnotexist"; SearchAssert.ThrowsCloudException( () => searchClient.DataSources.Create(dataSource), HttpStatusCode.BadRequest, "Data source type 'thistypedoesnotexist' is not supported"); }); }
public void CreateSynonymMapFailsWithUsefulMessageOnUserError() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); SynonymMap synonymMap = CreateTestSynonymMap(); synonymMap.Synonyms = "a => b => c"; // invalid SearchAssert.ThrowsCloudException( () => searchClient.SynonymMaps.Create(synonymMap), HttpStatusCode.BadRequest, "Syntax error in line 1: 'a => b => c'. Only one explicit mapping (=>) can be specified in a synonym rule."); }); }
internal static void UpdateIfExistsFailsOnNoResource <T>( Func <T, SearchRequestOptions, AccessCondition, T> createOrUpdateFunc, Func <T> newResourceDefinition) where T : IResourceWithETag { Func <T, AccessCondition, T> createOrUpdate = (a, b) => createOrUpdateFunc(a, null, b); var resource = newResourceDefinition(); SearchAssert.ThrowsCloudException( () => createOrUpdate(resource, AccessCondition.GenerateIfExistsCondition()), e => e.IsAccessConditionFailed()); // The resource should never have been created on the server, and thus it should not have an ETag Assert.Null(resource.ETag); }
internal static void DeleteIfExistsWorksOnlyWhenResourceExists <T>( Action <string, SearchRequestOptions, AccessCondition> deleteAction, Func <T> createResource, string resourceName) where T : IResourceWithETag { Action <string, AccessCondition> delete = (a, b) => deleteAction(a, null, b); createResource(); delete(resourceName, AccessCondition.GenerateIfExistsCondition()); SearchAssert.ThrowsCloudException( () => delete(resourceName, AccessCondition.GenerateIfExistsCondition()), e => e.IsAccessConditionFailed()); }