Skip to content

Commit

Permalink
add an extra unit test for doing an async read on a ZipFile InputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Feb 14, 2021
1 parent c814877 commit 78bc308
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Tests.TestSupport;
using System.Threading.Tasks;

namespace ICSharpCode.SharpZipLib.Tests.Zip
{
Expand Down Expand Up @@ -180,6 +181,53 @@ public void ZipFileStoreAes()
}
}

/// <summary>
/// As <see cref="ZipFileStoreAes"/>, but with Async reads
/// </summary>
[Test]
[Category("Encryption")]
[Category("Zip")]
public async Task ZipFileStoreAesAsync()
{
string password = "password";

using (var memoryStream = new MemoryStream())
{
// Try to create a zip stream
WriteEncryptedZipToStream(memoryStream, password, 256, CompressionMethod.Stored);

// reset
memoryStream.Seek(0, SeekOrigin.Begin);

// try to read it
var zipFile = new ZipFile(memoryStream, leaveOpen: true)
{
Password = password
};

foreach (ZipEntry entry in zipFile)
{
if (!entry.IsFile) continue;

// Should be stored rather than deflated
Assert.That(entry.CompressionMethod, Is.EqualTo(CompressionMethod.Stored), "Entry should be stored");

using (var zis = zipFile.GetInputStream(entry))
{
var buffer = new byte[entry.Size];

using (var inputStream = zipFile.GetInputStream(entry))
{
await zis.ReadAsync(buffer, 0, buffer.Length);
}

var content = Encoding.UTF8.GetString(buffer);
Assert.That(content, Is.EqualTo(DummyDataString), "Decompressed content does not match input data");
}
}
}
}

/// <summary>
/// Test using AES encryption on a file whose contents are Stored rather than deflated
/// </summary>
Expand Down

0 comments on commit 78bc308

Please sign in to comment.