Kavita/API.Tests/Services/BookServiceTests.cs
Joe Milazzo 3f51cb2a02
v0.6.1 Hotfix RC (#1635)
* Swapped out SQLite for Memory, but the one from hangfire. Added DisableConcurrentExecution on ProcessChange to avoid duplication when multiple threads execute at once.

* Fixed the Hangfire SQL issues with CPU/ram utilization some users are facing

* Fixed a case in SharpCompress fallback where an invalid ComicInfo wasn't picked up.

* When parsing epubs, if there is a volume in the epub title, try to parse and group. This is beneficial for Light Novels which are generally tagged this way.

* Fixed delete series in series detail not triggering

* Fixed some parsing logic for how we treat specials, like Annual and Omnibus.

* When scanning files, if the file is the cover image (loose leaf image), we reject it more quickly than previously.

* Added a potential bug marker

* Fixed a bug where Info was only showing Error level loggers

* Code smells
2022-11-05 06:56:48 -07:00

82 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using System.IO.Abstractions;
using API.Services;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Xunit;
namespace API.Tests.Services;
public class BookServiceTests
{
private readonly IBookService _bookService;
private readonly ILogger<BookService> _logger = Substitute.For<ILogger<BookService>>();
public BookServiceTests()
{
var directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem());
_bookService = new BookService(_logger, directoryService, new ImageService(Substitute.For<ILogger<ImageService>>(), directoryService));
}
[Theory]
[InlineData("The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub", 16)]
[InlineData("Non-existent file.epub", 0)]
[InlineData("Non an ebub.pdf", 0)]
[InlineData("test_ſ.pdf", 1)] // This is dependent on Docnet bug https://github.com/GowenGit/docnet/issues/80
[InlineData("test.pdf", 1)]
public void GetNumberOfPagesTest(string filePath, int expectedPages)
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");
Assert.Equal(expectedPages, _bookService.GetNumberOfPages(Path.Join(testDirectory, filePath)));
}
[Fact]
public void ShouldHaveComicInfo()
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");
var archive = Path.Join(testDirectory, "The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub");
const string summaryInfo = "Book Description";
var comicInfo = _bookService.GetComicInfo(archive);
Assert.NotNull(comicInfo);
Assert.Equal(summaryInfo, comicInfo.Summary);
Assert.Equal("genre1, genre2", comicInfo.Genre);
}
[Fact]
public void ShouldHaveComicInfo_WithAuthors()
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");
var archive = Path.Join(testDirectory, "The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub");
var comicInfo = _bookService.GetComicInfo(archive);
Assert.NotNull(comicInfo);
Assert.Equal("Roger Starbuck,Junya Inoue", comicInfo.Writer);
}
[Fact]
public void ShouldParseAsVolumeGroup_WithoutSeriesIndex()
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");
var archive = Path.Join(testDirectory, "TitleWithVolume_NoSeriesOrSeriesIndex.epub");
var comicInfo = _bookService.GetComicInfo(archive);
Assert.NotNull(comicInfo);
Assert.Equal("1", comicInfo.Volume);
Assert.Equal("Accel World", comicInfo.Series);
}
[Fact]
public void ShouldParseAsVolumeGroup_WithSeriesIndex()
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");
var archive = Path.Join(testDirectory, "TitleWithVolume.epub");
var comicInfo = _bookService.GetComicInfo(archive);
Assert.NotNull(comicInfo);
Assert.Equal("1.0", comicInfo.Volume);
Assert.Equal("Accel World", comicInfo.Series);
}
}