Implements C3 + C4 from docs/Extra.md Part 2. - Application: PortableSettings (machine-portable subset: appearance, behavior, favorites) + pure SettingsTransfer (Capture/Apply); ISettingsFile (import/export) and IProfileService ports. - Infrastructure: JsonSettingsFile (read/write a chosen .json) and JsonProfileService -> %AppData%\CommandForge\profiles.json, both via a shared source-gen context with a schema version + corrupt-file fallback. No telemetry; import never carries executable commands. - WPF: new Settings "Backup & profiles" section — Export/Import buttons and a named-profile picker (apply/delete + save-current). Import/apply route appearance/language/font through the existing observable-property setters (live apply + persist); favorites are written to settings and the shell re-syncs via a new SettingsViewModel.PortableSettingsApplied event. - EN/VI .resx keys; tests for capture/apply round-trip, file round-trip/fallbacks, and profile CRUD/persistence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using CommandForge.Application.Logging;
|
|
using CommandForge.Application.Settings;
|
|
using CommandForge.Infrastructure;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>Verifies the portable-settings capture/apply mapping covers every field (round-trip).</summary>
|
|
public sealed class SettingsTransferTests
|
|
{
|
|
[Fact]
|
|
public void Capture_Then_Apply_RoundTripsAllFields()
|
|
{
|
|
var srcPath = Path.Combine(Path.GetTempPath(), $"cf-src-{Guid.NewGuid():N}.json");
|
|
var dstPath = Path.Combine(Path.GetTempPath(), $"cf-dst-{Guid.NewGuid():N}.json");
|
|
try
|
|
{
|
|
var src = new JsonSettingsService(srcPath)
|
|
{
|
|
Theme = AppTheme.Dark,
|
|
Language = "vi",
|
|
FontSize = FontScale.Large,
|
|
CollapseSidebarByDefault = true,
|
|
ShowAdminRestartBadges = false,
|
|
ConfirmCaution = false,
|
|
AutoCreateRestorePoint = false,
|
|
AutoScrollConsole = false,
|
|
WarnOnCancel = false,
|
|
AutoCheckForUpdates = false,
|
|
LogLevel = LogLevel.Verbose,
|
|
FavoriteCommandIds = ["info.systeminfo", "net.flushdns"],
|
|
};
|
|
|
|
var captured = SettingsTransfer.Capture(src);
|
|
|
|
Assert.Equal(AppTheme.Dark, captured.Theme);
|
|
Assert.Equal("vi", captured.Language);
|
|
Assert.Equal(FontScale.Large, captured.FontSize);
|
|
Assert.Equal(["info.systeminfo", "net.flushdns"], captured.FavoriteCommandIds);
|
|
|
|
var dst = new JsonSettingsService(dstPath);
|
|
SettingsTransfer.Apply(captured, dst);
|
|
|
|
Assert.Equal(AppTheme.Dark, dst.Theme);
|
|
Assert.Equal("vi", dst.Language);
|
|
Assert.Equal(FontScale.Large, dst.FontSize);
|
|
Assert.True(dst.CollapseSidebarByDefault);
|
|
Assert.False(dst.ShowAdminRestartBadges);
|
|
Assert.False(dst.ConfirmCaution);
|
|
Assert.False(dst.AutoCreateRestorePoint);
|
|
Assert.False(dst.AutoScrollConsole);
|
|
Assert.False(dst.WarnOnCancel);
|
|
Assert.False(dst.AutoCheckForUpdates);
|
|
Assert.Equal(LogLevel.Verbose, dst.LogLevel);
|
|
Assert.Equal(["info.systeminfo", "net.flushdns"], dst.FavoriteCommandIds);
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(srcPath);
|
|
File.Delete(dstPath);
|
|
}
|
|
}
|
|
}
|