Files
HashTool/tests/HashTool.App.Tests/ViewTests.cs
T
poli0981andClaude Opus 5.5 4bd17a50f4 feat: hashtool CLI, app tests, release packaging inputs and benchmarks
- src/HashTool.Cli: `hashtool hash | verify | check | algorithms` on top of
  Core, NativeAOT-ready (3.9 MB native binary), coreutils-style output and
  exit codes (0 ok, 1 failed/mismatch, 2 usage or unreadable checksum
  file); Windows paths are written with '/' so lines need no escaping.
- tests/HashTool.Cli.Tests: commands, formats and exit codes.
- tests/HashTool.App.Tests (Avalonia headless): every page in several
  languages including RTL, a folder create-and-verify flow, translation
  integrity (keys, placeholders, Languages.json/resx/project wiring,
  satellite assemblies, unused keys), system language detection, command
  line parsing and helpers.
- tests/Compat/LegacyClient: drives Velopack 0.0.1298 (the library inside
  Hash Tool 1.1.x) against new release files for the upgrade gate.
- build/macos/Info.plist keeps the 1.x bundle identity and adds "Open
  With" document types; build/linux/hashtool.png is the AppImage icon.
- bench/HashTool.Benchmarks (BenchmarkDotNet) and a tool manifest pinning
  vpk 1.2.161, nuget-license and CycloneDX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:16:40 +07:00

81 lines
3.1 KiB
C#

using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.VisualTree;
using HashTool.App.Services;
using HashTool.App.ViewModels;
using HashTool.App.Views;
using HashTool.Core.Hashing;
using HashTool.Core.Tests;
using Xunit;
namespace HashTool.App.Tests;
/// <summary>Renders the real window and pages on Avalonia's headless platform.</summary>
public sealed class ViewTests
{
private const string Sha256Of123456789 = "15E2B0D3C33891EBB0F1EF609EC419420C20E320CE94C65FBC8C3312448EB225";
[AvaloniaFact]
public void EveryPageRendersWithoutMissingTranslations()
{
var main = AppHost.Get<MainWindowViewModel>();
var localization = AppHost.Get<LocalizationService>();
var window = new MainWindow { DataContext = main };
window.Show();
try
{
foreach (var code in new[] { "en-US", "vi-VN", "ar", "ja-JP", "de-DE", "fil-PH" })
{
localization.SelectedLanguage = localization.Find(code);
Assert.Equal(code is "ar" ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, window.FlowDirection);
foreach (var page in new[] { "Create", "Check", "Settings", "Update", "About", "Developer" })
{
main.NavigateCommand.Execute(page);
Dispatcher.UIThread.RunJobs();
window.UpdateLayout();
var missing = window.GetVisualDescendants().OfType<TextBlock>()
.Select(t => t.Text)
.Where(t => t is not null && t.StartsWith('[') && t.EndsWith(']'))
.ToList();
Assert.True(missing.Count == 0, $"{code}/{page}: {string.Join(", ", missing)}");
}
}
}
finally
{
localization.SelectedLanguage = localization.AvailableLanguages[0];
main.NavigateCommand.Execute("Create");
window.Close();
}
}
[AvaloniaFact]
public async Task CreateAndVerify_FolderInputAndChecksumFile()
{
using var temp = new TempDirectory();
temp.File("folder/sub/check.txt", "123456789");
var create = AppHost.Get<CreateHashViewModel>();
var check = AppHost.Get<CheckHashViewModel>();
create.SelectedAlgorithm = HashType.SHA256;
// 1.x crashed when a folder was dropped.
await create.AddPathsAsync([Path.Combine(temp.Path, "folder")]);
await create.RunAllCommand.ExecuteAsync(null);
var created = Assert.Single(create.Items);
Assert.Equal(Sha256Of123456789, created.ResultHash, ignoreCase: true);
var manifest = temp.File("folder/SHA256SUMS", $"{Sha256Of123456789.ToLowerInvariant()} sub/check.txt\n");
await check.AddPathsAsync([manifest]);
await check.RunAllCommand.ExecuteAsync(null);
var verified = Assert.Single(check.Items);
Assert.True(verified.IsMatch);
Assert.Equal(ItemStatus.Valid, verified.Status);
}
}