Inject IConsole into ValidatorRunner for testable console output#75
Merged
304NotModified merged 4 commits intomainfrom Apr 17, 2026
Merged
Conversation
Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/2ef89553-2469-46d8-8587-2c62c427fa11 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Inject IConsole into ValidatorRunner for improved testability
Inject IConsole into ValidatorRunner for testable console output
Apr 17, 2026
304NotModified
requested changes
Apr 17, 2026
…onsole required, remove SizeCapturingStream Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/d2fc4b14-e446-4e41-8704-97bcd27ae058 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
304NotModified
requested changes
Apr 17, 2026
…s, use instance _console field in tests Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/72e734b1-9ad7-4cb3-91ee-5cddb2c4570e Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
304NotModified
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ValidatorRunnerwrote directly toConsole.WriteLine/Console.Error, making stdout/stderr output untestable. SinceSystem.CommandLine2.0.6 removedIConsole, the abstraction is defined in-project.Core changes
IConsole— single interface with asyncWriteLineAsync(string)andWriteErrorLineAsync(string)methodsSystemConsole— production impl delegating toConsole.Out.WriteLineAsync/Console.Error.WriteLineAsyncValidatorRunner—IConsole consoleadded as primary-constructor parameter; all threeConsole.*calls replaced:Program.cs—IConsoleregistered asnew SystemConsole()singleton in DITest infrastructure
FakeConsole— in-memory impl withList<string> OutputLinesandList<string> ErrorLinesproperties for easy assertionMockFileSystem—GetFileSizereturns0; no stream-wrapping complexityValidatorRunnerTests—_consoleis a shared instance field (fresh per test via NUnit's per-test instantiation); factory helpers are instance methods that use_console; three new tests cover the "no files found" error path and the SonarQube/SARIF confirmation messagesOriginal prompt
Goal
Make
ValidatorRunnertestable by replacing directConsole.WriteLine/Console.Error.WriteLineAsynccalls with an injectedSystem.CommandLine.IConsoleabstraction. Add the missing tests that verify console output. Update all existing test helpers that constructValidatorRunnerso they compile and pass.1. Change
ValidatorRunner– injectIConsoleFile:
src/SLNX-validator/ValidatorRunner.csAdd
IConsole consoleas a primary-constructor parameter (afterIFileSystem fileSystem).Replace:
with:
Replace both:
and:
with:
and:
Add the using:
using System.CommandLine;2. Register
IConsolein DI –Program.csFile:
src/SLNX-validator/Program.csIn the
ServiceCollectionsetup, add:SystemConsoleis the concrete type inSystem.CommandLinethat wraps the realConsole.3. Update
ValidatorRunnerTests.csFile:
tests/SLNX-validator.Tests/ValidatorRunnerTests.cs3a. Add helper to create a test console
At the top of the class add a private helper that creates a simple in-memory console for testing.
System.CommandLineships aTestConsoleclass; use that.Add using:
using System.CommandLine;3b. Update
CreateRunnerandCreateRunnerWithSlnxBoth factory methods must accept an optional
IConsole? console = nullparameter and passconsole ?? new TestConsole()as the last argument to theValidatorRunnerconstructor.3c. Add missing tests for console output
Add a new test region
#region RunAsync – console outputwith the following tests (no more than needed):Important:
TestConsolefromSystem.CommandLinehas.Errorand.OutasIStandardStreamWriter. Use.ToString()on them to get the written text.Notes
System.CommandLineis already referenced insrc/SLNX-validator/SLNX-validator.csprojand the test project references the main project, soTestConsoleis already available in tests.IConsole? consoleparameter).The following is the prior conversation context from the user's chat exploration (may be truncated):
User: We missen wat tests voor @304NotModified/SLNX-validator/files/src/SLNX-validator/ValidatorRunner.cs. maar we missen ook een abstractie voor de console. Is daar een goede package voor of kunnen we beter een eigen schrijven?
Assistant: Goede bevindingen! Het project gebruikt al
System.CommandLine(...This pull request was created from Copilot chat.