Files
Nemera/tests/UnitTests/Lumina.Contracts.UnitTests/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/BookMetadataDtoTests.cs
T
BinaryAlley 565fe68239 Adds independent metadata and artwork enrichment
Splits the single combined enrichment phase of the media library scan into
independent, modular jobs, so that the metadata and the artwork of a book
are enriched separately and only when their respective triggers fire.

- Adds the MediaContributorRoleCategory enum (Other first, then Author,
  Translator, Illustrator, Publisher and Narrator) and makes the role
  category canonical, so that roles describing the same kind of
  contribution are never treated as distinct.
- Realizes the media contributor bounded context: a MediaContributor is a
  person, unique by display name, without a role. The role moves to the
  per-work participation (BookContributors), so that a single contributor
  can play multiple roles. Contributors are created and linked by the
  metadata enrichment job, and exposed to subsequent jobs.
- Makes the Book aggregate pure: the enrichment tracking state (metadata
  status, providers, timestamps and covers) no longer lives on the domain
  aggregate, but stays in the Books table, managed directly by the jobs.
- Models artwork generically as a BookArtwork child table (type, ordinal,
  content hash, status and provider), so that each piece of artwork is
  tracked independently and a change of one does not require the others to
  be re-fetched.
- Splits the scan DAG into ResultsSave, ProviderConfigurationInvalidation,
  MetadataEnrichment and ArtworkEnrichment jobs. The invalidation job
  fingerprints the provider configuration of a library and resets the
  enrichment state of the affected channel when it changed. The artwork job
  resolves the missing artwork, hashing it to detect identical covers and
  skip re-copying. Content-changed books are reset by the results save job.
- Deletes the book and its stored artwork when the file disappears from the
  library.
- Adds the migration creating the new tables, backfilling the existing
  covers into the artwork table, and adding the configuration fingerprints.
- Localizes the new scan job stages, and fixes the invalidation job wiping
  the library content locations by persisting the fingerprints through the
  change tracker instead of the repository update action.
2026-08-27 14:41:49 +03:00

111 lines
3.4 KiB
C#

#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
#endregion
namespace Lumina.Contracts.UnitTests.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Contains unit tests for the <see cref="BookMetadataDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookMetadataDtoTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
[Fact]
public void RoundTrip_WhenSerializingFullyPopulatedMetadata_ShouldPreserveValues()
{
// Arrange
BookMetadataDto expected = new(
"Dune",
"Dune",
"A science fiction novel.",
new ReleaseInfoDto(new DateOnly(1965, 8, 1), 1965, null, null, "US", null),
[new GenreDto("Science Fiction")],
[new TagDto("classic")],
new LanguageInfoDto("en", "English", "English"),
null,
"Chilton Books",
412,
BookFormat.Hardcover,
"First Edition",
1,
new BookSeriesDto("Dune Chronicles"),
"B0006C7V9I",
"12345",
"68008446",
"ocm01234567",
"OL12345W",
"lccn123",
"abc123",
"1234567890",
"id12345",
[new IsbnDto("978-0-306-40615-7", IsbnFormat.Isbn13)],
[new MediaContributorDto(new MediaContributorNameDto("Frank Herbert", "Frank Herbert"), new MediaContributorRoleDto("Author", MediaContributorRoleCategory.Author))],
[new BookRatingDto(4.5m, 5m, BookRatingSource.Goodreads, 1000)],
"https://example.com/dune.jpg"
);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
BookMetadataDto? actual = JsonSerializer.Deserialize<BookMetadataDto>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equivalent(expected, actual);
}
[Fact]
public void Serialize_WhenSerializingMetadata_ShouldSerializeFormatAsCamelCaseString()
{
// Arrange
BookMetadataDto sut = new(
"Dune",
null,
null,
null,
null,
null,
null,
null,
null,
null,
BookFormat.Paperback,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
);
// Act
string json = JsonSerializer.Serialize(sut, _jsonOptions);
// Assert
Assert.Contains("\"Format\":\"paperback\"", json, StringComparison.Ordinal);
}
}