@@ -7,6 +7,40 @@ namespace CodeLineCounter.Tests.Services
77 public class SolutionAnalyzerTest
88 {
99
10+ [ Fact ]
11+ public void analyze_and_export_solution_succeeds_with_valid_inputs ( )
12+ {
13+ // Arrange
14+ var basePath = FileUtils . GetBasePath ( ) ;
15+ var solutionPath = Path . GetFullPath ( Path . Combine ( basePath , ".." , ".." , ".." , ".." ) ) ;
16+ solutionPath = Path . Combine ( solutionPath , "CodeLineCounter.sln" ) ;
17+ var sw = new StringWriter ( ) ;
18+ Console . SetOut ( sw ) ;
19+ var verbose = false ;
20+ var format = CoreUtils . ExportFormat . JSON ;
21+
22+ // Act & Assert
23+ var exception = Record . Exception ( ( ) =>
24+ SolutionAnalyzer . AnalyzeAndExportSolution ( solutionPath , verbose , format ) ) ;
25+
26+ Assert . Null ( exception ) ;
27+ }
28+
29+ [ Fact ]
30+ public void analyze_and_export_solution_throws_on_invalid_path ( )
31+ {
32+ // Arrange
33+ var invalidPath = "" ;
34+ var verbose = false ;
35+ var format = CoreUtils . ExportFormat . JSON ;
36+
37+ // Act & Assert
38+ var exception = Assert . Throws < UnauthorizedAccessException > ( ( ) =>
39+ SolutionAnalyzer . AnalyzeAndExportSolution ( invalidPath , verbose , format ) ) ;
40+
41+ Assert . Contains ( "Access to the path '' is denied." , exception . Message ) ;
42+ }
43+
1044 [ Fact ]
1145 public void PerformAnalysis_ShouldReturnCorrectAnalysisResult ( )
1246 {
@@ -106,7 +140,7 @@ public void OutputDetailedMetrics_ShouldPrintMetricsAndProjectTotals()
106140 SolutionAnalyzer . OutputDetailedMetrics ( metrics , projectTotals ) ;
107141
108142 // Assert
109- var expectedOutput =
143+ var expectedOutput =
110144 $ "Project Project1 (/path/to/project1) - Namespace Namespace1 in file File1.cs (/path/to/project1/File1.cs) has 100 lines of code and a cyclomatic complexity of 10.{ Environment . NewLine } " +
111145 $ "Project Project2 (/path/to/project2) - Namespace Namespace2 in file File2.cs (/path/to/project2/File2.cs) has 200 lines of code and a cyclomatic complexity of 20.{ Environment . NewLine } " +
112146 $ "Project Project1 has 100 total lines of code.{ Environment . NewLine } " +
@@ -116,39 +150,39 @@ public void OutputDetailedMetrics_ShouldPrintMetricsAndProjectTotals()
116150 }
117151 }
118152
119- // Export metrics, duplications and dependencies data in parallel for valid input
120- [ Fact ]
121- public void export_results_with_valid_input_exports_all_files ( )
122- {
123- // Arrange
124- var result = new AnalysisResult
125- {
126- SolutionFileName = "TestSolution" ,
127- Metrics = new List < NamespaceMetrics > ( ) ,
128- ProjectTotals = new Dictionary < string , int > ( ) ,
129- TotalLines = 1000 ,
130- DuplicationMap = new List < DuplicationCode > ( ) ,
131- DependencyList = new List < DependencyRelation > ( )
132- } ;
133-
134- var basePath = FileUtils . GetBasePath ( ) ;
135- var solutionPath = Path . GetFullPath ( Path . Combine ( basePath , ".." , ".." , ".." , ".." ) ) ;
136-
137- solutionPath = Path . Combine ( solutionPath , "TestSolution.sln" ) ;
138- var format = CoreUtils . ExportFormat . CSV ;
139-
140- // Act
141- using ( var sw = new StringWriter ( ) )
142- {
143- Console . SetOut ( sw ) ;
144- SolutionAnalyzer . ExportResults ( result , solutionPath , format ) ;
145- }
153+ // Export metrics, duplications and dependencies data in parallel for valid input
154+ [ Fact ]
155+ public void export_results_with_valid_input_exports_all_files ( )
156+ {
157+ // Arrange
158+ var result = new AnalysisResult
159+ {
160+ SolutionFileName = "TestSolution" ,
161+ Metrics = new List < NamespaceMetrics > ( ) ,
162+ ProjectTotals = new Dictionary < string , int > ( ) ,
163+ TotalLines = 1000 ,
164+ DuplicationMap = new List < DuplicationCode > ( ) ,
165+ DependencyList = new List < DependencyRelation > ( )
166+ } ;
167+
168+ var basePath = FileUtils . GetBasePath ( ) ;
169+ var solutionPath = Path . GetFullPath ( Path . Combine ( basePath , ".." , ".." , ".." , ".." ) ) ;
170+
171+ solutionPath = Path . Combine ( solutionPath , "TestSolution.sln" ) ;
172+ var format = CoreUtils . ExportFormat . CSV ;
146173
147- // Assert
148- Assert . True ( File . Exists ( "TestSolution-CodeMetrics.csv" ) ) ;
149- Assert . True ( File . Exists ( "TestSolution-CodeDuplications.csv" ) ) ;
150- Assert . True ( File . Exists ( "TestSolution-CodeDependencies.csv" ) ) ;
151- }
174+ // Act
175+ using ( var sw = new StringWriter ( ) )
176+ {
177+ Console . SetOut ( sw ) ;
178+ SolutionAnalyzer . ExportResults ( result , solutionPath , format ) ;
179+ }
180+
181+ // Assert
182+ Assert . True ( File . Exists ( "TestSolution-CodeMetrics.csv" ) ) ;
183+ Assert . True ( File . Exists ( "TestSolution-CodeDuplications.csv" ) ) ;
184+ Assert . True ( File . Exists ( "TestSolution-CodeDependencies.csv" ) ) ;
185+ }
152186
153187 }
154188}
0 commit comments