Phase 3 缺陷修复 + 分类管理功能 + ComboBox 主题适配
缺陷修复: 日志自动滚动、StaticResource 顺序修复、ContextMenu PlacementTarget 绑定、PATH 命令支持、异常全量捕获、RefreshData 状态保留、全局崩溃日志 分类管理: 添加/编辑/删除分类,删除时工具移入全部,CategoryEditViewModel/Window UI 修复: ComboBox 自定义模板,暗色模式弹出层/下拉项主题配色,文本绑定修复
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using Moq;
|
||||
using PersonalToolBox.Models;
|
||||
using PersonalToolBox.Services;
|
||||
using PersonalToolBox.ViewModels;
|
||||
|
||||
namespace PersonalToolBox.Tests.ViewModels;
|
||||
|
||||
public class CategoryEditViewModelTests
|
||||
{
|
||||
private readonly Mock<IDataService> _dataServiceMock = new();
|
||||
private readonly Mock<ILogService> _logServiceMock = new();
|
||||
private readonly AppConfig _config;
|
||||
|
||||
public CategoryEditViewModelTests()
|
||||
{
|
||||
_config = new AppConfig();
|
||||
_dataServiceMock.Setup(d => d.Config).Returns(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_AddMode_SetsTitle()
|
||||
{
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object);
|
||||
|
||||
Assert.Equal("添加分类", vm.WindowTitle);
|
||||
Assert.Empty(vm.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_EditMode_SetsTitleAndName()
|
||||
{
|
||||
var cat = new Category { Name = "开发工具" };
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object, cat);
|
||||
|
||||
Assert.Equal("编辑分类", vm.WindowTitle);
|
||||
Assert.Equal("开发工具", vm.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_EmptyName_LogsWarning()
|
||||
{
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object);
|
||||
|
||||
vm.SaveCommand.Execute(null);
|
||||
|
||||
_logServiceMock.Verify(x => x.Warning(It.Is<string>(s => s.Contains("名称不能为空"))), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_AddMode_AddsCategoryAndCloses()
|
||||
{
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object) { Name = "新分类" };
|
||||
bool? closeResult = null;
|
||||
vm.CloseAction = (r) => closeResult = r;
|
||||
|
||||
vm.SaveCommand.Execute(null);
|
||||
|
||||
Assert.True(vm.Saved);
|
||||
Assert.True(closeResult);
|
||||
Assert.Single(_config.Categories);
|
||||
Assert.Equal("新分类", _config.Categories[0].Name);
|
||||
_dataServiceMock.Verify(x => x.Save(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_EditMode_UpdatesCategoryAndCloses()
|
||||
{
|
||||
var cat = new Category { Name = "旧名称" };
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object, cat) { Name = "新名称" };
|
||||
bool? closeResult = null;
|
||||
vm.CloseAction = (r) => closeResult = r;
|
||||
|
||||
vm.SaveCommand.Execute(null);
|
||||
|
||||
Assert.True(vm.Saved);
|
||||
Assert.True(closeResult);
|
||||
Assert.Equal("新名称", cat.Name);
|
||||
_dataServiceMock.Verify(x => x.Save(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cancel_ClosesWithoutSaving()
|
||||
{
|
||||
var vm = new CategoryEditViewModel(_dataServiceMock.Object, _logServiceMock.Object);
|
||||
bool? closeResult = null;
|
||||
vm.CloseAction = (r) => closeResult = r;
|
||||
|
||||
vm.CancelCommand.Execute(null);
|
||||
|
||||
Assert.False(vm.Saved);
|
||||
Assert.False(closeResult);
|
||||
_dataServiceMock.Verify(x => x.Save(), Times.Never);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user