Files
sharpcompress/tests/SharpCompress.Test/ReaderTests.cs
Matt Kotsenas 7b338511cc Create unique scratch path per test
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
2018-07-10 11:46:44 -07:00

52 lines
1.8 KiB
C#

using System.Collections.Generic;
using System.IO;
using SharpCompress.Common;
using SharpCompress.IO;
using SharpCompress.Readers;
using Xunit;
namespace SharpCompress.Test
{
public class ReaderTests : TestBase
{
protected void Read(string testArchive, CompressionType expectedCompression)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
Read(testArchive.AsEnumerable(), expectedCompression);
}
protected void Read(IEnumerable<string> testArchives, CompressionType expectedCompression)
{
foreach (var path in testArchives)
{
using (var stream = new NonDisposingStream(new ForwardOnlyStream(File.OpenRead(path)), true))
using (var reader = ReaderFactory.Open(stream, new ReaderOptions()
{
LeaveStreamOpen = true
}))
{
UseReader(this, reader, expectedCompression);
stream.ThrowOnDispose = false;
}
}
}
public static void UseReader(TestBase test, IReader reader, CompressionType expectedCompression)
{
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
Assert.Equal(reader.Entry.CompressionType, expectedCompression);
reader.WriteEntryToDirectory(test.SCRATCH_FILES_PATH, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
test.VerifyFiles();
}
}
}