mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-03 13:44:31 -04:00
* More cases for parsing regex * Fixed a bug where chapter cover images weren't being updated due to a missed not. * Removed a piece of code that was needed for upgrading, since all beta users agreed to wipe db. * Fixed InProgress to properly respect order and show more recent activity first. Issue is with IEntityDate LastModified not updating in DataContext. * Updated dependencies to lastest stable. * LastModified on Volumes wasn't updating, validated it does update when data is changed. * Rewrote a check to avoid a small heap object warning. * Ensure UpdateSeries checks all libraries for unique name. * Took care of some todos, removed unused imports, on dev go ahead and schedule reoocuring jobs since LiteDB caused the locking issue. * No Tracking when we aren't using entities. * Added code to remove abandoned progress rows after a chapter gets deleted. * RefreshMetadata uses one large query rather than many trips to DB for updating metadata. Significantly faster. * Fixed a bug where UpdateSeries would always complain about a unique name even when we weren't updating name. * Files that are linked to a series but can't parse out Vol/Chapter information are properly grouped like other Specials. * Refresh metadata on UI should call the task directly * Fixed a bug on updating series to make sure we don't complain if we aren't trying to update the name to an existing name. * Fixed #142 - Library cards should be sorted. * Refactored the name of some variables to be more agnostic to comics. * Implemented ScanLibrary but abandoning it. * Code Cleanup & removing ScanSeries code. * Some more tests and new Comparators for natural sorting. * Fixed #137 - When performing I/O on archives, ignore __MACOSX folders completely. * Fixed #137 - When performing I/O on archives, ignore __MACOSX folders completely. * All entities that will show under specials tab should be marked special, rather than just what has a special keyword. * Don't let specials generate cover images * Don't let specials generate cover images * SearchResults should send LocalizedName back since we are searching against it. * Added some tests around macosx folders found from my actual server. * Put extra notes about a case where duplicates come about, logger will now tell user about this issue. * Missed a build issue somehow... * Some code smells
154 lines
7.6 KiB
C#
154 lines
7.6 KiB
C#
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using API.Archive;
|
|
using API.Interfaces.Services;
|
|
using API.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace API.Tests.Services
|
|
{
|
|
public class ArchiveServiceTests
|
|
{
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
private readonly IArchiveService _archiveService;
|
|
private readonly ILogger<ArchiveService> _logger = Substitute.For<ILogger<ArchiveService>>();
|
|
|
|
public ArchiveServiceTests(ITestOutputHelper testOutputHelper)
|
|
{
|
|
_testOutputHelper = testOutputHelper;
|
|
_archiveService = new ArchiveService(_logger);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("flat file.zip", false)]
|
|
[InlineData("file in folder in folder.zip", true)]
|
|
[InlineData("file in folder.zip", true)]
|
|
[InlineData("file in folder_alt.zip", true)]
|
|
public void ArchiveNeedsFlatteningTest(string archivePath, bool expected)
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
|
|
var file = Path.Join(testDirectory, archivePath);
|
|
using ZipArchive archive = ZipFile.OpenRead(file);
|
|
Assert.Equal(expected, _archiveService.ArchiveNeedsFlattening(archive));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("non existent file.zip", false)]
|
|
[InlineData("winrar.rar", true)]
|
|
[InlineData("empty.zip", true)]
|
|
[InlineData("flat file.zip", true)]
|
|
[InlineData("file in folder in folder.zip", true)]
|
|
[InlineData("file in folder.zip", true)]
|
|
[InlineData("file in folder_alt.zip", true)]
|
|
public void IsValidArchiveTest(string archivePath, bool expected)
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
|
|
Assert.Equal(expected, _archiveService.IsValidArchive(Path.Join(testDirectory, archivePath)));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("non existent file.zip", 0)]
|
|
[InlineData("winrar.rar", 0)]
|
|
[InlineData("empty.zip", 0)]
|
|
[InlineData("flat file.zip", 1)]
|
|
[InlineData("file in folder in folder.zip", 1)]
|
|
[InlineData("file in folder.zip", 1)]
|
|
[InlineData("file in folder_alt.zip", 1)]
|
|
[InlineData("macos_none.zip", 0)]
|
|
[InlineData("macos_one.zip", 1)]
|
|
[InlineData("macos_native.zip", 21)]
|
|
public void GetNumberOfPagesFromArchiveTest(string archivePath, int expected)
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
|
|
var sw = Stopwatch.StartNew();
|
|
Assert.Equal(expected, _archiveService.GetNumberOfPagesFromArchive(Path.Join(testDirectory, archivePath)));
|
|
_testOutputHelper.WriteLine($"Processed Original in {sw.ElapsedMilliseconds} ms");
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
[InlineData("non existent file.zip", ArchiveLibrary.NotSupported)]
|
|
[InlineData("winrar.rar", ArchiveLibrary.SharpCompress)]
|
|
[InlineData("empty.zip", ArchiveLibrary.Default)]
|
|
[InlineData("flat file.zip", ArchiveLibrary.Default)]
|
|
[InlineData("file in folder in folder.zip", ArchiveLibrary.Default)]
|
|
[InlineData("file in folder.zip", ArchiveLibrary.Default)]
|
|
[InlineData("file in folder_alt.zip", ArchiveLibrary.Default)]
|
|
public void CanOpenArchive(string archivePath, ArchiveLibrary expected)
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
|
|
|
|
Assert.Equal(expected, _archiveService.CanOpen(Path.Join(testDirectory, archivePath)));
|
|
_testOutputHelper.WriteLine($"Processed Original in {sw.ElapsedMilliseconds} ms");
|
|
}
|
|
|
|
|
|
[Theory]
|
|
[InlineData("non existent file.zip", 0)]
|
|
[InlineData("winrar.rar", 0)]
|
|
[InlineData("empty.zip", 0)]
|
|
[InlineData("flat file.zip", 1)]
|
|
[InlineData("file in folder in folder.zip", 1)]
|
|
[InlineData("file in folder.zip", 1)]
|
|
[InlineData("file in folder_alt.zip", 1)]
|
|
public void CanExtractArchive(string archivePath, int expectedFileCount)
|
|
{
|
|
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
|
|
var extractDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives/Extraction");
|
|
|
|
DirectoryService.ClearAndDeleteDirectory(extractDirectory);
|
|
|
|
Stopwatch sw = Stopwatch.StartNew();
|
|
_archiveService.ExtractArchive(Path.Join(testDirectory, archivePath), extractDirectory);
|
|
var di1 = new DirectoryInfo(extractDirectory);
|
|
Assert.Equal(expectedFileCount, di1.Exists ? di1.GetFiles().Length : 0);
|
|
_testOutputHelper.WriteLine($"Processed in {sw.ElapsedMilliseconds} ms");
|
|
|
|
DirectoryService.ClearAndDeleteDirectory(extractDirectory);
|
|
}
|
|
|
|
|
|
|
|
[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")]
|
|
//[InlineData("png.zip", "png.PNG")]
|
|
[InlineData("macos_native.zip", "macos_native.jpg")]
|
|
public void GetCoverImageTest(string inputFile, string expectedOutputFile)
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/CoverImages");
|
|
var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile));
|
|
Stopwatch sw = Stopwatch.StartNew();
|
|
Assert.Equal(expectedBytes, _archiveService.GetCoverImage(Path.Join(testDirectory, inputFile)));
|
|
_testOutputHelper.WriteLine($"Processed in {sw.ElapsedMilliseconds} ms");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Archives/macos_native.zip")]
|
|
[InlineData("Formats/One File with DB_Supported.zip")]
|
|
public void CanParseCoverImage(string inputFile)
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/");
|
|
Assert.NotEmpty(_archiveService.GetCoverImage(Path.Join(testDirectory, inputFile)));
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldHaveComicInfo()
|
|
{
|
|
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos");
|
|
var archive = Path.Join(testDirectory, "file in folder.zip");
|
|
var summaryInfo = "By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?";
|
|
|
|
Assert.Equal(summaryInfo, _archiveService.GetSummaryInfo(archive));
|
|
|
|
}
|
|
}
|
|
} |