@@ -26,10 +26,10 @@ public void ToHumanBytes_ShouldRespectDecimalPlaces()
2626 [ InlineData ( "1 KB" , 1024 ) ]
2727 [ InlineData ( "1 MB" , 1048576 ) ]
2828 [ InlineData ( "2.5 GB" , 2684354560 ) ]
29- [ InlineData ( "1B" , 1 ) ] // no space, raw bytes
30- [ InlineData ( "1KB" , 1024 ) ] // no space before suffix
31- [ InlineData ( " 1 MB" , 1048576 ) ] // leading space
32- [ InlineData ( "2 GB " , 2147483648 ) ] // trailing space
29+ [ InlineData ( "1B" , 1 ) ]
30+ [ InlineData ( "1KB" , 1024 ) ]
31+ [ InlineData ( " 1 MB" , 1048576 ) ]
32+ [ InlineData ( "2 GB " , 2147483648 ) ]
3333 public void ToBytes_ShouldParseCorrectly ( string input , long expected )
3434 {
3535 long result = input . ToBytes ( ) ;
@@ -42,6 +42,23 @@ public void ToBytes_InvalidString_ShouldThrow()
4242 Assert . Throws < FormatException > ( ( ) => "invalid" . ToBytes ( ) ) ;
4343 }
4444
45+ [ Theory ]
46+ [ InlineData ( "1 XB" ) ] // unsupported unit
47+ [ InlineData ( "ten MB" ) ] // not a number
48+ [ InlineData ( "1.2.3 GB" ) ] // malformed number
49+ [ InlineData ( " " ) ] // empty after trim
50+ public void ToBytes_InvalidInputs_ShouldThrow ( string input )
51+ {
52+ Assert . ThrowsAny < Exception > ( ( ) => input . ToBytes ( ) ) ;
53+ }
54+
55+ [ Fact ]
56+ public void ToBytes_Null_ShouldThrow ( )
57+ {
58+ string input = null ;
59+ Assert . Throws < ArgumentNullException > ( ( ) => input . ToBytes ( ) ) ;
60+ }
61+
4562 [ Fact ]
4663 public void TryParseHumanBytes_ShouldReturnFalseOnInvalidInput ( )
4764 {
@@ -50,5 +67,19 @@ public void TryParseHumanBytes_ShouldReturnFalseOnInvalidInput()
5067 Assert . False ( success ) ;
5168 Assert . Equal ( 0 , result ) ;
5269 }
70+
71+ [ Theory ]
72+ [ InlineData ( "1 XB" ) ]
73+ [ InlineData ( "ten MB" ) ]
74+ [ InlineData ( "1.2.3 GB" ) ]
75+ [ InlineData ( " " ) ]
76+ [ InlineData ( null ) ]
77+ public void TryParseHumanBytes_InvalidInputs_ShouldReturnFalse ( string input )
78+ {
79+ bool success = input . TryParseHumanBytes ( out long result ) ;
80+
81+ Assert . False ( success ) ;
82+ Assert . Equal ( 0 , result ) ;
83+ }
5384 }
5485}
0 commit comments