mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-05 22:54:13 -04:00
* Refactored all files to have Interfaces within the same file. Started moving over to file-scoped namespaces. * Refactored common methods for getting underlying file's cover, pages, and extracting into 1 interface. * More refactoring around removing dependence on explicit filetype testing for getting information. * Code is buildable, tests are broken. Huge refactor (not completed) which makes most of DirectoryService testable with a mock filesystem (and thus the services that utilize it). * Finished porting DirectoryService to use mocked filesystem implementation. * Added a null check * Added a null check * Finished all unit tests for DirectoryService. * Some misc cleanup on the code * Fixed up some bugs from refactoring scan loop. * Implemented CleanupService testing and refactored more of DirectoryService to be non-static. Fixed a bug where cover file cleanup wasn't properly finding files due to a regex bug. * Fixed an issue in CleanupBackup() where we weren't properly selecting database files older than 30 days. Finished CleanupService Tests. * Refactored Flatten and RemoveNonImages to directory service to allow CacheService to be testable. * Finally have CacheService tested. Rewrote GetCachedPagePath() to be much more straightforward & performant. * Updated DefaultParserTests.cs to contain all existing tests and follow new test layout format. * All tests fixed up
54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO.Abstractions.TestingHelpers;
|
|
using System.Linq;
|
|
using API.Entities.Enums;
|
|
using API.Extensions;
|
|
using API.Parser;
|
|
using API.Services;
|
|
using API.Tests.Helpers;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Extensions
|
|
{
|
|
public class ParserInfoListExtensions
|
|
{
|
|
private readonly DefaultParser _defaultParser;
|
|
public ParserInfoListExtensions()
|
|
{
|
|
_defaultParser =
|
|
new DefaultParser(new DirectoryService(Substitute.For<ILogger<DirectoryService>>(),
|
|
new MockFileSystem()));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(new[] {"1", "1", "3-5", "5", "8", "0", "0"}, new[] {"1", "3-5", "5", "8", "0"})]
|
|
public void DistinctVolumesTest(string[] volumeNumbers, string[] expectedNumbers)
|
|
{
|
|
var infos = volumeNumbers.Select(n => new ParserInfo() {Volumes = n}).ToList();
|
|
Assert.Equal(expectedNumbers, infos.DistinctVolumes());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(new[] {@"Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, new[] {@"E:\Manga\Cynthia the Mission\Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, true)]
|
|
[InlineData(new[] {@"Cynthia The Mission - c000-006 (v06-07) [Desudesu&Brolen].zip"}, new[] {@"E:\Manga\Cynthia the Mission\Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, true)]
|
|
[InlineData(new[] {@"Cynthia The Mission v20 c12-20 [Desudesu&Brolen].zip"}, new[] {@"E:\Manga\Cynthia the Mission\Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, false)]
|
|
public void HasInfoTest(string[] inputInfos, string[] inputChapters, bool expectedHasInfo)
|
|
{
|
|
var infos = new List<ParserInfo>();
|
|
foreach (var filename in inputInfos)
|
|
{
|
|
infos.Add(_defaultParser.Parse(
|
|
filename,
|
|
string.Empty));
|
|
}
|
|
|
|
var files = inputChapters.Select(s => EntityFactory.CreateMangaFile(s, MangaFormat.Archive, 199)).ToList();
|
|
var chapter = EntityFactory.CreateChapter("0-6", false, files);
|
|
|
|
Assert.Equal(expectedHasInfo, infos.HasInfo(chapter));
|
|
}
|
|
}
|
|
}
|