fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 4m27s
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:
SunCheng
2026-02-11 13:00:01 +08:00
parent ca3e929770
commit 51172e8c5a
88 changed files with 10076 additions and 142 deletions

View File

@@ -499,4 +499,81 @@ public class BudgetSavingsTest : BaseTest
// 预计存款 = 116400 - 30000 - 2049.18 - 300 + 2000 = 86050.82
result.Limit.Should().BeApproximately(86050.82m, 0.1m);
}
[Fact]
public async Task GetSavings_年度_包含一月份归档存款_Test()
{
// Arrange
var year = 2026;
// 当前是2月11号
_dateTimeProvider.Now.Returns(new DateTime(year, 2, 11));
var budgets = new List<BudgetRecord>
{
// 月度预算
new() { Id = 1, Name = "工资", Type = BudgetPeriodType.Month, Limit = 11000, Category = BudgetCategory.Income, SelectedCategories = "工资" },
new() { Id = 2, Name = "房租", Type = BudgetPeriodType.Month, Limit = 3000, Category = BudgetCategory.Expense, SelectedCategories = "房租" }
};
// 当前月2月的交易数据
var currentTransactions = new Dictionary<(string, TransactionType), decimal>
{
{ ("工资", TransactionType.Income), 11000m },
{ ("房租", TransactionType.Expense), 3000m },
{ ("转账到公共", TransactionType.Expense), 5000m } // 2月份实际存款5000元
};
// 一月份的归档数据
var archives = new List<BudgetArchive>
{
new()
{
Year = year, Month = 1,
Content =
[
new BudgetArchiveContent
{
Id = 1,
Name = "工资",
Type = BudgetPeriodType.Month,
Limit = 11000,
Actual = 11000,
Category = BudgetCategory.Income
},
new BudgetArchiveContent
{
Id = 2,
Name = "房租",
Type = BudgetPeriodType.Month,
Limit = 3000,
Actual = 3000,
Category = BudgetCategory.Expense
},
new BudgetArchiveContent
{
Id = -2,
Name = "月度存款计划",
Type = BudgetPeriodType.Month,
Limit = 6287.34m,
Actual = 9600.0m, // ✅ 一月份实际存款9600元
Category = BudgetCategory.Savings
}
]
}
};
_budgetRepository.GetAllAsync().Returns(budgets);
_transactionStatisticsService.GetAmountGroupByClassifyAsync(Arg.Any<DateTime>(), Arg.Any<DateTime>())
.Returns(currentTransactions);
_budgetArchiveRepository.GetArchivesByYearAsync(year).Returns(archives);
_configService.GetConfigByKeyAsync<string>("SavingsCategories").Returns(Task.FromResult<string?>("转账到公共"));
// Act
var result = await _service.GetSavingsDtoAsync(BudgetPeriodType.Year, new DateTime(year, 1, 1));
// Assert
result.Should().NotBeNull();
// 年度已存款 = 一月份归档存款9600 + 二月份当前存款5000 = 14600
result.Current.Should().Be(14600m);
}
}