Files
CommandForge/tests/CommandForge.Tests/ConfirmationViewModelTests.cs
T
poli0981andClaude Opus 4.8 e66b3cffbc Phase 3b: confirmation, restore point, revert, deep admin commands
- IConfirmationService + confirmation dialog: Caution confirms (with optional
  restore point); Dangerous requires typing the command title to enable Run
  (golden rule #8).
- Restore Point as a catalog command (system.restorepoint, Checkpoint-Computer)
  run via the broker before risky commands — shares the one session UAC.
- Revert: detail-panel button runs the command's revertCommandId (with its own
  confirmation if risky); added revert pairs.
- 10 catalog commands incl. DISM RestoreHealth, SFC, Winsock reset, Defender
  quick scan, hibernate on/off, hide/show extensions, and the telemetry pair
  (Dangerous + revert) + EN/VI strings.
- Block app exit while a command is running (confirm, then cancel).
- Tests: confirmation gating (Caution always; Dangerous type-to-confirm) — 38 total.

Build -c Release: 0 warnings. dotnet test: 38/38. UX verified manually.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 21:25:57 +07:00

48 lines
1.5 KiB
C#

using CommandForge.Domain;
using CommandForge.Wpf.ViewModels;
namespace CommandForge.Tests;
/// <summary>Tests the confirmation gating, especially the type-to-confirm for Dangerous commands.</summary>
public sealed class ConfirmationViewModelTests
{
private static CommandDefinition Command(DangerLevel level) => new()
{
Id = "x",
CategoryId = "c",
TitleKey = "t",
DescriptionKey = "d",
Executable = "x",
DangerLevel = level,
};
[Fact]
public void Caution_CanRun_IsAlwaysTrue()
{
var viewModel = new ConfirmationViewModel(Command(DangerLevel.Caution), "Repair image", "desc", defaultCreateRestorePoint: true);
Assert.True(viewModel.CanRun);
}
[Fact]
public void Dangerous_CanRun_RequiresTypedTitle()
{
var viewModel = new ConfirmationViewModel(Command(DangerLevel.Dangerous), "Minimize telemetry", "desc", defaultCreateRestorePoint: true);
Assert.False(viewModel.CanRun);
viewModel.ConfirmationInput = "wrong";
Assert.False(viewModel.CanRun);
viewModel.ConfirmationInput = "Minimize telemetry";
Assert.True(viewModel.CanRun);
}
[Fact]
public void CreateRestorePoint_DefaultsToProvidedValue()
{
Assert.True(new ConfirmationViewModel(Command(DangerLevel.Caution), "t", "d", true).CreateRestorePoint);
Assert.False(new ConfirmationViewModel(Command(DangerLevel.Caution), "t", "d", false).CreateRestorePoint);
}
}