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

45 lines
1.7 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 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));
}
}