Hardens test assertions and adds missing test coverage.

This commit is contained in:
BinaryAlley committed 2026-08-18 08:28:16 -07:00
1 parent 6b86fd5805
commit 1189bbaf36
489 files changed
+39982 -512

No files matched your search

@@ -5,9 +5,9 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -21,24 +21,23 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
[ExcludeFromCodeCoverage]
public class LibraryMappingTests
{
private readonly LibraryFixture _libraryFixture = new();
[Fact]
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
{
// Arrange
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
["C:/Books", "D:/Media/Books"],
"D:/myPoster.jpg",
true,
false,
true,
false,
false,
[ScanId.CreateUnique()]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books", "D:/Media/Books"],
coverImage: "D:/myPoster.jpg",
isEnabled: true,
isLocked: false,
downloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
scanIds: [Guid.NewGuid()]);
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -64,20 +63,11 @@ public class LibraryMappingTests
public void ToRepositoryEntity_WhenMappingLibraryWithEmptyContentLocations_ShouldMapCorrectly()
{
// Arrange
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Empty Library",
LibraryType.Book,
[],
"D:/myPoster.jpg",
true,
false,
true,
false,
false,
[ScanId.CreateUnique()]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Empty Library",
libraryType: LibraryType.Book,
contentLocations: [],
coverImage: "D:/myPoster.jpg");
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -96,20 +86,15 @@ public class LibraryMappingTests
public void ToRepositoryEntity_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
libraryType,
["C:/Media"],
"D:/myPoster.jpg",
true,
false,
true,
false,
false,
[ScanId.CreateUnique()]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: libraryType,
contentLocations: ["C:/Media"],
coverImage: "D:/myPoster.jpg",
isEnabled: true,
isLocked: false,
downloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false);
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -136,20 +121,11 @@ public class LibraryMappingTests
"F:/Reading Material"
];
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
contentLocations,
"D:/myPoster.jpg",
true,
false,
true,
false,
false,
[ScanId.CreateUnique()]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
coverImage: "D:/myPoster.jpg");
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -170,20 +146,11 @@ public class LibraryMappingTests
"D:/Books"
];
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
contentLocations,
null,
true,
false,
true,
false,
false,
[ScanId.CreateUnique()]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
includeCoverImage: false);
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -204,20 +171,12 @@ public class LibraryMappingTests
"D:/Books"
];
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
contentLocations,
null,
true,
false,
true,
false,
false,
[]
);
Library library = libraryResult.Value;
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
includeCoverImage: false,
scanIds: []);
// Act
LibraryEntity result = library.ToRepositoryEntity();
@@ -2,6 +2,7 @@
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
@@ -19,13 +20,20 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenConten
public class BookMetadataDtoMappingTests
{
private readonly BookFixture _bookFixture = new();
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
[Fact]
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItAndMarkTheBookAsEnriched()
{
// Arrange
Book book = _bookFixture.Create();
BookMetadataDto metadata = CreateBookMetadata("The Fellowship of the Ring", "3");
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
title: "The Fellowship of the Ring",
description: "The first part of J.R.R. Tolkien's epic adventure.",
goodreadsId: "3",
format: BookFormat.Paperback,
publisher: "Houghton Mifflin",
pageCount: 398);
// Act
Result<Success> result = book.ApplyMetadata(metadata, "Goodreads", DateTime.UtcNow);
@@ -47,7 +55,9 @@ public class BookMetadataDtoMappingTests
{
// Arrange
Book book = _bookFixture.Create();
BookMetadataDto metadata = CreateBookMetadata("The Fellowship of the Ring", "3") with
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
title: "The Fellowship of the Ring",
goodreadsId: "3") with
{
Genres = [new GenreDto("")]
};
@@ -59,44 +69,4 @@ public class BookMetadataDtoMappingTests
Assert.True(result.IsFailure);
Assert.Equal(MetadataStatus.Pending, book.MetadataStatus);
}
private static BookMetadataDto CreateBookMetadata(string title, string goodreadsId)
{
return new BookMetadataDto(
Title: title,
OriginalTitle: title,
Description: "The first part of J.R.R. Tolkien's epic adventure.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1954, 7, 29),
OriginalReleaseYear: 1954,
ReReleaseDate: null,
ReReleaseYear: null,
ReleaseCountry: "uk",
ReleaseVersion: null
),
Genres: [new GenreDto("fantasy")],
Tags: [new TagDto("epic fantasy")],
Language: new LanguageInfoDto("en", "English", "English"),
OriginalLanguage: null,
Publisher: "Houghton Mifflin",
PageCount: 398,
Format: BookFormat.Paperback,
Edition: null,
VolumeNumber: 1,
Series: null,
ASIN: null,
GoodreadsId: goodreadsId,
LCCN: null,
OCLCNumber: null,
OpenLibraryId: null,
LibraryThingId: null,
GoogleBooksId: null,
BarnesAndNobleId: null,
AppleBooksId: null,
Isbns: null,
Contributors: null,
Ratings: null,
CoverImageUrl: null
);
}
}
@@ -24,7 +24,7 @@ public class IsbnMappingTests
public void ToRepositoryEntity_WhenMappingIsbn10_ShouldMapCorrectly()
{
// Arrange
Isbn isbn = _isbnFixture.Create(IsbnFormat.Isbn10);
Isbn isbn = _isbnFixture.Create(format: IsbnFormat.Isbn10);
// Act
IsbnEntity result = isbn.ToRepositoryEntity();
@@ -39,7 +39,7 @@ public class IsbnMappingTests
public void ToRepositoryEntity_WhenMappingIsbn13_ShouldMapCorrectly()
{
// Arrange
Isbn isbn = _isbnFixture.Create(IsbnFormat.Isbn13);
Isbn isbn = _isbnFixture.Create(format: IsbnFormat.Isbn13);
// Act
IsbnEntity result = isbn.ToRepositoryEntity();
@@ -56,9 +56,9 @@ public class IsbnMappingTests
// Arrange
List<Isbn> isbns =
[
_isbnFixture.Create(IsbnFormat.Isbn10),
_isbnFixture.Create(IsbnFormat.Isbn13),
_isbnFixture.Create(IsbnFormat.Isbn10)
_isbnFixture.Create(format: IsbnFormat.Isbn10),
_isbnFixture.Create(format: IsbnFormat.Isbn13),
_isbnFixture.Create(format: IsbnFormat.Isbn10)
];
// Act