private void TestCanSearchWithCustomConverter <T>(Action <SearchIndexClient> customizeSettings = null) where T : CustomBook, new() { customizeSettings = customizeSettings ?? (client => { }); SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = Book.DefineIndex(); serviceClient.Indexes.Create(index); SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name); customizeSettings(indexClient); var doc = new T() { InternationalStandardBookNumber = "123", Name = "Lord of the Rings", AuthorName = "J.R.R. Tolkien", PublishDateTime = new DateTime(1954, 7, 29) }; var batch = IndexBatch.Upload(new[] { doc }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentSearchResult <T> response = indexClient.Documents.Search <T>("*"); Assert.Equal(1, response.Results.Count); Assert.Equal(doc, response.Results[0].Document); }
public void IndexDoesNotThrowWhenDeletingDynamicDocumentWithExtraFields() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var document = new Document() { { "hotelId", "1" }, { "category", "Luxury" } }; var batch = IndexBatch.Upload(new[] { document }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Assert.Equal(1, client.Documents.Count()); document["category"] = "ignored"; batch = IndexBatch.Delete(new[] { document }); DocumentIndexResult documentIndexResult = client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Assert.Equal(1, documentIndexResult.Results.Count); AssertIndexActionSucceeded("1", documentIndexResult.Results[0], 200); Assert.Equal(0, client.Documents.Count()); }); }
private static Skillset CreateTestOcrSkillset(int repeat, TextExtractionAlgorithm algorithm, string name = null, bool shouldDetectOrientation = false) { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "url", Source = "/document/url" }, new InputFieldMappingEntry { Name = "queryString", Source = "/document/queryString" } }; for (int i = 0; i < repeat; i++) { var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "text", TargetName = "mytext" + i } }; skills.Add(new OcrSkill(inputs, outputs, "Tested OCR skill" + i, RootPathString) { TextExtractionAlgorithm = algorithm, ShouldDetectOrientation = shouldDetectOrientation, DefaultLanguageCode = "en", Context = "/document", }); } return(new Skillset(name: name ?? SearchTestUtilities.GenerateName(), description: "Skillset for testing OCR", skills: skills)); }
private IEnumerable <string> IndexDocuments(SearchIndexClient client, int totalDocCount) { int existingDocumentCount = Data.TestDocuments.Length; IEnumerable <string> hotelIds = Enumerable.Range(existingDocumentCount + 1, totalDocCount - existingDocumentCount) .Select(id => id.ToString()); var hotels = hotelIds.Select(id => new Hotel() { HotelId = id }).ToList(); for (int i = 0; i < hotels.Count; i += 1000) { IEnumerable <Hotel> nextHotels = hotels.Skip(i).Take(1000); if (!nextHotels.Any()) { break; } var batch = IndexBatch.Upload(nextHotels); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); } return(hotelIds); }
public void CanRoundtripIndexerWithFieldMappingFunctions() => Run(() => { Indexer expectedIndexer = new Indexer(SearchTestUtilities.GenerateName(), Data.DataSourceName, Data.TargetIndexName) { FieldMappings = new[] { // Try all the field mapping functions and parameters (even if they don't make sense in the context of the test DB). new FieldMapping("feature_id", "a", FieldMappingFunction.Base64Encode()), new FieldMapping("feature_id", "b", FieldMappingFunction.Base64Encode(useHttpServerUtilityUrlTokenEncode: true)), new FieldMapping("feature_id", "c", FieldMappingFunction.ExtractTokenAtPosition(delimiter: " ", position: 0)), new FieldMapping("feature_id", "d", FieldMappingFunction.Base64Decode()), new FieldMapping("feature_id", "e", FieldMappingFunction.Base64Decode(useHttpServerUtilityUrlTokenDecode: false)), new FieldMapping("feature_id", "f", FieldMappingFunction.JsonArrayToStringCollection()) } }; SearchServiceClient searchClient = Data.GetSearchServiceClient(); // We need to add desired fields to the index before those fields can be referenced by the field mappings Index index = searchClient.Indexes.Get(Data.TargetIndexName); string[] fieldNames = new[] { "a", "b", "c", "d", "e", "f" }; index.Fields = index.Fields.Concat(fieldNames.Select(name => new Field(name, DataType.String))).ToList(); searchClient.Indexes.CreateOrUpdate(index); searchClient.Indexers.Create(expectedIndexer); Indexer actualIndexer = searchClient.Indexers.Get(expectedIndexer.Name); AssertIndexersEqual(expectedIndexer, actualIndexer); });
private static Skillset CreateSkillsetWithEntityRecognitionDefaultSettings() { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "text", Source = "/document/mytext" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "entities", TargetName = "myEntities" } }; skills.Add(new EntityRecognitionSkill(inputs, outputs, "Tested Entity Recognition skill", RootPathString)); return(new Skillset(SearchTestUtilities.GenerateName(), description: "Skillset for testing default configuration", skills: skills)); }
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); }); }
private static Skillset CreateSkillsetWithSentimentDefaultSettings() { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "text", Source = "/document/mytext" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "score", TargetName = "mySentiment" } }; skills.Add(new SentimentSkill( inputs, outputs, name: "mysentiment", description: "Tested Sentiment skill", context: RootPathString)); return(new Skillset(SearchTestUtilities.GenerateName(), description: "Skillset for testing default configuration", skills: skills)); }
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 = IndexBatch.Upload(new[] { expectedDoc }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Document actualDoc = client.Documents.Get("1", indexedDoc.Keys); Assert.Equal(expectedDoc, actualDoc); }); }
public void CanGetStaticallyTypedDocumentWithNullOrEmptyValues() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var expectedDoc = new Hotel() { HotelId = "1", BaseRate = null, HotelName = null, Tags = new string[0], ParkingIncluded = null, LastRenovationDate = null, Rating = null, Location = null }; var batch = IndexBatch.Create(IndexAction.Create(expectedDoc)); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse <Hotel> getResponse = client.Documents.Get <Hotel>("1"); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); Assert.Equal(expectedDoc, getResponse.Document); }); }
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 = IndexBatch.Upload(new[] { expectedDoc }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Document actualDoc = client.Documents.Get("1", expectedDoc.Keys); Assert.Equal(expectedDoc, actualDoc); }); }
public void CanGetStaticallyTypedDocumentWithNullOrEmptyValues() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var expectedDoc = new Hotel() { HotelId = "1", BaseRate = null, HotelName = null, Tags = new string[0], ParkingIncluded = null, LastRenovationDate = null, Rating = null, Location = null }; var batch = IndexBatch.Upload(new[] { expectedDoc }); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Hotel actualDoc = client.Documents.Get <Hotel>("1"); Assert.Equal(expectedDoc, actualDoc); }); }
private IEnumerable <string> IndexThousandsOfDocuments(SearchIndexClient client) { int existingDocumentCount = Data.TestDocuments.Length; IEnumerable <string> hotelIds = Enumerable.Range(existingDocumentCount + 1, 2001 - existingDocumentCount).Select(id => id.ToString()); IEnumerable <Hotel> hotels = hotelIds.Select(id => new Hotel() { HotelId = id }); IEnumerable <IndexAction <Hotel> > actions = hotels.Select(h => IndexAction.Create(h)); var batch = IndexBatch.Create(actions.Take(1000)); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); batch = IndexBatch.Create(actions.Skip(1000)); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); return(hotelIds); }
public void DynamicDocumentDateTimesRoundTripAsUtc() { Run(() => { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = new Index() { Name = TestUtilities.GenerateName(), Fields = new[] { new Field("ISBN", DataType.String) { IsKey = true }, new Field("PublishDate", DataType.DateTimeOffset) } }; IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index); Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode); SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name); DateTime localDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local); DateTime utcDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime unspecifiedDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified); var batch = new IndexBatch( new[] { new IndexAction(new Document() { { "ISBN", "1" }, { "PublishDate", localDateTime } }), new IndexAction(new Document() { { "ISBN", "2" }, { "PublishDate", utcDateTime } }), new IndexAction(new Document() { { "ISBN", "3" }, { "PublishDate", unspecifiedDateTime } }) }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse getResponse = indexClient.Documents.Get("1"); Assert.Equal(new DateTimeOffset(localDateTime), getResponse.Document["PublishDate"]); getResponse = indexClient.Documents.Get("2"); Assert.Equal(new DateTimeOffset(utcDateTime), getResponse.Document["PublishDate"]); getResponse = indexClient.Documents.Get("3"); Assert.Equal(new DateTimeOffset(utcDateTime), getResponse.Document["PublishDate"]); }); }
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 CanUseIndexWithReservedName() { Run(() => { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); var indexWithReservedName = new Index() { Name = "prototype", Fields = new[] { new Field("ID", DataType.String) { IsKey = true } } }; serviceClient.Indexes.Create(indexWithReservedName); SearchIndexClient indexClient = Data.GetSearchIndexClient(indexWithReservedName.Name); var batch = IndexBatch.Upload(new[] { new Document() { { "ID", "1" } } }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); Document doc = indexClient.Documents.Get("1"); Assert.NotNull(doc); }); }
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); }); }
public void CanCreateBlobIndexerWithConfigurationParameters() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); Indexer expectedIndexer = Data.CreateTestIndexer(); DataSource blobDataSource = DataSource.AzureBlobStorage( SearchTestUtilities.GenerateName(), storageConnectionString: "fake", containerName: "fake"); expectedIndexer.DataSourceName = blobDataSource.Name; expectedIndexer.IsDisabled = true; expectedIndexer.Parameters = new IndexingParameters(); expectedIndexer.Parameters .ExcludeFileNameExtensions(".pdf") .IndexFileNameExtensions(".docx") .SetBlobExtractionMode(BlobExtractionMode.StorageMetadata); Indexer actualIndexer = searchClient.Indexers.Create(expectedIndexer); ExpectSameStartTime(expectedIndexer, actualIndexer); AssertIndexersEqual(expectedIndexer, actualIndexer); }); }
protected void TestCanSuggestWithDateTimeInStaticModel() { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = Book.DefineIndex(); serviceClient.Indexes.Create(index); SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name); var doc1 = new Book() { ISBN = "123", Title = "Lord of the Rings", Author = "J.R.R. Tolkien" }; var doc2 = new Book() { ISBN = "456", Title = "War and Peace", PublishDate = new DateTime(2015, 8, 18) }; var batch = IndexBatch.Upload(new[] { doc1, doc2 }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); var parameters = new SuggestParameters() { Select = new[] { "ISBN", "Title", "PublishDate" } }; DocumentSuggestResult <Book> response = indexClient.Documents.Suggest <Book>("War", "sg", parameters); Assert.Equal(1, response.Results.Count); Assert.Equal(doc2, response.Results[0].Document); }
private static Skillset CreateSkillsetWithImageAnalysisDefaultSettings() { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "url", Source = "/document/url" }, new InputFieldMappingEntry { Name = "queryString", Source = "/document/queryString" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "description", TargetName = "mydescription" } }; skills.Add(new ImageAnalysisSkill(inputs, outputs, "Tested image analysis skill", RootPathString)); return(new Skillset(SearchTestUtilities.GenerateName(), description: "Skillset for testing default configuration", skills: skills)); }
public void CanUseAllAnalyzerNamesInIndexDefinition() { Run(() => { SearchServiceClient client = Data.GetSearchServiceClient(); Index index = new Index() { Name = SearchTestUtilities.GenerateName(), Fields = new[] { new Field("id", DataType.String) { IsKey = true } }.ToList() }; AnalyzerName[] allAnalyzers = GetAllExtensibleEnumValues <AnalyzerName>(); for (int i = 0; i < allAnalyzers.Length; i++) { string fieldName = String.Format("field{0}", i); DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String); index.Fields.Add(new Field(fieldName, fieldType, allAnalyzers[i])); } client.Indexes.Create(index); }); }
private static Skillset CreateSkillsetWithSplitDefaultSettings() { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "text", Source = "/document/mytext" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "textItems", TargetName = "myTextItems" } }; skills.Add(new SplitSkill(inputs, outputs, "Tested Split skill", RootPathString) { TextSplitMode = TextSplitMode.Pages }); return(new Skillset(SearchTestUtilities.GenerateName(), description: "Skillset for testing default configuration", skills: skills)); }
protected void TestNullCannotBeConvertedToValueType() { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = new Index() { Name = SearchTestUtilities.GenerateName(), Fields = new[] { new Field("Key", DataType.String) { IsKey = true }, new Field("IntValue", DataType.Int32) } }; serviceClient.Indexes.Create(index); SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name); var doc = new ModelWithNullableInt() { Key = "123", IntValue = null }; var batch = IndexBatch.Upload(new[] { doc }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); SerializationException e = Assert.Throws <SerializationException>(() => indexClient.Documents.Search <ModelWithInt>("*")); Assert.Contains("Error converting value {null} to type 'System.Int32'. Path 'IntValue'.", e.ToString()); }
protected void TestCanSearchWithDateTimeInStaticModel() { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = Book.DefineIndex(); serviceClient.Indexes.Create(index); SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name); var tolkien = new Author() { FirstName = "J.R.R.", LastName = "Tolkien" }; var doc1 = new Book() { ISBN = "123", Title = "Lord of the Rings", Author = tolkien }; var doc2 = new Book() { ISBN = "456", Title = "War and Peace", PublishDate = new DateTime(2015, 8, 18) }; var batch = IndexBatch.Upload(new[] { doc1, doc2 }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentSearchResult <Book> response = indexClient.Documents.Search <Book>("War and Peace"); Assert.Equal(1, response.Results.Count); Assert.Equal(doc2, response.Results[0].Document); }
public void CanIndexAndRetrieveWithCamelCaseContractResolver() { Run(() => { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = Book.DefineIndex(useCamelCase: true); serviceClient.Indexes.Create(index); SearchIndexClient client = Data.GetSearchIndexClient(index.Name); client.SerializationSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var expectedBook = new Book() { ISBN = "123", Title = "The Hobbit", Author = "J.R.R. Tolkien" }; DocumentIndexResult result = client.Documents.Index(IndexBatch.Upload(new[] { expectedBook })); Assert.Equal(1, result.Results.Count); AssertIndexActionSucceeded("123", result.Results[0], 201); SearchTestUtilities.WaitForIndexing(); Assert.Equal(1, client.Documents.Count()); Book actualBook = client.Documents.Get <Book>(expectedBook.ISBN); Assert.Equal(expectedBook, actualBook); }); }
public void CannotCreateOrUpdateFreeServiceWithIdentity() { Run(() => { SearchManagementClient searchMgmt = GetSearchManagementClient(); string serviceName = SearchTestUtilities.GenerateServiceName(); SearchService service = DefineServiceWithSku(SkuName.Free); service.Identity = new Identity(IdentityType.SystemAssigned); CloudException e = Assert.Throws <CloudException>(() => searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service)); Assert.Equal("Resource identity is not supported for the selected SKU", e.Message); // retry create without identity service.Identity = null; service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); Assert.NotNull(service); Assert.Null(service.Identity); // try update the created service by defining an identity service.Identity = new Identity(); e = Assert.Throws <CloudException>(() => searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service)); Assert.Equal("Resource identity is not supported for the selected SKU", e.Message); searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); }); }
public void StaticallyTypedDateTimesRoundTripAsUtc() { Run(() => { SearchServiceClient serviceClient = Data.GetSearchServiceClient(); Index index = new Index() { Name = TestUtilities.GenerateName(), Fields = new[] { new Field("ISBN", DataType.String) { IsKey = true }, new Field("PublishDate", DataType.DateTimeOffset) } }; IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index); Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode); SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name); DateTime localDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local); DateTime utcDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime unspecifiedDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified); var batch = IndexBatch.Create( new[] { IndexAction.Create(new Book() { ISBN = "1", PublishDate = localDateTime }), IndexAction.Create(new Book() { ISBN = "2", PublishDate = utcDateTime }), IndexAction.Create(new Book() { ISBN = "3", PublishDate = unspecifiedDateTime }) }); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); DocumentGetResponse <Book> getResponse = indexClient.Documents.Get <Book>("1"); Assert.Equal(localDateTime.ToUniversalTime(), getResponse.Document.PublishDate); getResponse = indexClient.Documents.Get <Book>("2"); Assert.Equal(utcDateTime, getResponse.Document.PublishDate); getResponse = indexClient.Documents.Get <Book>("3"); Assert.Equal(utcDateTime, getResponse.Document.PublishDate); }); }
private static DataSource CreateTestSqlDataSource( HighWaterMarkChangeDetectionPolicy changeDetectionPolicy, DataDeletionDetectionPolicy deletionDetectionPolicy, bool useSqlVm = false) { // Test different overloads based on the given parameters. if (useSqlVm) { return(DataSource.SqlServerOnAzureVM( name: SearchTestUtilities.GenerateName(), sqlConnectionString: IndexerFixture.AzureSqlReadOnlyConnectionString, tableOrViewName: IndexerFixture.AzureSqlTestTableName, changeDetectionPolicy: changeDetectionPolicy, deletionDetectionPolicy: deletionDetectionPolicy, description: FakeDescription)); } else { return(DataSource.AzureSql( name: SearchTestUtilities.GenerateName(), sqlConnectionString: IndexerFixture.AzureSqlReadOnlyConnectionString, tableOrViewName: IndexerFixture.AzureSqlTestTableName, changeDetectionPolicy: changeDetectionPolicy, deletionDetectionPolicy: deletionDetectionPolicy, description: FakeDescription)); } }
public void CanAddAndRemoveServiceIdentity() { Run(() => { SearchManagementClient searchMgmt = GetSearchManagementClient(); string serviceName = SearchTestUtilities.GenerateServiceName(); SearchService service = DefineServiceWithSku(SkuName.Basic); service.Identity = null; service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service); Assert.NotNull(service); Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None); // assign an identity of type 'SystemAssigned' service.Identity = new Identity(IdentityType.SystemAssigned); service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service); Assert.NotNull(service); Assert.NotNull(service.Identity); Assert.Equal(IdentityType.SystemAssigned, service.Identity.Type); string principalId = string.IsNullOrWhiteSpace(service.Identity.PrincipalId) ? null : service.Identity.PrincipalId; Assert.NotNull(principalId); string tenantId = string.IsNullOrWhiteSpace(service.Identity.TenantId) ? null : service.Identity.TenantId; Assert.NotNull(tenantId); // remove the identity by setting it's type to 'None' service.Identity.Type = IdentityType.None; service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service); Assert.NotNull(service); Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None); searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name); }); }
public void CanSearchWithCustomAnalyzer() { Run(() => { const string CustomAnalyzerName = "my_email_analyzer"; const string CustomCharFilterName = "my_email_filter"; Index index = new Index() { Name = SearchTestUtilities.GenerateName(), Fields = new[] { new Field("id", DataType.String) { IsKey = true }, new Field("message", (AnalyzerName)CustomAnalyzerName) { IsSearchable = true } }, Analyzers = new[] { new CustomAnalyzer() { Name = CustomAnalyzerName, Tokenizer = TokenizerName.Standard, CharFilters = new[] { (CharFilterName)CustomCharFilterName } } }, CharFilters = new[] { new PatternReplaceCharFilter(CustomCharFilterName, "@", "_") } }; Data.GetSearchServiceClient().Indexes.Create(index); SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name); var documents = new[] { new Document() { { "id", "1" }, { "message", "My email is [email protected]." } }, new Document() { { "id", "2" }, { "message", "His email is [email protected]." } }, }; indexClient.Documents.Index(IndexBatch.Upload(documents)); SearchTestUtilities.WaitForIndexing(); DocumentSearchResult <Document> result = indexClient.Documents.Search("*****@*****.**"); Assert.Equal("1", result.Results.Single().Document["id"]); }); }