@@ -93,6 +93,65 @@ public void DisplayName_UnknownFileMode_ThrowsBencodeException()
9393 act . Invoking ( x => x ( ) ) . ShouldThrow < BencodeException > ( ) ;
9494 }
9595
96+ [ Fact ]
97+ public void PiecesAsHexString_Get_ReturnsHexUppercaseWithoutDashes ( )
98+ {
99+ var pieces = new byte [ ] { 66 , 115 , 135 , 19 , 149 , 125 , 229 , 85 , 68 , 117 , 252 , 185 , 243 , 247 , 139 , 38 , 11 , 37 , 60 , 112 } ;
100+ var torrent = new Torrent
101+ {
102+ Pieces = pieces
103+ } ;
104+
105+ torrent . PiecesAsHexString . Should ( ) . Be ( "42738713957DE5554475FCB9F3F78B260B253C70" ) ;
106+ }
107+
108+ [ Fact ]
109+ public void PiecesAsHexString_Set_ValidUppercaseHexSetsPiecesProperty ( )
110+ {
111+ var pieces = new byte [ ] { 66 , 115 , 135 , 19 , 149 , 125 , 229 , 85 , 68 , 117 , 252 , 185 , 243 , 247 , 139 , 38 , 11 , 37 , 60 , 112 } ;
112+ var torrent = new Torrent ( ) ;
113+
114+ torrent . PiecesAsHexString = "42738713957DE5554475FCB9F3F78B260B253C70" ;
115+
116+ torrent . Pieces . Should ( ) . Equal ( pieces ) ;
117+ }
118+
119+ [ Fact ]
120+ public void PiecesAsHexString_Set_NullThrowsArgumentException ( )
121+ {
122+ var torrent = new Torrent ( ) ;
123+ Action action = ( ) => torrent . PiecesAsHexString = null ;
124+ action . ShouldThrow < ArgumentException > ( ) ;
125+ }
126+
127+ [ Theory ]
128+ [ InlineAutoMockedData ( "qwer" ) ]
129+ [ InlineAutoMockedData ( "123456789012345678901234567890123456789" ) ]
130+ [ InlineAutoMockedData ( "12345678901234567890123456789012345678901" ) ]
131+ public void PiecesAsHexString_Set_LengthNotMultipleOf40ShouldThrowArgumentException ( string value )
132+ {
133+ var torrent = new Torrent ( ) ;
134+ Action action = ( ) => torrent . PiecesAsHexString = value ;
135+ action . ShouldThrow < ArgumentException > ( ) ;
136+ }
137+
138+ [ Theory ]
139+ [ InlineAutoMockedData ( "a" ) ]
140+ [ InlineAutoMockedData ( "b" ) ]
141+ [ InlineAutoMockedData ( "c" ) ]
142+ [ InlineAutoMockedData ( "G" ) ]
143+ [ InlineAutoMockedData ( "H" ) ]
144+ [ InlineAutoMockedData ( "T" ) ]
145+ [ InlineAutoMockedData ( "." ) ]
146+ [ InlineAutoMockedData ( "*" ) ]
147+ [ InlineAutoMockedData ( "[" ) ]
148+ public void PiecesAsHexString_Set_ValueWithNonUppercaseHexCharacterShouldThrowArgumentException ( string value )
149+ {
150+ var torrent = new Torrent ( ) ;
151+ Action action = ( ) => torrent . PiecesAsHexString = value ;
152+ action . ShouldThrow < ArgumentException > ( ) ;
153+ }
154+
96155 [ Theory ]
97156 [ AutoMockedData ]
98157 public void TotalSize_SingleFile_ShouldBeFileSize ( long fileSize )
0 commit comments