Refactored more archive code into the service and updated documentation now that methods are public.

This commit is contained in:
Joseph Milazzo 2021-01-26 10:03:06 -06:00
parent 6b76c8b211
commit 6621730afb
13 changed files with 137 additions and 125 deletions

View file

@ -1,6 +1,5 @@
using System.IO;
using System.IO.Compression;
using API.Extensions;
using API.Interfaces;
using API.Services;
using Microsoft.Extensions.Logging;
@ -14,9 +13,6 @@ namespace API.Tests.Services
private readonly IArchiveService _archiveService;
private readonly ILogger<ArchiveService> _logger = Substitute.For<ILogger<ArchiveService>>();
private readonly string _testDirectory =
Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService");
public ArchiveServiceTests()
{
_archiveService = new ArchiveService(_logger);
@ -29,9 +25,21 @@ namespace API.Tests.Services
[InlineData("file in folder_alt.zip", true)]
public void ArchiveNeedsFlatteningTest(string archivePath, bool expected)
{
var file = Path.Join(_testDirectory, archivePath);
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService");
var file = Path.Join(testDirectory, archivePath);
using ZipArchive archive = ZipFile.OpenRead(file);
Assert.Equal(expected, _archiveService.ArchiveNeedsFlattening(archive));
}
[Theory]
[InlineData("v10.cbz", "v10.expected.jpg")]
[InlineData("v10 - with folder.cbz", "v10 - with folder.expected.jpg")]
[InlineData("v10 - nested folder.cbz", "v10 - nested folder.expected.jpg")]
public void GetCoverImageTest(string inputFile, string expectedOutputFile)
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/CoverImageTests");
var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile));
Assert.Equal(expectedBytes, _archiveService.GetCoverImage(Path.Join(testDirectory, inputFile)));
}
}
}