@@ -263,4 +263,56 @@ public async Task ModelInvokingShouldUseOverrideContextFormatterIfProvidedAsync(
263
263
// Assert
264
264
Assert . Equal ( "Custom formatted context with 2 results." , result . Instructions ) ;
265
265
}
266
+
267
+ [ Fact ]
268
+ public async Task SearchAsyncRespectsFilterOption ( )
269
+ {
270
+ // Arrange
271
+ var mockTextSearch = new Mock < ITextSearch > ( ) ;
272
+ var searchResults = new Mock < IAsyncEnumerable < TextSearchResult > > ( ) ;
273
+ var mockEnumerator = new Mock < IAsyncEnumerator < TextSearchResult > > ( ) ;
274
+
275
+ // Simulate the filtered results
276
+ var filteredResult = new TextSearchResult ( "Filtered Content" ) { Name = "FilteredDoc" , Link = "http://example.com/filtered" } ;
277
+ var results = new List < TextSearchResult > { filteredResult } ;
278
+
279
+ mockEnumerator . SetupSequence ( e => e . MoveNextAsync ( ) )
280
+ . ReturnsAsync ( true )
281
+ . ReturnsAsync ( false ) ;
282
+
283
+ mockEnumerator . SetupSequence ( e => e . Current )
284
+ . Returns ( filteredResult ) ;
285
+
286
+ searchResults . Setup ( r => r . GetAsyncEnumerator ( It . IsAny < CancellationToken > ( ) ) )
287
+ . Returns ( mockEnumerator . Object ) ;
288
+
289
+ TextSearchFilter ? capturedFilter = null ;
290
+ mockTextSearch . Setup ( ts => ts . GetTextSearchResultsAsync (
291
+ It . IsAny < string > ( ) ,
292
+ It . IsAny < TextSearchOptions > ( ) ,
293
+ It . IsAny < CancellationToken > ( ) ) )
294
+ . Callback < string , TextSearchOptions ? , CancellationToken > ( ( q , opts , ct ) =>
295
+ {
296
+ capturedFilter = opts ? . Filter ;
297
+ } )
298
+ . ReturnsAsync ( new KernelSearchResults < TextSearchResult > ( searchResults . Object ) ) ;
299
+
300
+ var filter = new TextSearchFilter ( ) . Equality ( "Name" , "FilteredDoc" ) ;
301
+ var options = new TextSearchProviderOptions
302
+ {
303
+ Filter = filter
304
+ } ;
305
+
306
+ var provider = new TextSearchProvider ( mockTextSearch . Object , options : options ) ;
307
+
308
+ // Act
309
+ var result = await provider . SearchAsync ( "Sample user question?" , CancellationToken . None ) ;
310
+
311
+ // Assert
312
+ Assert . Contains ( "Filtered Content" , result ) ;
313
+ Assert . Contains ( "SourceDocName: FilteredDoc" , result ) ;
314
+ Assert . Contains ( "SourceDocLink: http://example.com/filtered" , result ) ;
315
+ Assert . NotNull ( capturedFilter ) ;
316
+ Assert . Equal ( filter , capturedFilter ) ;
317
+ }
266
318
}
0 commit comments