Files
frameledger/tests/FrameLedger.App.Tests/SystemInfoViewModelTests.cs
poli0981andClaude Opus 5.5 ff949afc6f feat(legal): NOTICE with the GPLv3 section 7 additional terms, the licence header in every source file, and the documents for people who build, contribute or redistribute (D45, beta.12 PR-1) (#253)
- NOTICE: copyright, GPL-3.0-only, and three additional terms of the kinds section 7 permits - (b) preserve the
  notices and the attribution in the program's legal notices, (c) mark a modified version as different and do not
  call it "FrameLedger" alone, (e) no trademark rights in the name. Shipped as licenses\NOTICE.txt; release.yml
  refuses a published tree without it.
- Section 7 wants additional terms named in the source files: every first-party .cs .cpp .h .inl .ps1 .xaml file
  (1,053; src/native/third_party excluded) opens with the SPDX line and a pointer to NOTICE. tools/notice-check.ps1
  is the gate (six self-test cases, both directions; -Fix writes a missing header) and tools/resx-gen.ps1 generates
  the string accessors with the header.
- The native VERSIONINFO LegalCopyright said GPL-3.0-or-later; it now names the real licence.
- CONTRIBUTING.md, FORKING.md, CODE_OF_CONDUCT.md (Contributor Covenant 2.1 by reference), legal/TRADEMARKS.md.
- 12_BUILD gate list, CLAUDE.md layout and conventions.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 22:16:00 +07:00

121 lines
4.7 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Globalization;
using FluentAssertions;
using FrameLedger.App.Services;
using FrameLedger.App.ViewModels;
using FrameLedger.Application.Persistence;
using FrameLedger.Application.Recording;
namespace FrameLedger.App.Tests;
/// <summary>
/// Settings ▸ System (2026-09-21): this PC through the same source every session's snapshot comes from. A field the
/// source could not read is N/A, a source that throws is a card of N/A, and Copy is the same lines as text.
/// </summary>
[Collection(StringsCultureCollection.Name)]
public sealed class SystemInfoViewModelTests
{
private sealed class FixedSource(Func<HardwareSnapshot> take) : IHardwareSnapshotSource
{
public HardwareSnapshot Take() => take();
}
private sealed class FakeClipboard(bool accepts) : IClipboard
{
public string? Text { get; private set; }
public bool SetText(string text)
{
Text = text;
return accepts;
}
}
private sealed class FakeStrip : IMessageStrip
{
public List<string> Lines { get; } = [];
public void Info(string title, string body) => Lines.Add("info:" + body);
public void Success(string title, string body) => Lines.Add("success:" + body);
public void Warn(string title, string body) => Lines.Add("warn:" + body);
}
private static async Task<T> InEnglishAsync<T>(Func<Task<T>> work)
{
CultureInfo? previous = Strings.Culture;
CultureInfo previousThread = CultureInfo.CurrentCulture;
try
{
Strings.Culture = CultureInfo.GetCultureInfo("en");
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
return await work().ConfigureAwait(false);
}
finally
{
Strings.Culture = previous;
CultureInfo.CurrentCulture = previousThread;
}
}
[Fact]
public async Task TheSnapshotIsStatedLineByLineAndCopyIsTheSameLines()
{
var clipboard = new FakeClipboard(accepts: true);
var strip = new FakeStrip();
(SystemInfoViewModel vm, string[] lines) = await InEnglishAsync(async () =>
{
var model = new SystemInfoViewModel(new FixedSource(static () => new HardwareSnapshot
{
CpuName = "AMD Ryzen 7 9800X3D",
GpuName = "NVIDIA GeForce RTX 5080",
GpuDriver = "32.0.15.8180",
RamGb = 31.9,
OsBuild = "10.0.26200",
DisplayRes = "2560x1440",
DisplayHz = 239.96,
}), clipboard, strip);
await model.Pending.ConfigureAwait(false);
model.CopyCommand.Execute(null);
return (model, model.Lines.Select(static l => l.Label + "=" + l.Value).ToArray());
});
lines.Should().Equal(
"Processor=AMD Ryzen 7 9800X3D",
"Graphics card=NVIDIA GeForce RTX 5080",
"Graphics driver=32.0.15.8180",
"Memory=31.9 GB",
"Windows build=10.0.26200",
"Primary display=2560x1440 @ 240 Hz");
clipboard.Text.Should().Contain("Processor: AMD Ryzen 7 9800X3D").And.Contain("Primary display: 2560x1440 @ 240 Hz");
strip.Lines.Should().ContainSingle().Which.Should().StartWith("info:");
vm.Lines.Should().HaveCount(6);
}
[Fact]
public async Task WhatCouldNotBeReadIsNotAvailableAndAThrowingSourceIsACardOfNotAvailable()
{
string[] partial = await InEnglishAsync(async () =>
{
var model = new SystemInfoViewModel(new FixedSource(static () => new HardwareSnapshot { GpuName = "Some GPU", DisplayRes = "1920x1080" }), new FakeClipboard(true), new FakeStrip());
await model.Pending.ConfigureAwait(false);
return model.Lines.Select(static l => l.Value).ToArray();
});
partial.Should().Equal("N/A", "Some GPU", "N/A", "N/A", "N/A", "1920x1080");
var strip = new FakeStrip();
string[] thrown = await InEnglishAsync(async () =>
{
var model = new SystemInfoViewModel(new FixedSource(static () => throw new InvalidOperationException("DXGI is not answering")), new FakeClipboard(accepts: false), strip);
await model.Pending.ConfigureAwait(false);
model.CopyCommand.Execute(null);
return model.Lines.Select(static l => l.Value).ToArray();
});
thrown.Should().AllBe("N/A").And.HaveCount(6);
strip.Lines.Should().ContainSingle().Which.Should().StartWith("warn:", "a clipboard another process holds is a refusal, never a crash");
}
}