Files
EmailBill/WebApi.Test/Repository/TransactionPeriodicRepositoryTest.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

47 lines
1.8 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 TransactionPeriodicRepositoryTest : TransactionTestBase
{
private readonly ITransactionPeriodicRepository _repository;
public TransactionPeriodicRepositoryTest()
{
_repository = new TransactionPeriodicRepository(FreeSql);
}
[Fact]
public async Task GetPendingPeriodicBillsAsync_获取待执行账单_Test()
{
// 应该执行的NextExecuteTime <= Now
await _repository.AddAsync(new TransactionPeriodic { Reason = "Bill1", NextExecuteTime = DateTime.Now.AddDays(-1), IsEnabled = true });
// 不该执行的NextExecuteTime > Now
await _repository.AddAsync(new TransactionPeriodic { Reason = "Bill2", NextExecuteTime = DateTime.Now.AddDays(1), IsEnabled = true });
// 不该执行的:未激活
await _repository.AddAsync(new TransactionPeriodic { Reason = "Bill3", NextExecuteTime = DateTime.Now.AddDays(-1), IsEnabled = false });
var results = await _repository.GetPendingPeriodicBillsAsync();
results.Should().HaveCount(1);
results.First().Reason.Should().Be("Bill1");
}
[Fact]
public async Task UpdateExecuteTimeAsync_更新执行时间_Test()
{
var bill = new TransactionPeriodic { Reason = "Bill", NextExecuteTime = DateTime.Now };
await _repository.AddAsync(bill);
var last = DateTime.Now;
var next = DateTime.Now.AddMonths(1);
await _repository.UpdateExecuteTimeAsync(bill.Id, last, next);
var updated = await _repository.GetByIdAsync(bill.Id);
updated!.LastExecuteTime.Should().BeCloseTo(last, TimeSpan.FromSeconds(1));
updated.NextExecuteTime.Should().BeCloseTo(next, TimeSpan.FromSeconds(1));
}
}