2021-09-27 12:42:46 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Wabbajack.Common;
|
|
|
|
using Wabbajack.Paths.IO;
|
|
|
|
using Wabbajack.RateLimiter;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.FileExtractor.Test;
|
|
|
|
|
|
|
|
public class ExtractorTests
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
private readonly FileExtractor _extractor;
|
|
|
|
private readonly IResource<FileExtractor> _limiter;
|
|
|
|
private readonly TemporaryFileManager _manager;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public ExtractorTests(FileExtractor extractor, TemporaryFileManager manager, IResource<FileExtractor> limiter)
|
|
|
|
{
|
|
|
|
_extractor = extractor;
|
|
|
|
_manager = manager;
|
|
|
|
_limiter = limiter;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public async Task CanExtract7z()
|
|
|
|
{
|
|
|
|
var src = KnownFolders.EntryPoint.Combine("TestData", "cheese.7z");
|
|
|
|
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()};
|
2021-10-23 22:38:55 +00:00
|
|
|
}, null, CancellationToken.None);
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.True(results.Count == 1);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[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);
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.True(results.Count == 1);
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|