naps2/NAPS2.Lib.Tests/Dependencies/DownloadFormatTests.cs
Fabian Neundorf 758e1f2e01 DownloadController uses HttpClient instead of WebClient
This can use Task and download into a Stream. Thus DownloadFormat is now
accepting a Stream and canceling a download (before extraction) does not
require it to remove the temporary file.
2023-06-25 22:55:40 +02:00

44 lines
1.3 KiB
C#

using NAPS2.Dependencies;
using NAPS2.Sdk.Tests;
using Xunit;
namespace NAPS2.Lib.Tests.Dependencies;
public class DownloadFormatTests : ContextualTests
{
[Fact]
public void Gzip()
{
var path = Path.Combine(FolderPath, "f.gz");
string extractedPath;
using (MemoryStream stream = new(BinaryResources.stock_dog_jpeg))
{
extractedPath = DownloadFormat.Gzip.Prepare(stream, path);
}
var expectedDog = BinaryResources.stock_dog;
Assert.Equal(expectedDog, File.ReadAllBytes(extractedPath));
}
[Fact]
public void Zip()
{
var path = Path.Combine(FolderPath, "f.zip");
string extractedPath;
using (MemoryStream stream = new(BinaryResources.animals))
{
extractedPath = DownloadFormat.Zip.Prepare(stream, path);
}
var dogPath = Path.Combine(extractedPath, "animals/dogs/stock-dog.jpeg");
var catPath = Path.Combine(extractedPath, "animals/cats/stock-cat.jpeg");
Assert.True(File.Exists(dogPath));
Assert.True(File.Exists(catPath));
var expectedDog = BinaryResources.stock_dog;
var expectedCat = BinaryResources.stock_cat;
Assert.Equal(expectedDog, File.ReadAllBytes(dogPath));
Assert.Equal(expectedCat, File.ReadAllBytes(catPath));
}
}