using System.Diagnostics;
using System.Threading.Tasks;
using NUnit.Framework.Internal;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
void Repro(string input) {
using var ms = new MemoryStream();
using (var zos = new ZipOutputStream(ms){ IsStreamOwner = false }) {
zos.PutNextEntry(new ZipEntry("file1"){ CompressionMethod = CompressionMethod.Stored });
zos.Write(Encoding.UTF8.GetBytes(input.ToLower()));
zos.CloseEntryAsync(CancellationToken.None).Wait();
zos.PutNextEntry(new ZipEntry("file2"){ CompressionMethod = CompressionMethod.Stored });
zos.Write(Encoding.UTF8.GetBytes(input.ToLower()));
zos.CloseEntryAsync(CancellationToken.None).Wait();
zos.PutNextEntry(new ZipEntry("file3"){ CompressionMethod = CompressionMethod.Stored });
zos.Write(Encoding.UTF8.GetBytes(input.ToLower()));
zos.CloseEntryAsync(CancellationToken.None).Wait();
ms.Seek(0, SeekOrigin.Begin);
Log($"Wrote {ms.Length} bytes!");
using (var zis = new ZipInputStream(ms){ IsStreamOwner = false }) {
var entry = zis.GetNextEntry();
Assert.That(entry, Is.Not.Null);
Assert.That(entry.Name, Is.EqualTo("file1"));
var output = new StreamReader(zis).ReadToEnd();
Assert.That(output, Is.EqualTo(input));
entry = zis.GetNextEntry();
Assert.That(entry, Is.Not.Null);
Assert.That(entry.Name, Is.EqualTo("file2"));
output = new StreamReader(zis).ReadToEnd();
Assert.That(output, Is.EqualTo(input));
entry = zis.GetNextEntry();
Assert.That(entry, Is.Not.Null);
Assert.That(entry.Name, Is.EqualTo("file3"));
output = new StreamReader(zis).ReadToEnd();
Assert.That(output, Is.EqualTo(input));
void Test<T>(Action<T> a, T input)
using var ctx = new TestExecutionContext.IsolatedContext();
Console.WriteLine($"Testing input \"{input}\"...\n");
Console.WriteLine("\n=> OK!");
Console.WriteLine($"\n=> Failed! ({x.GetType().Name})");
Console.WriteLine($"\n{x.Message}");
var trimmedStack = string.Join("\n", x.StackTrace.Split("\n").Where(l => !l.Contains("ReportFailure")));
Console.WriteLine($"{trimmedStack}");
Console.WriteLine($"\n{new string('=', 128)}\n");
void Log(string message) => Console.WriteLine($" {message}");