@@ -6,26 +6,37 @@ namespace CodeLineCounter.Tests
66{
77 public class CodeAnalyzerTests
88 {
9+ private readonly TextWriter _originalConsoleOut ;
10+
11+ public CodeAnalyzerTests ( )
12+ {
13+ _originalConsoleOut = Console . Out ;
14+ }
15+
916 [ Fact ]
1017 public void TestAnalyzeSolution ( )
1118 {
12- using StringWriter consoleOutput = new ( ) ;
13- Console . SetOut ( consoleOutput ) ;
14-
15- string basePath = FileUtils . GetBasePath ( ) ;
16- var solutionPath = Path . GetFullPath ( Path . Combine ( basePath , ".." , ".." , ".." , ".." , "CodeLineCounter.sln" ) ) ;
17-
18- // Act
19- var ( metrics , projectTotals , totalLines , totalFiles , duplicationMap , dependencies ) = CodeMetricsAnalyzer . AnalyzeSolution ( solutionPath ) ;
20-
21- // Assert
22- Assert . NotNull ( metrics ) ;
23- Assert . NotEmpty ( metrics ) ;
24- Assert . NotEmpty ( projectTotals ) ;
25- Assert . NotEqual ( 0 , totalLines ) ;
26- Assert . NotEqual ( 0 , totalFiles ) ;
27- Assert . NotNull ( duplicationMap ) ;
28- Assert . NotNull ( dependencies ) ;
19+ using ( StringWriter consoleOutput = new ( ) )
20+ {
21+ Console . SetOut ( consoleOutput ) ;
22+
23+ string basePath = FileUtils . GetBasePath ( ) ;
24+ var solutionPath = Path . GetFullPath ( Path . Combine ( basePath , ".." , ".." , ".." , ".." , "CodeLineCounter.sln" ) ) ;
25+
26+ // Act
27+ var ( metrics , projectTotals , totalLines , totalFiles , duplicationMap , dependencies ) = CodeMetricsAnalyzer . AnalyzeSolution ( solutionPath ) ;
28+
29+ // Assert
30+ Assert . NotNull ( metrics ) ;
31+ Assert . NotEmpty ( metrics ) ;
32+ Assert . NotEmpty ( projectTotals ) ;
33+ Assert . NotEqual ( 0 , totalLines ) ;
34+ Assert . NotEqual ( 0 , totalFiles ) ;
35+ Assert . NotNull ( duplicationMap ) ;
36+ Assert . NotNull ( dependencies ) ;
37+ }
38+ // Reset console output
39+ Console . SetOut ( _originalConsoleOut ) ;
2940 }
3041
3142 [ Fact ]
@@ -52,6 +63,8 @@ public void AnalyzeSourceCode_Should_Set_CurrentNamespace()
5263 Assert . Equal ( "MyNamespace" , currentNamespace ) ;
5364
5465 }
66+ // Reset console output
67+ Console . SetOut ( _originalConsoleOut ) ;
5568
5669 }
5770
@@ -78,6 +91,8 @@ public void AnalyzeSourceCode_Should_Set_FileLineCount()
7891 // Assert - 3 lines only because comment lines are ignored
7992 Assert . Equal ( 3 , fileLineCount ) ;
8093 }
94+ // Reset console output
95+ Console . SetOut ( _originalConsoleOut ) ;
8196
8297 }
8398
@@ -104,6 +119,8 @@ public void AnalyzeSourceCode_Should_Set_FileCyclomaticComplexity()
104119 // Assert
105120 Assert . Equal ( 1 , fileCyclomaticComplexity ) ;
106121 }
122+ // Reset console output
123+ Console . SetOut ( _originalConsoleOut ) ;
107124
108125 }
109126
0 commit comments