File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed
BencodeNET.Tests/Torrents Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -192,20 +192,17 @@ public void TotalSize_UnknownFileMode_IsZero()
192192
193193 [ Theory ]
194194 [ AutoMockedData ]
195- public void NumberOfPieces_ShouldBeTotalSizeDividedByPieceSizeRoundedUp ( long fileSize , long pieceSize )
195+ public void NumberOfPieces_ShouldBePiecesLengthDividedByPieceSizeRoundedUp ( int piecesByteCount , long pieceSize )
196196 {
197- var expected = ( int ) Math . Ceiling ( ( double ) fileSize / pieceSize ) ;
197+ var expected = ( int ) Math . Ceiling ( ( double ) piecesByteCount / pieceSize ) ;
198198
199199 var torrent = new Torrent
200200 {
201- File = new SingleFileInfo
202- {
203- FileSize = fileSize
204- } ,
201+ Pieces = new byte [ piecesByteCount ] ,
205202 PieceSize = pieceSize
206203 } ;
207204
208- torrent . TotalSize . Should ( ) . Be ( fileSize ) ;
205+ torrent . Pieces . Length . Should ( ) . Be ( piecesByteCount ) ;
209206 torrent . NumberOfPieces . Should ( ) . Be ( expected ) ;
210207 }
211208
Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ public virtual string DisplayName
164164 /// A concatenation of all 20-byte SHA1 hash values (one for each piece).
165165 /// Use <see cref="PiecesAsHexString"/> to get/set this value as a hex string instead.
166166 /// </summary>
167- public virtual byte [ ] Pieces { get ; set ; }
167+ public virtual byte [ ] Pieces { get ; set ; } = new byte [ 0 ] ;
168168
169169 /// <summary>
170170 /// Gets or sets <see cref="Pieces"/> from/to a hex string (without dashes), e.g. 1C115D26444AEF2A5E936133DCF8789A552BBE9F[...].
@@ -218,7 +218,9 @@ public virtual long TotalSize
218218 /// <summary>
219219 /// The total number of file pieces.
220220 /// </summary>
221- public virtual int NumberOfPieces => ( int ) Math . Ceiling ( ( double ) TotalSize / PieceSize ) ;
221+ public virtual int NumberOfPieces => Pieces != null
222+ ? ( int ) Math . Ceiling ( ( double ) Pieces . Length / PieceSize )
223+ : 0 ;
222224
223225 /// <summary>
224226 /// Converts the torrent to a <see cref="BDictionary"/>.
You can’t perform that action at this time.
0 commit comments