mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Relocates real-resource tests into integration projects and improves data access unit tests
This commit is contained in:
1 parent
551259ad81
commit
042c5e4729
56 files changed
+5642
-4136
No files matched your search
@@ -1,15 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.Epub.Core;
|
||||
using Lumina.Plugins.Epub.Fixtures.Core.Epub;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Epub.UnitTests.Core;
|
||||
@@ -18,71 +11,27 @@ namespace Lumina.Plugins.Epub.UnitTests.Core;
|
||||
/// Contains unit tests for the <see cref="EpubReader"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EpubReaderTests : IDisposable
|
||||
public class EpubReaderTests
|
||||
{
|
||||
private readonly string _temporaryDirectory = Path.Combine(Path.GetTempPath(), $"lumina-epub-reader-{Guid.NewGuid():N}");
|
||||
private readonly string _epubPath;
|
||||
private readonly EpubReader _sut = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EpubReaderTests"/> class.
|
||||
/// </summary>
|
||||
public EpubReaderTests()
|
||||
{
|
||||
Directory.CreateDirectory(_temporaryDirectory);
|
||||
_epubPath = Path.Combine(_temporaryDirectory, "minimal.epub");
|
||||
TestEpubFileFactory.CreateMinimalEpub(_epubPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportedExtensions_WhenAccessed_ShouldOnlyContainEpub()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<string> result = _sut.SupportedExtensions;
|
||||
|
||||
// Assert
|
||||
Assert.Equal([".epub"], _sut.SupportedExtensions);
|
||||
Assert.Equal([".epub"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryTypes_WhenAccessed_ShouldContainEBookAndBook()
|
||||
{
|
||||
// Assert
|
||||
Assert.Equal([LibraryType.EBook, LibraryType.Book], _sut.SupportedLibraryTypes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OpenAsync_WhenCalled_ShouldReturnTheParsedDocument()
|
||||
{
|
||||
// Arrange
|
||||
string workingDirectory = Path.Combine(_temporaryDirectory, "work");
|
||||
|
||||
// Act
|
||||
ReadingDocumentDto result = await _sut.OpenAsync(_epubPath, workingDirectory, shouldRenderPdfAsImages: false, CancellationToken.None);
|
||||
IReadOnlyList<LibraryType> result = _sut.SupportedLibraryTypes;
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Minimal EPUB Book", result.Title);
|
||||
Assert.Equal(2, result.Spine.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetResourceAsync_WhenResourceWasExtracted_ShouldReturnItsBytes()
|
||||
{
|
||||
// Arrange
|
||||
string workingDirectory = Path.Combine(_temporaryDirectory, "work");
|
||||
ReadingDocumentDto document = await _sut.OpenAsync(_epubPath, workingDirectory, shouldRenderPdfAsImages: false, CancellationToken.None);
|
||||
string resourceKey = document.Resources.Keys.Single();
|
||||
|
||||
// Act
|
||||
byte[] result = await _sut.GetResourceAsync(_epubPath, workingDirectory, resourceKey, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotEmpty(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_temporaryDirectory))
|
||||
Directory.Delete(_temporaryDirectory, recursive: true);
|
||||
Assert.Equal([LibraryType.EBook, LibraryType.Book], result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user