Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit service version #20770

Merged
merged 8 commits into from
May 17, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public async Task CreateIndexerAsync()
Environment.GetEnvironmentVariable("SEARCH_API_KEY"));
SearchIndexClient indexClient = new SearchIndexClient(endpoint, credential);
#if !SNIPPET
indexClient = resources.GetIndexClient(new SearchClientOptions());
indexClient = resources.GetIndexClient(new SearchClientOptions(ServiceVersion));
#endif

// Create a synonym map from a file containing country names and abbreviations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void DiagnosticsAreUnique()
{
// Make sure we're not repeating Header/Query names already defined
// in the base ClientOptions
SearchClientOptions options = new SearchClientOptions();
SearchClientOptions options = new SearchClientOptions(ServiceVersion);
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedHeaderNames));
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedQueryParameters));

Expand Down
39 changes: 24 additions & 15 deletions sdk/search/Azure.Search.Documents/tests/SearchIndexerClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Azure.Search.Documents.Tests
{
[ClientTestFixture(SearchClientOptions.ServiceVersion.V2020_06_30, SearchClientOptions.ServiceVersion.V2020_06_30_Preview)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to SearchTestBase instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that in a subsequent PR to handle any fallout.

public class SearchIndexerClientTests : SearchTestBase
{
public SearchIndexerClientTests(bool async, SearchClientOptions.ServiceVersion serviceVersion)
Expand Down Expand Up @@ -40,7 +41,7 @@ public void DiagnosticsAreUnique()
{
// Make sure we're not repeating Header/Query names already defined
// in the base ClientOptions
SearchClientOptions options = new SearchClientOptions();
SearchClientOptions options = new SearchClientOptions(ServiceVersion);
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedHeaderNames));
Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedQueryParameters));

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

SearchIndexerClient serviceClient = resources.GetIndexerClient();
SearchIndexerClient serviceClient = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));

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

SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions());
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));
string skillsetName = Recording.Random.GetName();

SearchIndexerSkillset skillset = CreateSkillsetModel(skillsetName, resources);

// Create the skillset.
SearchIndexerSkillset createdSkillset = await client.CreateSkillsetAsync(skillset);

await TestSkillsetAsync(client, skillset, createdSkillset, skillsetName);
}

private SearchIndexerSkillset CreateSkillsetModel(string skillsetName, SearchResources resources)
{
// Skills based on https://github.com/Azure-Samples/azure-search-sample-data/blob/master/hotelreviews/HotelReviews_skillset.json.
SearchIndexerSkill skill1 = new SplitSkill(
new[]
Expand Down Expand Up @@ -502,10 +513,8 @@ public async Task CrudSkillset()
SourceContext = null,
};

SearchIndexerKnowledgeStoreProjection projection1 = new();
projection1.Tables.Add(table1);
projection1.Tables.Add(table2);
projection1.Tables.Add(table3);
SearchIndexerKnowledgeStoreProjection projection1 = new()
{ Tables = { table1, table2, table3 } };

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

SearchIndexerKnowledgeStoreProjection projection2 = new();
projection2.Tables.Add(table4);
projection2.Tables.Add(table5);
projection2.Tables.Add(table6);
SearchIndexerKnowledgeStoreProjection projection2 = new()
{ Tables = { table4, table5, table6 } };

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

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

// Create the skillset.
SearchIndexerSkillset createdSkillset = await client.CreateSkillsetAsync(skillset);
return skillset;
}

private async Task TestSkillsetAsync(SearchIndexerClient client, SearchIndexerSkillset skillset, SearchIndexerSkillset createdSkillset, string skillsetName)
{
try
{
Assert.That(createdSkillset, Is.EqualTo(skillset).Using(SearchIndexerSkillsetComparer.Shared));
Expand Down Expand Up @@ -620,13 +629,13 @@ public async Task RoundtripAllSkills()

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

SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions());
SearchIndexerClient client = resources.GetIndexerClient(new SearchClientOptions(ServiceVersion));
string skillsetName = Recording.Random.GetName();

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

return t switch
Expand Down
Loading