Skip to content

Commit 5ffb3cb

Browse files
committed
tests: ZipFileExtensions async
1 parent 146e2ea commit 5ffb3cb

File tree

3 files changed

+80
-56
lines changed

3 files changed

+80
-56
lines changed

src/libraries/System.IO.Compression.ZipFile/tests/ZipFileExtensions.ZipArchive.Create.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
4+
using System.Collections.Generic;
55
using System.Threading.Tasks;
66
using Xunit;
77

88
namespace System.IO.Compression.Tests
99
{
1010
public class ZipFile_ZipArchive_Create : ZipFileTestBase
1111
{
12+
public static IEnumerable<object[]> Get_CreateEntryFromFileExtension_Data()
13+
{
14+
foreach (bool withCompressionLevel in _bools)
15+
{
16+
foreach (bool async in _bools)
17+
{
18+
yield return new object[] { withCompressionLevel, async };
19+
}
20+
}
21+
}
22+
1223
[Theory]
13-
[InlineData(true)]
14-
[InlineData(false)]
15-
public async Task CreateEntryFromFileExtension(bool withCompressionLevel)
24+
[MemberData(nameof(Get_CreateEntryFromFileExtension_Data))]
25+
public async Task CreateEntryFromFileExtension(bool withCompressionLevel, bool async)
1626
{
1727
//add file
1828
using (TempFile testArchive = CreateTempCopyFile(zfile("normal.zip"), GetTestFilePath()))
1929
{
20-
using (ZipArchive archive = ZipFile.Open(testArchive.Path, ZipArchiveMode.Update))
21-
{
30+
ZipArchive archive = await CallZipFileOpen(async, testArchive.Path, ZipArchiveMode.Update);
31+
2232
string entryName = "added.txt";
2333
string sourceFilePath = zmodified(Path.Combine("addFile", entryName));
2434

25-
Assert.Throws<ArgumentNullException>(() => ((ZipArchive)null).CreateEntryFromFile(sourceFilePath, entryName));
26-
Assert.Throws<ArgumentNullException>(() => archive.CreateEntryFromFile(null, entryName));
27-
Assert.Throws<ArgumentNullException>(() => archive.CreateEntryFromFile(sourceFilePath, null));
35+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallZipFileExtensionsCreateEntryFromFile(async, (ZipArchive)null, sourceFilePath, entryName));
36+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallZipFileExtensionsCreateEntryFromFile(async, archive, null, entryName));
37+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallZipFileExtensionsCreateEntryFromFile(async, archive, sourceFilePath, null));
2838

2939
ZipArchiveEntry e = withCompressionLevel ?
30-
archive.CreateEntryFromFile(sourceFilePath, entryName) :
31-
archive.CreateEntryFromFile(sourceFilePath, entryName, CompressionLevel.Fastest);
40+
await CallZipFileExtensionsCreateEntryFromFile(async, archive, sourceFilePath, entryName) :
41+
await CallZipFileExtensionsCreateEntryFromFile(async, archive, sourceFilePath, entryName, CompressionLevel.Fastest);
3242
Assert.NotNull(e);
33-
}
34-
await IsZipSameAsDirAsync(testArchive.Path, zmodified("addFile"), ZipArchiveMode.Read, requireExplicit: false, checkTimes: false);
43+
44+
await DisposeZipArchive(async, archive);
45+
46+
await IsZipSameAsDir(testArchive.Path, zmodified("addFile"), ZipArchiveMode.Read, requireExplicit: false, checkTimes: false, async);
3547
}
3648
}
3749
}

src/libraries/System.IO.Compression.ZipFile/tests/ZipFileExtensions.ZipArchive.Extract.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Threading.Tasks;
45
using Xunit;
56

67
namespace System.IO.Compression.Tests
78
{
89
public class ZipFile_ZipArchive_Extract : ZipFileTestBase
910
{
10-
[Fact]
11-
public void ExtractToDirectoryExtension()
11+
[Theory]
12+
[MemberData(nameof(Get_Booleans_Data))]
13+
public async Task ExtractToDirectoryExtension(bool async)
1214
{
13-
using (ZipArchive archive = ZipFile.Open(zfile("normal.zip"), ZipArchiveMode.Read))
14-
{
15-
string tempFolder = GetTestFilePath();
16-
Assert.Throws<ArgumentNullException>(() => ((ZipArchive)null).ExtractToDirectory(tempFolder));
17-
Assert.Throws<ArgumentNullException>(() => archive.ExtractToDirectory(null));
18-
archive.ExtractToDirectory(tempFolder);
19-
20-
DirsEqual(tempFolder, zfolder("normal"));
21-
}
15+
ZipArchive archive = await CallZipFileOpen(async, zfile("normal.zip"), ZipArchiveMode.Read);
16+
17+
string tempFolder = GetTestFilePath();
18+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallZipFileExtensionsExtractToDirectory(async, (ZipArchive)null, tempFolder));
19+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallZipFileExtensionsExtractToDirectory(async, archive, null));
20+
await CallZipFileExtensionsExtractToDirectory(async, archive, tempFolder);
21+
22+
DirsEqual(tempFolder, zfolder("normal"));
23+
24+
await DisposeZipArchive(async, archive);
2225
}
2326

24-
[Fact]
2527
[ActiveIssue("https://github.com/dotnet/runtime/issues/72951", TestPlatforms.iOS | TestPlatforms.tvOS)]
26-
public void ExtractToDirectoryExtension_Unicode()
28+
[Theory]
29+
[MemberData(nameof(Get_Booleans_Data))]
30+
public async Task ExtractToDirectoryExtension_Unicode(bool async)
2731
{
28-
using (ZipArchive archive = ZipFile.OpenRead(zfile("unicode.zip")))
29-
{
30-
string tempFolder = GetTestFilePath();
31-
archive.ExtractToDirectory(tempFolder);
32-
DirFileNamesEqual(tempFolder, zfolder("unicode"));
33-
}
32+
ZipArchive archive = await CallZipFileOpenRead(async, zfile("unicode.zip"));
33+
34+
string tempFolder = GetTestFilePath();
35+
await CallZipFileExtensionsExtractToDirectory(async, archive, tempFolder);
36+
DirFileNamesEqual(tempFolder, zfolder("unicode"));
37+
38+
await DisposeZipArchive(async, archive);
39+
3440
}
3541

3642
}
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Threading.Tasks;
45
using Xunit;
56

67
namespace System.IO.Compression.Tests
78
{
89
public class ZipFile_ZipArchiveEntry_Extract : ZipFileTestBase
910
{
10-
[Fact]
11-
public void ExtractToFileExtension()
11+
[Theory]
12+
[MemberData(nameof(Get_Booleans_Data))]
13+
public async Task ExtractToFileExtension(bool async)
1214
{
13-
using (ZipArchive archive = ZipFile.Open(zfile("normal.zip"), ZipArchiveMode.Read))
14-
{
15-
string file = GetTestFilePath();
16-
ZipArchiveEntry e = archive.GetEntry("first.txt");
15+
ZipArchive archive = await CallZipFileOpen(async, zfile("normal.zip"), ZipArchiveMode.Read);
16+
17+
string file = GetTestFilePath();
18+
ZipArchiveEntry e = archive.GetEntry("first.txt");
1719

18-
Assert.Throws<ArgumentNullException>(() => ((ZipArchiveEntry)null).ExtractToFile(file));
19-
Assert.Throws<ArgumentNullException>(() => e.ExtractToFile(null));
20+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallExtractToFile(async, (ZipArchiveEntry)null, file));
21+
await Assert.ThrowsAsync<ArgumentNullException>(() => CallExtractToFile(async, e, null));
2022

21-
//extract when there is nothing there
22-
e.ExtractToFile(file);
23+
//extract when there is nothing there
24+
await CallExtractToFile(async, e, file);
2325

24-
using (Stream fs = File.Open(file, FileMode.Open), es = e.Open())
25-
{
26-
StreamsEqual(fs, es);
27-
}
26+
using (Stream fs = File.Open(file, FileMode.Open))
27+
{
28+
Stream es = await OpenEntryStream(async, e);
29+
StreamsEqual(fs, es);
30+
await DisposeStream(async, es);
31+
}
2832

29-
Assert.Throws<IOException>(() => e.ExtractToFile(file, false));
33+
await Assert.ThrowsAsync<IOException>(() => CallExtractToFile(async, e, file, false));
3034

31-
//truncate file
32-
using (Stream fs = File.Open(file, FileMode.Truncate))
33-
{ }
35+
//truncate file
36+
using (Stream fs = File.Open(file, FileMode.Truncate)) { }
3437

35-
//now use overwrite mode
36-
e.ExtractToFile(file, true);
38+
//now use overwrite mode
39+
await CallExtractToFile(async, e, file, true);
3740

38-
using (Stream fs = File.Open(file, FileMode.Open), es = e.Open())
39-
{
40-
StreamsEqual(fs, es);
41-
}
41+
using (Stream fs = File.Open(file, FileMode.Open))
42+
{
43+
Stream es = await OpenEntryStream(async, e);
44+
StreamsEqual(fs, es);
45+
await DisposeStream(async, es);
4246
}
47+
48+
await DisposeZipArchive(async, archive);
4349
}
4450
}
4551
}

0 commit comments

Comments
 (0)