@@ -59,6 +59,57 @@ public void ParseArguments_Should_Ignore_Invalid_Arguments()
5959 Assert . Equal ( "testDirectory" , DirectoryPath ) ;
6060 }
6161
62+ // ParseArguments correctly processes valid command line arguments with all options
63+ [ Fact ]
64+ public void ParseArguments_processes_valid_arguments_with_all_options ( )
65+ {
66+ // Arrange
67+ string [ ] args = new [ ] { "-verbose" , "-d" , "C:/test" , "-format" , "JSON" , "-help" } ;
68+
69+ // Act
70+ var result = CoreUtils . ParseArguments ( args ) ;
71+
72+ // Assert
73+ Assert . True ( result . Verbose ) ;
74+ Assert . Equal ( "C:/test" , result . DirectoryPath ) ;
75+ Assert . True ( result . Help ) ;
76+ Assert . Equal ( CoreUtils . ExportFormat . JSON , result . format ) ;
77+ }
78+
79+ // ParseArguments handles empty or null argument array
80+ [ Fact ]
81+ public void ParseArguments_handles_empty_argument_array ( )
82+ {
83+ // Arrange
84+ string [ ] emptyArgs = Array . Empty < string > ( ) ;
85+
86+ // Act
87+ var result = CoreUtils . ParseArguments ( emptyArgs ) ;
88+
89+ // Assert
90+ Assert . False ( result . Verbose ) ;
91+ Assert . Null ( result . DirectoryPath ) ;
92+ Assert . False ( result . Help ) ;
93+ Assert . Equal ( CoreUtils . ExportFormat . CSV , result . format ) ;
94+ }
95+
96+ // ParseArguments processes invalid format option gracefully
97+ [ Fact ]
98+ public void ParseArguments_handles_invalid_format_option ( )
99+ {
100+ // Arrange
101+ string [ ] args = new [ ] { "-format" , "INVALID" } ;
102+ var consoleOutput = new StringWriter ( ) ;
103+ Console . SetOut ( consoleOutput ) ;
104+
105+ // Act
106+ var result = CoreUtils . ParseArguments ( args ) ;
107+
108+ // Assert
109+ Assert . Equal ( CoreUtils . ExportFormat . CSV , result . format ) ;
110+ Assert . Contains ( "Invalid format" , consoleOutput . ToString ( ) ) ;
111+ }
112+
62113 [ Fact ]
63114 public void GetUserChoice_Should_Return_Valid_Choice ( )
64115 {
@@ -91,6 +142,39 @@ public void GetUserChoice_Should_Return_Invalid_Choice()
91142 Assert . Equal ( - 1 , result ) ;
92143 }
93144
145+ // GetUserChoice returns valid selection when input is within range
146+ [ Fact ]
147+ public void GetUserChoice_returns_valid_selection_for_valid_input ( )
148+ {
149+ // Arrange
150+ var input = "2" ;
151+ var consoleInput = new StringReader ( input ) ;
152+ Console . SetIn ( consoleInput ) ;
153+
154+ // Act
155+ int result = CoreUtils . GetUserChoice ( 3 ) ;
156+
157+ // Assert
158+ Assert . Equal ( 2 , result ) ;
159+ }
160+
161+ [ Theory ]
162+ [ InlineData ( "" ) ]
163+ [ InlineData ( " " ) ]
164+ [ InlineData ( "abc" ) ]
165+ public void GetUserChoice_handles_invalid_input ( string input )
166+ {
167+ // Arrange
168+ var consoleInput = new StringReader ( input ) ;
169+ Console . SetIn ( consoleInput ) ;
170+
171+ // Act
172+ int result = CoreUtils . GetUserChoice ( 5 ) ;
173+
174+ // Assert
175+ Assert . Equal ( - 1 , result ) ;
176+ }
177+
94178 [ Fact ]
95179 public void DisplaySolutions_Should_Write_Solutions_To_Console ( )
96180 {
@@ -204,5 +288,21 @@ public void CheckSettings_WhenSettingsAreInvalid_ReturnsFalse()
204288 // Assert
205289 Assert . False ( result ) ;
206290 }
291+
292+ [ Theory ]
293+ [ InlineData ( "CO.Solution.Build-CodeMetrics.txt" , CoreUtils . ExportFormat . CSV ) ]
294+ [ InlineData ( "CO.Solution.Build-CodeDuplications.json" , CoreUtils . ExportFormat . JSON ) ]
295+ [ InlineData ( "CO.Solution.Build-CodeMetrics." , CoreUtils . ExportFormat . CSV ) ]
296+ [ InlineData ( "CO.Solution.Build-CodeDuplications.²" , CoreUtils . ExportFormat . JSON ) ]
297+ [ InlineData ( "metrics_789.csv" , CoreUtils . ExportFormat . CSV ) ]
298+ public void get_export_file_name_with_extension_handles_alphanumeric ( string fileName , CoreUtils . ExportFormat format )
299+ {
300+ // Act
301+ var result = CoreUtils . GetExportFileNameWithExtension ( fileName , format ) ;
302+
303+ // Assert
304+ Assert . Contains ( Path . GetFileNameWithoutExtension ( fileName ) , result ) ;
305+ Assert . True ( File . Exists ( result ) || ! File . Exists ( result ) ) ;
306+ }
207307 }
208308}
0 commit comments