@@ -9,22 +9,22 @@ namespace JulianVerdurmen.SlnxValidator.Tests;
99
1010public class ValidatorRunnerTests
1111{
12- private static ValidatorRunner CreateRunner ( IFileSystem fileSystem , IRequiredFilesChecker ? checker = null )
12+ private static ValidatorRunner CreateRunner ( IFileSystem fileSystem , IRequiredFilesChecker ? checker = null , IConsole ? console = null )
1313 {
1414 checker ??= Substitute . For < IRequiredFilesChecker > ( ) ;
1515 var resolver = Substitute . For < ISlnxFileResolver > ( ) ;
1616 var collector = new SlnxCollector ( fileSystem , resolver , Substitute . For < ISlnxValidator > ( ) , checker ) ;
1717 var sonarReporter = new SonarReporter ( fileSystem ) ;
1818 var sarifReporter = new SarifReporter ( fileSystem ) ;
19- return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem ) ;
19+ return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem , console ?? new TestConsole ( ) ) ;
2020 }
2121
2222 private static ValidatorRunnerOptions Options ( string input = "test.slnx" ,
2323 bool continueOnError = false , string ? requiredFilesPattern = null ) =>
2424 new ( input , SonarqubeReportPath : null , continueOnError , requiredFilesPattern , WorkingDirectory : "." ) ;
2525
2626 private static ValidatorRunner CreateRunnerWithSlnx (
27- string slnxPath , string slnxContent , IRequiredFilesChecker ? checker = null )
27+ string slnxPath , string slnxContent , IRequiredFilesChecker ? checker = null , IConsole ? console = null )
2828 {
2929 checker ??= Substitute . For < IRequiredFilesChecker > ( ) ;
3030 var fileSystem = new MockFileSystem ( new Dictionary < string , string >
@@ -39,7 +39,7 @@ private static ValidatorRunner CreateRunnerWithSlnx(
3939 var collector = new SlnxCollector ( fileSystem , resolver , validator , checker ) ;
4040 var sonarReporter = new SonarReporter ( fileSystem ) ;
4141 var sarifReporter = new SarifReporter ( fileSystem ) ;
42- return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem ) ;
42+ return new ValidatorRunner ( collector , sonarReporter , sarifReporter , checker , fileSystem , console ?? new TestConsole ( ) ) ;
4343 }
4444
4545 #region RunAsync – file resolution
@@ -248,5 +248,58 @@ public async Task RunAsync_IgnoreAllCodesMajorSpecificCode_SpecificCodeCausesExi
248248 }
249249
250250 #endregion
251+
252+ #region RunAsync – console output
253+
254+ [ Test ]
255+ public async Task RunAsync_NoFilesFound_WritesErrorToConsole ( )
256+ {
257+ // Arrange
258+ var console = new TestConsole ( ) ;
259+ var runner = CreateRunner ( new MockFileSystem ( ) , console : console ) ;
260+
261+ // Act
262+ await runner . RunAsync ( Options ( "nonexistent.slnx" ) , CancellationToken . None ) ;
263+
264+ // Assert
265+ console . Error . ToString ( ) . Should ( ) . Contain ( "No .slnx files found for input: nonexistent.slnx" ) ;
266+ }
267+
268+ [ Test ]
269+ public async Task RunAsync_SonarqubeReportPath_WritesConfirmationToConsole ( )
270+ {
271+ // Arrange
272+ var slnxPath = Path . GetFullPath ( "test.slnx" ) ;
273+ var console = new TestConsole ( ) ;
274+ var runner = CreateRunnerWithSlnx ( slnxPath , "<Solution />" , console : console ) ;
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 . Out . ToString ( ) . Should ( ) . Contain ( "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 console = new TestConsole ( ) ;
291+ var runner = CreateRunnerWithSlnx ( slnxPath , "<Solution />" , console : console ) ;
292+ var options = new ValidatorRunnerOptions ( slnxPath , SonarqubeReportPath : null ,
293+ ContinueOnError : false , RequiredFilesPattern : null , WorkingDirectory : "." ,
294+ SarifReportPath : "report.sarif" ) ;
295+
296+ // Act
297+ await runner . RunAsync ( options , CancellationToken . None ) ;
298+
299+ // Assert
300+ console . Out . ToString ( ) . Should ( ) . Contain ( "SARIF report written to: report.sarif" ) ;
301+ }
302+
303+ #endregion
251304}
252305
0 commit comments