mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-14 21:23:38 +00:00
Tests fail in Visual Studio because they try to reuse the same scratch working space, and each test is responsible for resetting the space. To simplify the test code: 1. Make `TestBase` `IDisposable` and have it create the scratch space 2. Remove `ResetScratch()` as it is now handled by the base class 3. Add a unique ID to each scrach space folder to prevent collisions
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using SharpCompress.Common;
|
|
using SharpCompress.IO;
|
|
using SharpCompress.Readers;
|
|
using SharpCompress.Writers;
|
|
|
|
namespace SharpCompress.Test
|
|
{
|
|
public class WriterTests : TestBase
|
|
{
|
|
private readonly ArchiveType type;
|
|
|
|
protected WriterTests(ArchiveType type)
|
|
{
|
|
this.type = type;
|
|
}
|
|
|
|
protected void Write(CompressionType compressionType, string archive, string archiveToVerifyAgainst)
|
|
{
|
|
using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) {
|
|
WriterOptions writerOptions = new WriterOptions(compressionType)
|
|
{
|
|
LeaveStreamOpen = true,
|
|
};
|
|
|
|
writerOptions.ArchiveEncoding.Default = Encoding.GetEncoding(866);
|
|
|
|
using (var writer = WriterFactory.Open(stream, type, writerOptions))
|
|
{
|
|
writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);
|
|
}
|
|
}
|
|
CompareArchivesByPath(Path.Combine(SCRATCH2_FILES_PATH, archive),
|
|
Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst));
|
|
|
|
using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive)))
|
|
{
|
|
ReaderOptions readerOptions = new ReaderOptions();
|
|
|
|
readerOptions.ArchiveEncoding.Default = Encoding.GetEncoding(866);
|
|
|
|
using (var reader = ReaderFactory.Open(new NonDisposingStream(stream), readerOptions))
|
|
{
|
|
reader.WriteAllToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions()
|
|
{
|
|
ExtractFullPath = true
|
|
});
|
|
}
|
|
}
|
|
VerifyFiles();
|
|
}
|
|
}
|
|
}
|