public void AutoSuggest() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "AutoSuggest"); var client = new AutoSuggestClient(new ApiKeyServiceClientCredentials(SubscriptionKey), HttpMockServer.CreateInstance()); var resp = client.AutoSuggestMethod(query: "tom cruise", market: "en-us"); Assert.NotNull(resp); Assert.NotNull(resp.QueryContext); Assert.NotNull(resp.SuggestionGroups); Assert.NotNull(resp.SuggestionGroups[0]); var suggestions = resp.SuggestionGroups[0].SearchSuggestions; Assert.NotNull(suggestions); Assert.True(suggestions.Count == 8); foreach (var suggestion in suggestions) { Assert.NotNull(suggestion); Assert.NotEmpty(suggestion.Url); Assert.NotEmpty(suggestion.DisplayText); Assert.NotEmpty(suggestion.SearchKind); Assert.NotEmpty(suggestion.Query); } } }
async static Task RunQuickstart() { // Generate the credentials and create the client. var credentials = new Microsoft.Azure.CognitiveServices.Search.AutoSuggest.ApiKeyServiceClientCredentials(subscription_key); var client = new AutoSuggestClient(credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = endpoint }; var result = await client.AutoSuggestMethodAsync("xb"); var groups = result.SuggestionGroups; if (groups.Count > 0) { var group = groups[0]; Console.Write("First suggestion group: {0}\n", group.Name); var suggestions = group.SearchSuggestions; if (suggestions.Count > 0) { Console.WriteLine("First suggestion:"); Console.WriteLine("Query: {0}", suggestions[0].Query); Console.WriteLine("Display text: {0}", suggestions[0].DisplayText); } else { Console.WriteLine("No suggestions found in this group."); } } else { Console.WriteLine("No suggestions found."); } }