Files
CommandForge/tests/CommandForge.Tests/WindowsRegistryServiceTests.cs
poli0981andClaude Opus 4.8 bc132b82e6 feat(registry): read-only before/after diff + undo via revert (v-next Đợt 6)
Implements C6 + C2 from docs/Extra.md Part 2, with a safe design that
preserves the Elevator invariant (no new privileged write path).

- Catalog: optional affectedRegistryValues field (RegistryValueRef in
  Domain + DTO + mapping), declared on tweak.showext / tweak.showhidden.
- Application: IRegistryService (read-only) + pure RegistrySnapshot
  (Capture + Diff -> RegistryChange).
- Infrastructure: WindowsRegistryService over Microsoft.Win32.Registry;
  unknown hive / missing key / access error all read as null.
- WPF: after a run with affectedRegistryValues, MainViewModel re-reads
  the values and appends a localized before/after diff to the console.
- Undo (C2): History entries whose command has a vetted RevertCommandId
  get an "Undo" button that runs that catalog revert command — NO
  arbitrary registry writes, the Elevator still only accepts catalog ids.
- EN/VI .resx; docs (Changelog/roadmap/Security.md §4).
- Tests: snapshot diff (null/changed), Win32 read smoke (known/missing/
  bad hive), and the catalog schema field.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 15:13:39 +07:00

43 lines
1.1 KiB
C#

using CommandForge.Domain;
using CommandForge.Infrastructure.Registry;
namespace CommandForge.Tests;
/// <summary>Smoke tests for the read-only Win32 registry service against well-known keys.</summary>
public sealed class WindowsRegistryServiceTests
{
[Fact]
public void Read_KnownValue_ReturnsNonNull()
{
var service = new WindowsRegistryService();
var value = service.Read(new RegistryValueRef
{
Path = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
Name = "ProductName",
});
Assert.False(string.IsNullOrEmpty(value));
}
[Fact]
public void Read_MissingKey_ReturnsNull()
{
var service = new WindowsRegistryService();
Assert.Null(service.Read(new RegistryValueRef
{
Path = "HKCU\\Software\\CommandForge\\Missing_" + Guid.NewGuid().ToString("N"),
Name = "Nope",
}));
}
[Fact]
public void Read_UnknownHive_ReturnsNull()
{
var service = new WindowsRegistryService();
Assert.Null(service.Read(new RegistryValueRef { Path = "BOGUS\\Whatever", Name = "X" }));
}
}