using MongoDB.Driver.Linq;
namespace Dpz.Core.ServiceTest;
[TestFixture]
public class ArticleServiceTest:Basic
{
[TestCase("关于代糖的误解")]
[TestCase("过滤html标签、属性,防止XSS攻击")]
public async Task ArticleTitleIndexTest(string title)
{
var list = await ArticleRepository.SearchFor(x => x.Title == title).ToListAsync();
Assert.IsNotNull(list);
Assert.IsNotEmpty(list);
}
[Test]
public async Task ArticleSearchIndexTest()
{
var searchText = "dotnet";
var search1 = Builders<Article>.Search.Text(x => x.Title, searchText);
var search2 = Builders<Article>.Search.Text(x => x.Markdown, searchText);
var searchCompound = Builders<Article>.Search.Compound().Must(search1).Must(search2);
var list = await ArticleRepository.Collection.Aggregate().Search(searchCompound)
.ToListAsync();
Assert.IsNotNull(list);
Assert.IsNotEmpty(list);
}
}