Skip to content

test: add xUnit test project with 100% coverage gate - #42

Merged
amd989 merged 3 commits into
masterfrom
claude/test-project-coverage-3c8c43
Nov 6, 2026
Merged

amd989 merged 3 commits into
masterfrom
claude/test-project-coverage-3c8c43

Conversation

@amd989

@amd989 amd989 commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a Symlinker.Tests project (xUnit v3) and a coverage gate: every dotnet test run collects coverage for the app and fails below 100% line, branch or method coverage. CI now runs the tests on pull requests and uploads the Cobertura report.

To make the app testable, the logic moves out of the window into plain classes. MainWindow is now view glue. This branch is up to date with #40 (UI/UX fixes) and #41 (elevate only the link step), and both are wired through the new classes without changing their behavior.

What changed

New classes (all tested)

  • LinkCreator: the link workflow (replace prompts, move-and-link, copy with progress across drives, rollback on failure). It talks to an IDialogService and an ILinkRunner, so tests drive it with fakes against the real file system.
  • LinkRunner (ILinkRunner): feat: elevate only the link step instead of restarting as admin #41's "elevate only when needed" logic, moved out of the window. PrepareAsync() starts the admin helper (one UAC prompt) before anything on disk changes, restarts it if it died, and returns false on a declined prompt. RunAsync() sends symbolic links that need admin to the helper and everything else to LinkCommand.
  • InputValidator: the field checks behind fix: address main window UI/UX review findings #40's inline errors, plus ColorContrast for text on the accent color.
  • UiHelpers: path names, picker start folders, byte formatting, app version, LinkNameAutoFill.
  • Dialogs.cs: IDialogService / IProgressDialog and the MahApps implementation.

Changes to code from #40 and #41

Excluded from coverage ([ExcludeFromCodeCoverage], each with a justification)

  • MainWindow, App, Program, MetroDialogService, InputError: need a live window.
  • ElevatedLinker.StartAsync: shows the UAC prompt.
  • ElevatedLinker.GetServerProcessId, Elevation.GetShieldIcon: native calls whose failure paths can't be triggered.
  • Generated resource code is skipped by attribute.

Tooling

  • global.json opts dotnet test into Microsoft.Testing.Platform (xunit.v3 4.x requires it on the .NET 10 SDK).
  • Coverage comes from coverlet.MTP. The settings are in Symlinker.Tests.csproj.
  • CLAUDE.md documents the testing setup and the new classes.

Behavior changes (small, from removing unreachable branches)

  • The move check no longer tests "source inside target". The target is always missing or an empty folder, so that case can't happen.
  • The target's parent folder is created with Path.Combine(target, ".."). Before, a target typed with a trailing slash (D:\x\y\) created y itself, and the move then failed.
  • If a rollback fails, the message always says where the files are now (the original path if they never moved).
  • LinkMover.IsLink drops a redundant Exists check. Missing entries are still "not a link".
  • LinkPathInUse drops a catch (ArgumentException) that Path.Combine can no longer throw on .NET Core.
  • When replacing an existing item, admin rights are now asked for once before the delete. Before feat: elevate only the link step instead of restarting as admin #41 was moved into LinkCreator, the window asked before the delete and checked again before mklink; the second check was always a no-op.

Reviewer notes

  • Folder links in tests are junctions, which need no special rights. Three tests need real symbolic links: they skip without Developer Mode or elevation, and the coverage gate then fails locally because their 8 lines aren't covered. GitHub's Windows runners are elevated, so CI runs everything.
  • Tested locally with Developer Mode on: 172 tests pass, nothing skipped, 100% line, branch and method coverage. Five repeated runs were all green (the pipe tests use threads). Release build is clean. Symlinker.exe --link-helper with bad arguments exits with code 2, and the window launches with --mode file --type hard.
  • Retested by hand after this merge with Developer Mode off: the real UAC flow from feat: elevate only the link step instead of restarting as admin #41 works (first symbolic link asks once, later ones don't, declining leaves everything as it was). The logic is also unit-tested in LinkRunnerTests and LinkCreatorTests.

🤖 Generated with Claude Code

amd989 and others added 3 commits November 6, 2026 08:05
Move the link workflow out of MainWindow into testable classes
(LinkCreator, Mklink, UiHelpers) behind a small dialog interface,
and cover them with tests against the real file system.

- dotnet test runs on Microsoft.Testing.Platform (global.json) and
  fails below 100% line, branch or method coverage (coverlet.MTP)
- WPF and UAC glue is marked [ExcludeFromCodeCoverage]
- CI runs the tests on pull requests and uploads the coverage report
- Remove unreachable branches in the move and rollback paths
- Update CLAUDE.md for the WPF layout and testing

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-coverage-3c8c43

# Conflicts:
#	CLAUDE.md
#	Symlinker/MainWindow.xaml.cs
#	Symlinker/Program.cs
…-coverage-3c8c43

# Conflicts:
#	CLAUDE.md
#	Symlinker/Elevation.cs
#	Symlinker/MainWindow.Inputs.cs
#	Symlinker/MainWindow.xaml.cs
@amd989
amd989 merged commit a796a45 into master Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant