wabbajack/Wabbajack.FileExtractor.Test/ExtractorTests.cs
2021-09-27 06:42:46 -06:00

57 lines
2.0 KiB
C#

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Xunit;
namespace Wabbajack.FileExtractor.Test
{
public class ExtractorTests
{
private readonly FileExtractor _extractor;
private readonly TemporaryFileManager _manager;
private readonly IResource<FileExtractor> _limiter;
public ExtractorTests(FileExtractor extractor, TemporaryFileManager manager, IResource<FileExtractor> limiter)
{
_extractor = extractor;
_manager = manager;
_limiter = limiter;
}
[Fact]
public async Task CanExtract7z()
{
var src = KnownFolders.EntryPoint.Combine("TestData", "cheese.7z");
using var job = await _limiter.Begin("Extracting files", 0, CancellationToken.None);
var results = await _extractor.GatheringExtractWith7Zip(
new NativeFileStreamFactory(src), path => true,
async (path, file) =>
{
await using var s = await file.GetStream();
using var sr = new StreamReader(s);
return new { Path = path, Data = await sr.ReadToEndAsync() };
}, null, job, CancellationToken.None);
Assert.True(results.Count == 1);
}
[Fact]
public async Task CanExtractWithGatheringExtract()
{
var src = KnownFolders.EntryPoint.Combine("TestData", "cheese.7z");
var results = await _extractor.GatheringExtract(
new NativeFileStreamFactory(src), path => true,
async (path, file) =>
{
await using var s = await file.GetStream();
using var sr = new StreamReader(s);
return new { Path = path, Data = await sr.ReadToEndAsync() };
}, CancellationToken.None);
Assert.True(results.Count == 1);
}
}
}