fix
This commit is contained in:
@@ -441,4 +441,82 @@ public class TransactionCategoryApplicationTest : BaseApplicationTest
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DeleteIconAsync Tests
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteIconAsync_存在的分类_应成功删除图标()
|
||||
{
|
||||
// Arrange
|
||||
var category = new TransactionCategory
|
||||
{
|
||||
Id = 1,
|
||||
Name = "测试",
|
||||
Type = TransactionType.Expense,
|
||||
Icon = """["<svg>icon1</svg>","<svg>icon2</svg>"]"""
|
||||
};
|
||||
_categoryRepository.GetByIdAsync(1).Returns(category);
|
||||
_categoryRepository.UpdateAsync(Arg.Any<TransactionCategory>()).Returns(true);
|
||||
|
||||
// Act
|
||||
await _application.DeleteIconAsync(1);
|
||||
|
||||
// Assert
|
||||
await _categoryRepository.Received(1).UpdateAsync(Arg.Is<TransactionCategory>(
|
||||
c => c.Id == 1 && c.Icon == null
|
||||
));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteIconAsync_分类不存在_应抛出NotFoundException()
|
||||
{
|
||||
// Arrange
|
||||
_categoryRepository.GetByIdAsync(999).Returns((TransactionCategory?)null);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<NotFoundException>(() => _application.DeleteIconAsync(999));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteIconAsync_更新失败_应抛出BusinessException()
|
||||
{
|
||||
// Arrange
|
||||
var category = new TransactionCategory
|
||||
{
|
||||
Id = 1,
|
||||
Name = "测试",
|
||||
Type = TransactionType.Expense,
|
||||
Icon = """["<svg>icon1</svg>"]"""
|
||||
};
|
||||
_categoryRepository.GetByIdAsync(1).Returns(category);
|
||||
_categoryRepository.UpdateAsync(Arg.Any<TransactionCategory>()).Returns(false);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<BusinessException>(() => _application.DeleteIconAsync(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteIconAsync_无图标的分类_应成功()
|
||||
{
|
||||
// Arrange
|
||||
var category = new TransactionCategory
|
||||
{
|
||||
Id = 1,
|
||||
Name = "测试",
|
||||
Type = TransactionType.Expense,
|
||||
Icon = null
|
||||
};
|
||||
_categoryRepository.GetByIdAsync(1).Returns(category);
|
||||
_categoryRepository.UpdateAsync(Arg.Any<TransactionCategory>()).Returns(true);
|
||||
|
||||
// Act
|
||||
await _application.DeleteIconAsync(1);
|
||||
|
||||
// Assert
|
||||
await _categoryRepository.Received(1).UpdateAsync(Arg.Is<TransactionCategory>(
|
||||
c => c.Id == 1 && c.Icon == null
|
||||
));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user