@@ -9,21 +9,23 @@ namespace JulianVerdurmen.SlnxValidator.Tests;
99
1010public class ValidatorRunnerTests
1111{
12- private static ValidatorRunner CreateRunner ( IFileSystem fileSystem , IRequiredFilesChecker ? checker = null )
12+ private readonly FakeConsole _console = new ( ) ;
13+
14+ private ValidatorRunner CreateRunner ( IFileSystem fileSystem , IRequiredFilesChecker ? checker = null )
1315 {
1416 checker ??= Substitute . For < IRequiredFilesChecker > ( ) ;
1517 var resolver = Substitute . For < ISlnxFileResolver > ( ) ;
1618 var collector = new SlnxCollector ( fileSystem , resolver , Substitute . For < ISlnxValidator > ( ) , checker ) ;
1719 var sonarReporter = new SonarReporter ( fileSystem ) ;
1820 var sarifReporter = new SarifReporter ( fileSystem ) ;
19- return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem ) ;
21+ return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem , _console ) ;
2022 }
2123
2224 private static ValidatorRunnerOptions Options ( string input = "test.slnx" ,
2325 bool continueOnError = false , string ? requiredFilesPattern = null ) =>
2426 new ( input , SonarqubeReportPath : null , continueOnError , requiredFilesPattern , WorkingDirectory : "." ) ;
2527
26- private static ValidatorRunner CreateRunnerWithSlnx (
28+ private ValidatorRunner CreateRunnerWithSlnx (
2729 string slnxPath , string slnxContent , IRequiredFilesChecker ? checker = null )
2830 {
2931 checker ??= Substitute . For < IRequiredFilesChecker > ( ) ;
@@ -39,7 +41,7 @@ private static ValidatorRunner CreateRunnerWithSlnx(
3941 var collector = new SlnxCollector ( fileSystem , resolver , validator , checker ) ;
4042 var sonarReporter = new SonarReporter ( fileSystem ) ;
4143 var sarifReporter = new SarifReporter ( fileSystem ) ;
42- return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem ) ;
44+ return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem , _console ) ;
4345 }
4446
4547 #region RunAsync – file resolution
@@ -248,5 +250,54 @@ public async Task RunAsync_IgnoreAllCodesMajorSpecificCode_SpecificCodeCausesExi
248250 }
249251
250252 #endregion
251- }
252253
254+ #region RunAsync – console output
255+
256+ [ Test ]
257+ public async Task RunAsync_NoFilesFound_WritesErrorToConsole ( )
258+ {
259+ // Arrange
260+ var runner = CreateRunner ( new MockFileSystem ( ) ) ;
261+
262+ // Act
263+ await runner . RunAsync ( Options ( "nonexistent.slnx" ) , CancellationToken . None ) ;
264+
265+ // Assert
266+ _console . ErrorLines . Should ( ) . ContainMatch ( "*No .slnx files found for input: nonexistent.slnx*" ) ;
267+ }
268+
269+ [ Test ]
270+ public async Task RunAsync_SonarqubeReportPath_WritesConfirmationToConsole ( )
271+ {
272+ // Arrange
273+ var slnxPath = Path . GetFullPath ( "test.slnx" ) ;
274+ var runner = CreateRunnerWithSlnx ( slnxPath , "<Solution />" ) ;
275+ var options = new ValidatorRunnerOptions ( slnxPath , SonarqubeReportPath : "report.xml" ,
276+ ContinueOnError : false , RequiredFilesPattern : null , WorkingDirectory : "." ) ;
277+
278+ // Act
279+ await runner . RunAsync ( options , CancellationToken . None ) ;
280+
281+ // Assert
282+ _console . OutputLines . Should ( ) . ContainMatch ( "*SonarQube report written to: report.xml*" ) ;
283+ }
284+
285+ [ Test ]
286+ public async Task RunAsync_SarifReportPath_WritesConfirmationToConsole ( )
287+ {
288+ // Arrange
289+ var slnxPath = Path . GetFullPath ( "test.slnx" ) ;
290+ var runner = CreateRunnerWithSlnx ( slnxPath , "<Solution />" ) ;
291+ var options = new ValidatorRunnerOptions ( slnxPath , SonarqubeReportPath : null ,
292+ ContinueOnError : false , RequiredFilesPattern : null , WorkingDirectory : "." ,
293+ SarifReportPath : "report.sarif" ) ;
294+
295+ // Act
296+ await runner . RunAsync ( options , CancellationToken . None ) ;
297+
298+ // Assert
299+ _console . OutputLines . Should ( ) . ContainMatch ( "*SARIF report written to: report.sarif*" ) ;
300+ }
301+
302+ #endregion
303+ }
0 commit comments