mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 15:30:34 -04:00
* Recreated Kavita Logging with Serilog instead of Default. This needs to be move out of the appsettings now, to allow auto updater to patch. * Refactored the code to be completely configured via Code rather than appsettings.json. This is a required step for Auto Updating. * Added in the ability to send logs directly to the UI only for users on the log route. Stopping implementation as Alerts page will handle the rest of the implementation. * Fixed up the backup service to not rely on Config from appsettings.json * Tweaked the Logging levels available * Moved everything over to File-scoped namespaces * Moved everything over to File-scoped namespaces * Code cleanup, removed an old migration and changed so debug logging doesn't print sensitive db data * Removed dead code
58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
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);
|
||
}
|
||
|
||
}
|