fix
This commit is contained in:
@@ -316,4 +316,105 @@ public class BudgetApplicationTest : BaseApplicationTest
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCategoryStatsAsync Tests
|
||||
|
||||
[Fact]
|
||||
public async Task GetCategoryStatsAsync_Should_Include_Trend_And_Description_In_Month_Stats()
|
||||
{
|
||||
// Arrange
|
||||
var referenceDate = new DateTime(2026, 2, 14);
|
||||
var category = BudgetCategory.Expense;
|
||||
|
||||
var serviceResponse = new BudgetCategoryStats
|
||||
{
|
||||
Month = new BudgetStatsDto
|
||||
{
|
||||
Limit = 3000,
|
||||
Current = 1200,
|
||||
Rate = 40,
|
||||
Trend = new List<decimal?> { 100, 200, 300, 400, 500, null, null },
|
||||
Description = "<table><tr><th>日期</th><th>金额</th></tr></table>"
|
||||
},
|
||||
Year = new BudgetStatsDto
|
||||
{
|
||||
Limit = 36000,
|
||||
Current = 5000,
|
||||
Rate = 13.89m,
|
||||
Trend = new List<decimal?> { 1000, 2000, 3000, null },
|
||||
Description = "<table><tr><th>月份</th><th>金额</th></tr></table>"
|
||||
}
|
||||
};
|
||||
|
||||
_budgetService.GetCategoryStatsAsync(category, referenceDate).Returns(serviceResponse);
|
||||
|
||||
// Act
|
||||
var result = await _application.GetCategoryStatsAsync(category, referenceDate);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
|
||||
// 验证 Month 数据
|
||||
result.Month.Limit.Should().Be(3000);
|
||||
result.Month.Current.Should().Be(1200);
|
||||
result.Month.Remaining.Should().Be(1800);
|
||||
result.Month.UsagePercentage.Should().Be(40);
|
||||
result.Month.Trend.Should().NotBeNull();
|
||||
result.Month.Trend.Should().HaveCount(7);
|
||||
result.Month.Trend[0].Should().Be(100);
|
||||
result.Month.Trend[5].Should().BeNull();
|
||||
result.Month.Description.Should().NotBeEmpty();
|
||||
result.Month.Description.Should().Contain("<table>");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetCategoryStatsAsync_Should_Include_Trend_And_Description_In_Year_Stats()
|
||||
{
|
||||
// Arrange
|
||||
var referenceDate = new DateTime(2026, 2, 14);
|
||||
var category = BudgetCategory.Income;
|
||||
|
||||
var serviceResponse = new BudgetCategoryStats
|
||||
{
|
||||
Month = new BudgetStatsDto
|
||||
{
|
||||
Limit = 5000,
|
||||
Current = 3000,
|
||||
Rate = 60,
|
||||
Trend = new List<decimal?> { 500, 1000, 1500, 2000, 2500, 3000 },
|
||||
Description = "<p>月度收入明细</p>"
|
||||
},
|
||||
Year = new BudgetStatsDto
|
||||
{
|
||||
Limit = 60000,
|
||||
Current = 10000,
|
||||
Rate = 16.67m,
|
||||
Trend = new List<decimal?> { 5000, 10000, null, null, null, null, null, null, null, null, null, null },
|
||||
Description = "<p>年度收入明细</p>"
|
||||
}
|
||||
};
|
||||
|
||||
_budgetService.GetCategoryStatsAsync(category, referenceDate).Returns(serviceResponse);
|
||||
|
||||
// Act
|
||||
var result = await _application.GetCategoryStatsAsync(category, referenceDate);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
|
||||
// 验证 Year 数据
|
||||
result.Year.Limit.Should().Be(60000);
|
||||
result.Year.Current.Should().Be(10000);
|
||||
result.Year.Remaining.Should().Be(50000);
|
||||
result.Year.UsagePercentage.Should().Be(16.67m);
|
||||
result.Year.Trend.Should().NotBeNull();
|
||||
result.Year.Trend.Should().HaveCount(12);
|
||||
result.Year.Trend[0].Should().Be(5000);
|
||||
result.Year.Trend[1].Should().Be(10000);
|
||||
result.Year.Trend[2].Should().BeNull();
|
||||
result.Year.Description.Should().NotBeEmpty();
|
||||
result.Year.Description.Should().Contain("年度收入明细");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user