Files
EmailBill/WebApi.Test/Repository/EmailMessageRepositoryTest.cs
SunCheng 704f58b1a1
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 24s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 3s
fix
2026-01-30 10:41:19 +08:00

53 lines
1.9 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.
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");
}
}