Files
EmailBill/WebApi.Test/Repository/EmailMessageRepositoryTest.cs
SunCheng e93c3d6bae
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 27s
Docker Build & Deploy / Deploy to Production (push) Successful in 9s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
测试覆盖率
2026-01-28 17:00:58 +08:00

55 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FluentAssertions;
namespace WebApi.Test.Repository;
public class EmailMessageRepositoryTest : RepositoryTestBase
{
private readonly IEmailMessageRepository _repository;
public EmailMessageRepositoryTest()
{
_repository = new EmailMessageRepository(FreeSql);
}
[Fact]
public async Task ExistsAsync_检查存在_Test()
{
await _repository.AddAsync(new EmailMessage { Md5 = "md5_value", Subject = "Test" });
var msg = await _repository.ExistsAsync("md5_value");
msg.Should().NotBeNull();
var notfound = await _repository.ExistsAsync("other");
notfound.Should().BeNull();
}
[Fact]
public async Task GetPagedListAsync_游标分页_Test()
{
// 插入3条数据时间倒序
var m1 = new EmailMessage { Subject = "M1", ReceivedDate = DateTime.Now }; // Latest
var m2 = new EmailMessage { Subject = "M2", ReceivedDate = DateTime.Now.AddDays(-1) };
var m3 = new EmailMessage { Subject = "M3", ReceivedDate = DateTime.Now.AddDays(-2) }; // Oldest
// FreeSql IDs are snowflakes, increasing.
// Assuming ID order follows insertion (mostly true for snowflakes if generated sequentially)
// But ReceivedDate is the primary sort in logic usually.
// Let's verify standard cursor pagination usually sorts by Date DESC, ID DESC.
await _repository.AddAsync(m1);
await _repository.AddAsync(m2);
await _repository.AddAsync(m3);
// Fetch page 1 (size 2)
var result1 = await _repository.GetPagedListAsync(null, null, 2);
result1.list.Should().HaveCount(2);
result1.list[0].Subject.Should().Be("M1");
result1.list[1].Subject.Should().Be("M2");
// Fetch page 2 using cursor
var result2 = await _repository.GetPagedListAsync(result1.lastReceivedDate, result1.lastId, 2);
result2.list.Should().HaveCount(1);
result2.list[0].Subject.Should().Be("M3");
}
}