Repository: microsoft/semantic-kernel
File: dotnet/src/SemanticKernel.UnitTests/Data/TextSearchProviderTests.cs (C#)

Code before:

        var options = new TextSearchProviderOptions
        {
            SearchTime = TextSearchProviderOptions.RagBehavior.BeforeAIInvoke,
            Top = 2,
            ContextFormatter = results => $"Custom formatted context with {results.Count} results."
        };

        var component = new TextSearchProvider(mockTextSearch.Object, options: options);

        // Act
        var result = await component.ModelInvokingAsync([new ChatMessage(ChatRole.User, "Sample user question?")], CancellationToken.None);

        // Assert
        Assert.Equal("Custom formatted context with 2 results.", result.Instructions);
    }

    [Fact]
    public async Task SearchAsyncRespectsFilterOption()
    {
        // Arrange
        var mockTextSearch = new Mock<ITextSearch>();
        var searchResults = new Mock<IAsyncEnumerable<TextSearchResult>>();
        var mockEnumerator = new Mock<IAsyncEnumerator<TextSearchResult>>();

        // 模拟被过滤的结果
        var filteredResult = new TextSearchResult("Filtered Content") { Name = "FilteredDoc", Link = "http://example.com/filtered" };
        var results = new List<TextSearchResult> { filteredResult };

        mockEnumerator.SetupSequence(e => e.MoveNextAsync())
            .ReturnsAsync(true)
            .ReturnsAsync(false);

        mockEnumerator.SetupSequence(e => e.Current)
            .Returns(filteredResult);

        searchResults.Setup(r => r.GetAsyncEnumerator(It.IsAny<CancellationToken>()))
            .Returns(mockEnumerator.Object);

        TextSearchFilter? capturedFilter = null;
        mockTextSearch.Setup(ts => ts.GetTextSearchResultsAsync(
                It.IsAny<string>(),
                It.IsAny<TextSearchOptions>(),
                It.IsAny<CancellationToken>()))
            .Callback<string, TextSearchOptions?, CancellationToken>((q, opts, ct) =>
            {
                capturedFilter = opts?.Filter;
            })
            .ReturnsAsync(new KernelSearchResults<TextSearchResult>(searchResults.Object));

        var filter = new TextSearchFilter().Equality("Name", "FilteredDoc");

Review comment (suggestion):
For those of us who only understand English 😃
```suggestion
        // Simulate the filtered results
```

Code after:

        var options = new TextSearchProviderOptions
        {
            SearchTime = TextSearchProviderOptions.RagBehavior.BeforeAIInvoke,
            Top = 2,
            ContextFormatter = results => $"Custom formatted context with {results.Count} results."
        };

        var component = new TextSearchProvider(mockTextSearch.Object, options: options);

        // Act
        var result = await component.ModelInvokingAsync([new ChatMessage(ChatRole.User, "Sample user question?")], CancellationToken.None);

        // Assert
        Assert.Equal("Custom formatted context with 2 results.", result.Instructions);
    }

    [Fact]
    public async Task SearchAsyncRespectsFilterOption()
    {
        // Arrange
        var mockTextSearch = new Mock<ITextSearch>();
        var searchResults = new Mock<IAsyncEnumerable<TextSearchResult>>();
        var mockEnumerator = new Mock<IAsyncEnumerator<TextSearchResult>>();

        // Simulate the filtered results
        var filteredResult = new TextSearchResult("Filtered Content") { Name = "FilteredDoc", Link = "http://example.com/filtered" };
        var results = new List<TextSearchResult> { filteredResult };

        mockEnumerator.SetupSequence(e => e.MoveNextAsync())
            .ReturnsAsync(true)
            .ReturnsAsync(false);

        mockEnumerator.SetupSequence(e => e.Current)
            .Returns(filteredResult);

        searchResults.Setup(r => r.GetAsyncEnumerator(It.IsAny<CancellationToken>()))
            .Returns(mockEnumerator.Object);

        TextSearchFilter? capturedFilter = null;
        mockTextSearch.Setup(ts => ts.GetTextSearchResultsAsync(
                It.IsAny<string>(),
                It.IsAny<TextSearchOptions>(),
                It.IsAny<CancellationToken>()))
            .Callback<string, TextSearchOptions?, CancellationToken>((q, opts, ct) =>
            {
                capturedFilter = opts?.Filter;
            })
            .ReturnsAsync(new KernelSearchResults<TextSearchResult>(searchResults.Object));

        var filter = new TextSearchFilter().Equality("Name", "FilteredDoc");