6
6
using System . IO ;
7
7
using System . Linq ;
8
8
using System . Text ;
9
+ using Does = ICSharpCode . SharpZipLib . Tests . TestSupport . Does ;
9
10
using TimeSetting = ICSharpCode . SharpZipLib . Zip . ZipEntryFactory . TimeSetting ;
10
11
11
12
namespace ICSharpCode . SharpZipLib . Tests . Zip
@@ -40,7 +41,7 @@ public void Basics()
40
41
ZipEntry entry = zf [ 0 ] ;
41
42
Assert . AreEqual ( tempName1 , entry . Name ) ;
42
43
Assert . AreEqual ( 1 , entry . Size ) ;
43
- Assert . IsTrue ( zf . TestArchive ( true ) ) ;
44
+ Assert . That ( zf , Does . PassTestArchive ( ) ) ;
44
45
45
46
zf . Close ( ) ;
46
47
}
@@ -128,7 +129,7 @@ public void CreateEmptyDirectories(string password)
128
129
var folderEntry = zipFile . GetEntry ( "floyd/" ) ;
129
130
Assert . That ( folderEntry . IsDirectory , Is . True , "The entry must be a folder" ) ;
130
131
131
- Assert . IsTrue ( zipFile . TestArchive ( testData : true ) ) ;
132
+ Assert . That ( zipFile , Does . PassTestArchive ( ) ) ;
132
133
}
133
134
}
134
135
}
@@ -166,14 +167,15 @@ public void ContentEqualAfterAfterArchived([Values(0, 1, 64)]int contentSize)
166
167
public void Encryption ( ZipEncryptionMethod encryptionMethod )
167
168
{
168
169
const string tempName1 = "a.dat" ;
170
+ const int tempSize = 1 ;
169
171
170
172
var target = new MemoryStream ( ) ;
171
173
172
174
string tempFilePath = GetTempFilePath ( ) ;
173
175
Assert . IsNotNull ( tempFilePath , "No permission to execute this test?" ) ;
174
176
175
177
string addFile = Path . Combine ( tempFilePath , tempName1 ) ;
176
- MakeTempFile ( addFile , 1 ) ;
178
+ MakeTempFile ( addFile , tempSize ) ;
177
179
178
180
try
179
181
{
@@ -189,17 +191,13 @@ public void Encryption(ZipEncryptionMethod encryptionMethod)
189
191
using ( ZipFile zf = new ZipFile ( archive ) )
190
192
{
191
193
zf . Password = "Ahoy" ;
192
- Assert . AreEqual ( 1 , zf . Count ) ;
193
- ZipEntry entry = zf [ 0 ] ;
194
- Assert . AreEqual ( tempName1 , entry . Name ) ;
195
- Assert . AreEqual ( 1 , entry . Size ) ;
196
- Assert . IsTrue ( zf . TestArchive ( true , TestStrategy . FindFirstError , ( status , message ) =>
197
- {
198
- if ( ! string . IsNullOrEmpty ( message ) ) {
199
- Console . WriteLine ( $ "{ message } ({ status . Entry ? . Name ?? "-" } )") ;
200
- }
201
- } ) ) ;
202
- Assert . IsTrue ( entry . IsCrypted ) ;
194
+ Assert . That ( zf . Count , Is . EqualTo ( 1 ) ) ;
195
+ var entry = zf [ 0 ] ;
196
+ Assert . That ( entry . Name , Is . EqualTo ( tempName1 ) ) ;
197
+ Assert . That ( entry . Size , Is . EqualTo ( tempSize ) ) ;
198
+ Assert . That ( entry . IsCrypted ) ;
199
+
200
+ Assert . That ( zf , Does . PassTestArchive ( ) ) ;
203
201
204
202
switch ( encryptionMethod )
205
203
{
@@ -363,14 +361,15 @@ public void ExtractExceptions()
363
361
public void ReadingOfLockedDataFiles ( )
364
362
{
365
363
const string tempName1 = "a.dat" ;
364
+ const int tempSize = 1 ;
366
365
367
366
var target = new MemoryStream ( ) ;
368
367
369
368
string tempFilePath = GetTempFilePath ( ) ;
370
369
Assert . IsNotNull ( tempFilePath , "No permission to execute this test?" ) ;
371
370
372
371
string addFile = Path . Combine ( tempFilePath , tempName1 ) ;
373
- MakeTempFile ( addFile , 1 ) ;
372
+ MakeTempFile ( addFile , tempSize ) ;
374
373
375
374
try
376
375
{
@@ -383,11 +382,11 @@ public void ReadingOfLockedDataFiles()
383
382
var archive = new MemoryStream ( target . ToArray ( ) ) ;
384
383
using ( ZipFile zf = new ZipFile ( archive ) )
385
384
{
386
- Assert . AreEqual ( 1 , zf . Count ) ;
387
- ZipEntry entry = zf [ 0 ] ;
388
- Assert . AreEqual ( tempName1 , entry . Name ) ;
389
- Assert . AreEqual ( 1 , entry . Size ) ;
390
- Assert . IsTrue ( zf . TestArchive ( true ) ) ;
385
+ Assert . That ( zf . Count , Is . EqualTo ( 1 ) ) ;
386
+ var entry = zf [ 0 ] ;
387
+ Assert . That ( entry . Name , Is . EqualTo ( tempName1 ) ) ;
388
+ Assert . That ( entry . Size , Is . EqualTo ( tempSize ) ) ;
389
+ Assert . That ( zf , Does . PassTestArchive ( ) ) ;
391
390
392
391
zf . Close ( ) ;
393
392
}
@@ -404,14 +403,15 @@ public void ReadingOfLockedDataFiles()
404
403
public void NonAsciiPasswords ( )
405
404
{
406
405
const string tempName1 = "a.dat" ;
406
+ const int tempSize = 1 ;
407
407
408
408
var target = new MemoryStream ( ) ;
409
409
410
410
string tempFilePath = GetTempFilePath ( ) ;
411
411
Assert . IsNotNull ( tempFilePath , "No permission to execute this test?" ) ;
412
412
413
413
string addFile = Path . Combine ( tempFilePath , tempName1 ) ;
414
- MakeTempFile ( addFile , 1 ) ;
414
+ MakeTempFile ( addFile , tempSize ) ;
415
415
416
416
string password = "abc\u0066 \u0393 " ;
417
417
try
@@ -425,12 +425,12 @@ public void NonAsciiPasswords()
425
425
using ( ZipFile zf = new ZipFile ( archive ) )
426
426
{
427
427
zf . Password = password ;
428
- Assert . AreEqual ( 1 , zf . Count ) ;
429
- ZipEntry entry = zf [ 0 ] ;
430
- Assert . AreEqual ( tempName1 , entry . Name ) ;
431
- Assert . AreEqual ( 1 , entry . Size ) ;
432
- Assert . IsTrue ( zf . TestArchive ( true ) ) ;
433
- Assert . IsTrue ( entry . IsCrypted ) ;
428
+ Assert . That ( zf . Count , Is . EqualTo ( 1 ) ) ;
429
+ var entry = zf [ 0 ] ;
430
+ Assert . That ( entry . Name , Is . EqualTo ( tempName1 ) ) ;
431
+ Assert . That ( entry . Size , Is . EqualTo ( tempSize ) ) ;
432
+ Assert . That ( zf , Does . PassTestArchive ( ) ) ;
433
+ Assert . That ( entry . IsCrypted ) ;
434
434
}
435
435
}
436
436
finally
@@ -636,10 +636,11 @@ public void SetDirectoryModifiedDate()
636
636
public void CreateZipShouldLeaveOutputStreamOpenIfRequested ( bool leaveOpen )
637
637
{
638
638
const string tempFileName = "a(2).dat" ;
639
+ const int tempSize = 16 ;
639
640
640
641
using var tempFolder = Utils . GetTempDir ( ) ;
641
642
// Create test input file
642
- tempFolder . CreateDummyFile ( tempFileName , size : 16 ) ;
643
+ tempFolder . CreateDummyFile ( tempFileName , tempSize ) ;
643
644
644
645
// Create the zip with fast zip
645
646
var target = new TrackedMemoryStream ( ) ;
@@ -653,11 +654,11 @@ public void CreateZipShouldLeaveOutputStreamOpenIfRequested(bool leaveOpen)
653
654
// Check that the file contents are correct in both cases
654
655
var archive = new MemoryStream ( target . ToArray ( ) ) ;
655
656
using var zf = new ZipFile ( archive ) ;
656
- Assert . AreEqual ( expected : 1 , zf . Count ) ;
657
+ Assert . That ( zf . Count , Is . EqualTo ( 1 ) ) ;
657
658
var entry = zf [ 0 ] ;
658
- Assert . AreEqual ( tempFileName , entry . Name ) ;
659
- Assert . AreEqual ( expected : 16 , entry . Size ) ;
660
- Assert . IsTrue ( zf . TestArchive ( testData : true ) ) ;
659
+ Assert . That ( entry . Name , Is . EqualTo ( tempFileName ) ) ;
660
+ Assert . That ( entry . Size , Is . EqualTo ( tempSize ) ) ;
661
+ Assert . That ( zf , Does . PassTestArchive ( ) ) ;
661
662
}
662
663
663
664
[ Category ( "Zip" ) ]
0 commit comments