fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 31s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 31s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
This commit is contained in:
@@ -69,6 +69,77 @@ public class TransactionStatisticsServiceTest : BaseTest
|
||||
result["2024-01-01"].expense.Should().Be(150m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDailyStatisticsAsync_月份为0查询全年()
|
||||
{
|
||||
// Arrange
|
||||
var year = 2024;
|
||||
var month = 0; // 0 表示查询全年
|
||||
var testData = new List<TransactionRecord>
|
||||
{
|
||||
// 1月
|
||||
new() { Id=1, OccurredAt=new DateTime(2024,1,15), Amount=-100m, Type=TransactionType.Expense },
|
||||
new() { Id=2, OccurredAt=new DateTime(2024,1,20), Amount=5000m, Type=TransactionType.Income },
|
||||
// 6月
|
||||
new() { Id=3, OccurredAt=new DateTime(2024,6,10), Amount=-200m, Type=TransactionType.Expense },
|
||||
new() { Id=4, OccurredAt=new DateTime(2024,6,15), Amount=3000m, Type=TransactionType.Income },
|
||||
// 12月
|
||||
new() { Id=5, OccurredAt=new DateTime(2024,12,25), Amount=-300m, Type=TransactionType.Expense },
|
||||
new() { Id=6, OccurredAt=new DateTime(2024,12,31), Amount=2000m, Type=TransactionType.Income }
|
||||
};
|
||||
|
||||
ConfigureQueryAsync(testData);
|
||||
|
||||
// Act
|
||||
var result = await _service.GetDailyStatisticsAsync(year, month);
|
||||
|
||||
// Assert - 应包含全年各个月份的数据
|
||||
result.Should().ContainKey("2024-01-15");
|
||||
result.Should().ContainKey("2024-06-10");
|
||||
result.Should().ContainKey("2024-12-31");
|
||||
result["2024-01-15"].expense.Should().Be(100m);
|
||||
result["2024-06-10"].expense.Should().Be(200m);
|
||||
result["2024-12-31"].income.Should().Be(2000m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDailyStatisticsAsync_月份为0不应抛出异常()
|
||||
{
|
||||
// Arrange
|
||||
var year = 2026;
|
||||
var month = 0;
|
||||
ConfigureQueryAsync(new List<TransactionRecord>());
|
||||
|
||||
// Act & Assert - 不应抛出 ArgumentOutOfRangeException
|
||||
var act = async () => await _service.GetDailyStatisticsAsync(year, month);
|
||||
await act.Should().NotThrowAsync<ArgumentOutOfRangeException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDailyStatisticsAsync_包含存款分类统计()
|
||||
{
|
||||
// Arrange
|
||||
var year = 2024;
|
||||
var month = 1;
|
||||
var savingClassify = "股票,基金"; // 存款分类
|
||||
var testData = new List<TransactionRecord>
|
||||
{
|
||||
new() { Id=1, OccurredAt=new DateTime(2024,1,1), Amount=-100m, Type=TransactionType.Expense, Classify="餐饮" },
|
||||
new() { Id=2, OccurredAt=new DateTime(2024,1,1), Amount=-500m, Type=TransactionType.Expense, Classify="股票" },
|
||||
new() { Id=3, OccurredAt=new DateTime(2024,1,1), Amount=-300m, Type=TransactionType.Expense, Classify="基金" }
|
||||
};
|
||||
|
||||
ConfigureQueryAsync(testData);
|
||||
|
||||
// Act
|
||||
var result = await _service.GetDailyStatisticsAsync(year, month, savingClassify);
|
||||
|
||||
// Assert
|
||||
result.Should().ContainKey("2024-01-01");
|
||||
result["2024-01-01"].saving.Should().Be(800m); // 股票500 + 基金300
|
||||
result["2024-01-01"].expense.Should().Be(900m); // 总支出
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTrendStatisticsAsync_多个月份()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user