Skip to content

Commit 0848378

Browse files
Use explicit service version (Azure#20770)
* Pass service version explicitly to search client options
1 parent 26d6b81 commit 0848378

File tree

12 files changed

+620
-555
lines changed

12 files changed

+620
-555
lines changed

sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public async Task CreateIndexerAsync()
184184
Environment.GetEnvironmentVariable("SEARCH_API_KEY"));
185185
SearchIndexClient indexClient = new SearchIndexClient(endpoint, credential);
186186
#if !SNIPPET
187-
indexClient = resources.GetIndexClient(new SearchClientOptions());
187+
indexClient = resources.GetIndexClient(new SearchClientOptions(ServiceVersion));
188188
#endif
189189

190190
// Create a synonym map from a file containing country names and abbreviations

sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void DiagnosticsAreUnique()
8484
{
8585
// Make sure we're not repeating Header/Query names already defined
8686
// in the base ClientOptions
87-
SearchClientOptions options = new SearchClientOptions();
87+
SearchClientOptions options = new SearchClientOptions(ServiceVersion);
8888
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedHeaderNames));
8989
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedQueryParameters));
9090

sdk/search/Azure.Search.Documents/tests/SearchIndexerClientTests.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Azure.Search.Documents.Tests
1515
{
16+
[ClientTestFixture(SearchClientOptions.ServiceVersion.V2020_06_30, SearchClientOptions.ServiceVersion.V2020_06_30_Preview)]
1617
public class SearchIndexerClientTests : SearchTestBase
1718
{
1819
public SearchIndexerClientTests(bool async, SearchClientOptions.ServiceVersion serviceVersion)
@@ -40,7 +41,7 @@ public void DiagnosticsAreUnique()
4041
{
4142
// Make sure we're not repeating Header/Query names already defined
4243
// in the base ClientOptions
43-
SearchClientOptions options = new SearchClientOptions();
44+
SearchClientOptions options = new SearchClientOptions(ServiceVersion);
4445
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedHeaderNames));
4546
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedQueryParameters));
4647

@@ -66,7 +67,7 @@ public async Task CreateAzureBlobIndexer()
6667
{
6768
await using SearchResources resources = await SearchResources.CreateWithBlobStorageAndIndexAsync(this, populate: true);
6869

69-
SearchIndexerClient serviceClient = resources.GetIndexerClient();
70+
SearchIndexerClient serviceClient = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));
7071

7172
// Create the Azure Blob data source and indexer.
7273
SearchIndexerDataSourceConnection dataSource = new SearchIndexerDataSourceConnection(
@@ -381,9 +382,19 @@ public async Task CrudSkillset()
381382
{
382383
await using SearchResources resources = await SearchResources.CreateWithBlobStorageAndIndexAsync(this);
383384

384-
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions());
385+
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));
385386
string skillsetName = Recording.Random.GetName();
386387

388+
SearchIndexerSkillset skillset = CreateSkillsetModel(skillsetName, resources);
389+
390+
// Create the skillset.
391+
SearchIndexerSkillset createdSkillset = await client.CreateSkillsetAsync(skillset);
392+
393+
await TestSkillsetAsync(client, skillset, createdSkillset, skillsetName);
394+
}
395+
396+
private SearchIndexerSkillset CreateSkillsetModel(string skillsetName, SearchResources resources)
397+
{
387398
// Skills based on https://github.com/Azure-Samples/azure-search-sample-data/blob/master/hotelreviews/HotelReviews_skillset.json.
388399
SearchIndexerSkill skill1 = new SplitSkill(
389400
new[]
@@ -502,10 +513,8 @@ public async Task CrudSkillset()
502513
SourceContext = null,
503514
};
504515

505-
SearchIndexerKnowledgeStoreProjection projection1 = new();
506-
projection1.Tables.Add(table1);
507-
projection1.Tables.Add(table2);
508-
projection1.Tables.Add(table3);
516+
SearchIndexerKnowledgeStoreProjection projection1 = new()
517+
{ Tables = { table1, table2, table3 } };
509518

510519
SearchIndexerKnowledgeStoreTableProjectionSelector table4 = new("hotelReviewsInlineDocument")
511520
{
@@ -538,10 +547,8 @@ public async Task CrudSkillset()
538547
};
539548
table6.Inputs.Add(new("Keyphrases") { Source = "/document/reviews_text/pages/*/Keyphrases/*", SourceContext = null });
540549

541-
SearchIndexerKnowledgeStoreProjection projection2 = new();
542-
projection2.Tables.Add(table4);
543-
projection2.Tables.Add(table5);
544-
projection2.Tables.Add(table6);
550+
SearchIndexerKnowledgeStoreProjection projection2 = new()
551+
{ Tables = { table4, table5, table6 } };
545552

546553
List<SearchIndexerKnowledgeStoreProjection> projections = new() { projection1, projection2 };
547554

@@ -551,9 +558,11 @@ public async Task CrudSkillset()
551558
KnowledgeStore = new SearchIndexerKnowledgeStore(resources.StorageAccountConnectionString, projections),
552559
};
553560

554-
// Create the skillset.
555-
SearchIndexerSkillset createdSkillset = await client.CreateSkillsetAsync(skillset);
561+
return skillset;
562+
}
556563

564+
private async Task TestSkillsetAsync(SearchIndexerClient client, SearchIndexerSkillset skillset, SearchIndexerSkillset createdSkillset, string skillsetName)
565+
{
557566
try
558567
{
559568
Assert.That(createdSkillset, Is.EqualTo(skillset).Using(SearchIndexerSkillsetComparer.Shared));
@@ -620,13 +629,13 @@ public async Task RoundtripAllSkills()
620629

621630
await using SearchResources resources = SearchResources.CreateWithNoIndexes(this);
622631

623-
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions());
632+
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));
624633
string skillsetName = Recording.Random.GetName();
625634

626635
// Enumerate all skills and create them with consistently fake input to test for nullability during deserialization.
627636
SearchIndexerSkill CreateSkill(Type t, string[] inputNames, string[] outputNames)
628637
{
629-
var inputs = inputNames.Select(input => new InputFieldMappingEntry(input) { Source = "/document/content" } ).ToList();
638+
var inputs = inputNames.Select(input => new InputFieldMappingEntry(input) { Source = "/document/content" }).ToList();
630639
var outputs = outputNames.Select(output => new OutputFieldMappingEntry(output, targetName: Recording.Random.GetName())).ToList();
631640

632641
return t switch

0 commit comments

Comments
 (0)