Skip to content

Commit c51671a

Browse files
Change the return type of ItextSearch to align with search abstractions in M.E.VD
1 parent da331f6 commit c51671a

File tree

13 files changed

+164
-215
lines changed

13 files changed

+164
-215
lines changed

dotnet/src/Plugins/Plugins.UnitTests/Web/Bing/BingTextSearchTests.cs

+17-22
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ public async Task SearchReturnsSuccessfullyAsync()
5050
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient });
5151

5252
// Act
53-
KernelSearchResults<string> result = await textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
53+
var results = textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
5454

5555
// Assert
56-
Assert.NotNull(result);
57-
Assert.NotNull(result.Results);
58-
var resultList = await result.Results.ToListAsync();
56+
Assert.NotNull(results);
57+
var resultList = await results.ToListAsync();
5958
Assert.NotNull(resultList);
6059
Assert.Equal(10, resultList.Count);
6160
foreach (var stringResult in resultList)
@@ -74,12 +73,11 @@ public async Task GetTextSearchResultsReturnsSuccessfullyAsync()
7473
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient });
7574

7675
// Act
77-
KernelSearchResults<TextSearchResult> result = await textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
76+
var results = textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
7877

7978
// Assert
80-
Assert.NotNull(result);
81-
Assert.NotNull(result.Results);
82-
var resultList = await result.Results.ToListAsync();
79+
Assert.NotNull(results);
80+
var resultList = await results.ToListAsync();
8381
Assert.NotNull(resultList);
8482
Assert.Equal(10, resultList.Count);
8583
foreach (var textSearchResult in resultList)
@@ -100,12 +98,11 @@ public async Task GetSearchResultsReturnsSuccessfullyAsync()
10098
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient });
10199

102100
// Act
103-
KernelSearchResults<object> result = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
101+
var results = textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
104102

105103
// Assert
106-
Assert.NotNull(result);
107-
Assert.NotNull(result.Results);
108-
var resultList = await result.Results.ToListAsync();
104+
Assert.NotNull(results);
105+
var resultList = await results.ToListAsync();
109106
Assert.NotNull(resultList);
110107
Assert.Equal(10, resultList.Count);
111108
foreach (BingWebPage webPage in resultList)
@@ -128,12 +125,11 @@ public async Task SearchWithCustomStringMapperReturnsSuccessfullyAsync()
128125
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient, StringMapper = new TestTextSearchStringMapper() });
129126

130127
// Act
131-
KernelSearchResults<string> result = await textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
128+
var results = textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
132129

133130
// Assert
134-
Assert.NotNull(result);
135-
Assert.NotNull(result.Results);
136-
var resultList = await result.Results.ToListAsync();
131+
Assert.NotNull(results);
132+
var resultList = await results.ToListAsync();
137133
Assert.NotNull(resultList);
138134
Assert.Equal(10, resultList.Count);
139135
foreach (var stringResult in resultList)
@@ -154,12 +150,11 @@ public async Task GetTextSearchResultsWithCustomResultMapperReturnsSuccessfullyA
154150
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient, ResultMapper = new TestTextSearchResultMapper() });
155151

156152
// Act
157-
KernelSearchResults<TextSearchResult> result = await textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
153+
var results = textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
158154

159155
// Assert
160-
Assert.NotNull(result);
161-
Assert.NotNull(result.Results);
162-
var resultList = await result.Results.ToListAsync();
156+
Assert.NotNull(results);
157+
var resultList = await results.ToListAsync();
163158
Assert.NotNull(resultList);
164159
Assert.Equal(10, resultList.Count);
165160
foreach (var textSearchResult in resultList)
@@ -207,7 +202,7 @@ public async Task BuildsCorrectUriForEqualityFilterAsync(string paramName, objec
207202

208203
// Act
209204
TextSearchOptions searchOptions = new() { Top = 4, Skip = 0, Filter = new TextSearchFilter().Equality(paramName, paramValue) };
210-
KernelSearchResults<object> result = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions);
205+
var results = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions).ToListAsync();
211206

212207
// Assert
213208
var requestUris = this._messageHandlerStub.RequestUris;
@@ -227,7 +222,7 @@ public async Task DoesNotBuildsUriForInvalidQueryParameterAsync()
227222
var textSearch = new BingTextSearch(apiKey: "ApiKey", options: new() { HttpClient = this._httpClient });
228223

229224
// Act && Assert
230-
var e = await Assert.ThrowsAsync<ArgumentException>(async () => await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions));
225+
var e = await Assert.ThrowsAsync<ArgumentException>(async () => await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions).ToListAsync());
231226
Assert.Equal("Unknown equality filter clause field name 'fooBar', must be one of answerCount,cc,freshness,mkt,promote,responseFilter,safeSearch,setLang,textDecorations,textFormat,contains,ext,filetype,inanchor,inbody,intitle,ip,language,loc,location,prefer,site,feed,hasfeed,url (Parameter 'searchOptions')", e.Message);
232227
}
233228

dotnet/src/Plugins/Plugins.UnitTests/Web/Google/GoogleTextSearchTests.cs

+16-21
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ public async Task SearchReturnsSuccessfullyAsync()
5353
searchEngineId: "SearchEngineId");
5454

5555
// Act
56-
KernelSearchResults<string> result = await textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
56+
var results = textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
5757

5858
// Assert
59-
Assert.NotNull(result);
60-
Assert.NotNull(result.Results);
61-
var resultList = await result.Results.ToListAsync();
59+
Assert.NotNull(results);
60+
var resultList = await results.ToListAsync();
6261
Assert.NotNull(resultList);
6362
Assert.Equal(4, resultList.Count);
6463
foreach (var stringResult in resultList)
@@ -79,12 +78,11 @@ public async Task GetTextSearchResultsReturnsSuccessfullyAsync()
7978
searchEngineId: "SearchEngineId");
8079

8180
// Act
82-
KernelSearchResults<TextSearchResult> result = await textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
81+
var results = textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
8382

8483
// Assert
85-
Assert.NotNull(result);
86-
Assert.NotNull(result.Results);
87-
var resultList = await result.Results.ToListAsync();
84+
Assert.NotNull(results);
85+
var resultList = await results.ToListAsync();
8886
Assert.NotNull(resultList);
8987
Assert.Equal(4, resultList.Count);
9088
foreach (var textSearchResult in resultList)
@@ -107,12 +105,11 @@ public async Task GetSearchResultsReturnsSuccessfullyAsync()
107105
searchEngineId: "SearchEngineId");
108106

109107
// Act
110-
KernelSearchResults<object> results = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
108+
var results = textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 10, Skip = 0 });
111109

112110
// Assert
113111
Assert.NotNull(results);
114-
Assert.NotNull(results.Results);
115-
var resultList = await results.Results.ToListAsync();
112+
var resultList = await results.ToListAsync();
116113
Assert.NotNull(resultList);
117114
Assert.Equal(4, resultList.Count);
118115
foreach (Result result in resultList.Cast<Result>())
@@ -138,12 +135,11 @@ public async Task SearchWithCustomStringMapperReturnsSuccessfullyAsync()
138135
options: new() { StringMapper = new TestTextSearchStringMapper() });
139136

140137
// Act
141-
KernelSearchResults<string> result = await textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
138+
var results = textSearch.SearchAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
142139

143140
// Assert
144-
Assert.NotNull(result);
145-
Assert.NotNull(result.Results);
146-
var resultList = await result.Results.ToListAsync();
141+
Assert.NotNull(results);
142+
var resultList = await results.ToListAsync();
147143
Assert.NotNull(resultList);
148144
Assert.Equal(4, resultList.Count);
149145
foreach (var stringResult in resultList)
@@ -167,12 +163,11 @@ public async Task GetTextSearchResultsWithCustomResultMapperReturnsSuccessfullyA
167163
options: new() { ResultMapper = new TestTextSearchResultMapper() });
168164

169165
// Act
170-
KernelSearchResults<TextSearchResult> result = await textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
166+
var results = textSearch.GetTextSearchResultsAsync("What is the Semantic Kernel?", new() { Top = 4, Skip = 0 });
171167

172168
// Assert
173-
Assert.NotNull(result);
174-
Assert.NotNull(result.Results);
175-
var resultList = await result.Results.ToListAsync();
169+
Assert.NotNull(results);
170+
var resultList = await results.ToListAsync();
176171
Assert.NotNull(resultList);
177172
Assert.Equal(4, resultList.Count);
178173
foreach (var textSearchResult in resultList)
@@ -209,7 +204,7 @@ public async Task BuildsCorrectUriForEqualityFilterAsync(string paramName, objec
209204

210205
// Act
211206
TextSearchOptions searchOptions = new() { Top = 4, Skip = 0, Filter = new TextSearchFilter().Equality(paramName, paramValue) };
212-
KernelSearchResults<object> result = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions);
207+
var results = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions).ToListAsync();
213208

214209
// Assert
215210
var requestUris = this._messageHandlerStub.RequestUris;
@@ -231,7 +226,7 @@ public async Task DoesNotBuildsUriForInvalidQueryParameterAsync()
231226
searchEngineId: "SearchEngineId");
232227

233228
// Act && Assert
234-
var e = await Assert.ThrowsAsync<ArgumentException>(async () => await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions));
229+
var e = await Assert.ThrowsAsync<ArgumentException>(async () => await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", searchOptions).ToListAsync());
235230
Assert.Equal("Unknown equality filter clause field name 'fooBar', must be one of cr,dateRestrict,exactTerms,excludeTerms,filter,gl,hl,linkSite,lr,orTerms,rights,siteSearch (Parameter 'searchOptions')", e.Message);
236231
}
237232

0 commit comments

Comments
 (0)