mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Refactors the add book slice and shared media contributor model across the stack
This commit is contained in:
1 parent
3a2c80b615
commit
9a71a6d32b
61 files changed
+5223
-1384
No files matched your search
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddBookCommandMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookCommandMappingTests
|
||||
{
|
||||
private readonly AddBookCommandFixture _commandBookFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteCommand_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookCommand command = _commandBookFixture.Create(libraryId: libraryId.ToString());
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId.Value);
|
||||
Assert.Equal(command.Path, result.Value.Path);
|
||||
Assert.Equal(command.Metadata!.Title, result.Value.Metadata.Title);
|
||||
Assert.Equal(command.Metadata.ReleaseInfo!.OriginalReleaseYear, result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
Assert.Equal(command.Metadata.Genres!.Count, result.Value.Metadata.Genres.Count);
|
||||
Assert.Equal(command.Metadata.Tags!.Count, result.Value.Metadata.Tags.Count);
|
||||
Assert.Equal(command.ISBNs!.Count, result.Value.ISBNs.Count);
|
||||
Assert.Equal(command.Contributors!.Count, result.Value.Contributors.Count);
|
||||
Assert.Equal(command.Ratings!.Count, result.Value.Ratings.Count);
|
||||
Assert.True(result.Value.Format.HasValue);
|
||||
Assert.Equal(command.Format, result.Value.Format.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapRequiredPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookCommand command = _commandBookFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
isbns: [],
|
||||
contributors: [],
|
||||
ratings: [],
|
||||
includeOptionalProperties: false);
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId.Value);
|
||||
Assert.Equal(command.Path, result.Value.Path);
|
||||
Assert.Empty(result.Value.ISBNs);
|
||||
Assert.Empty(result.Value.Contributors);
|
||||
Assert.Empty(result.Value.Ratings);
|
||||
Assert.False(result.Value.Format.HasValue);
|
||||
Assert.False(result.Value.Edition.HasValue);
|
||||
Assert.False(result.Value.VolumeNumber.HasValue);
|
||||
Assert.False(result.Value.ASIN.HasValue);
|
||||
Assert.False(result.Value.GoodreadsId.HasValue);
|
||||
Assert.False(result.Value.LCCN.HasValue);
|
||||
Assert.False(result.Value.OCLCNumber.HasValue);
|
||||
Assert.False(result.Value.OpenLibraryId.HasValue);
|
||||
Assert.False(result.Value.LibraryThingId.HasValue);
|
||||
Assert.False(result.Value.GoogleBooksId.HasValue);
|
||||
Assert.False(result.Value.BarnesAndNobleId.HasValue);
|
||||
Assert.False(result.Value.AppleBooksId.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenRatingCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand command = _commandBookFixture.Create(ratings: [_bookRatingDtoFixture.Create(value: -1, maxValue: 5, includeOptionalProperties: false)]);
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.Metadata.RatingValueMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenIsbnCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand command = _commandBookFixture.Create(isbns: [_isbnDtoFixture.Create(value: "invalid", format: IsbnFormat.Isbn13)]);
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMetadataCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand command = _commandBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: "")]));
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+11
-12
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
@@ -21,20 +21,22 @@ public class AddBookRequestMappingTests
|
||||
{
|
||||
private readonly AddBookRequestFixture _requestFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
private readonly MediaContributorRoleDtoFixture _mediaContributorRoleDtoFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _requestFixture.Create();
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
AddBookCommand result = request.ToCommand(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId.ToString(), result.LibraryId);
|
||||
Assert.Equal(request.Path, result.Path);
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Equal(request.Format, result.Format);
|
||||
Assert.Equal(request.Edition, result.Edition);
|
||||
@@ -58,15 +60,15 @@ public class AddBookRequestMappingTests
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _requestFixture.Create(
|
||||
libraryId: Guid.NewGuid(),
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
includeOptionalProperties: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
AddBookCommand result = request.ToCommand(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
@@ -93,24 +95,21 @@ public class AddBookRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _requestFixture.Create(
|
||||
libraryId: Guid.NewGuid(),
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
isbns: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
contributors:
|
||||
[
|
||||
new(
|
||||
_mediaContributorNameDtoFixture.Create(displayName: "John Doe", legalName: "John Smith Doe"),
|
||||
_mediaContributorRoleDtoFixture.Create(name: "Author", category: MediaContributorRoleCategory.Author)
|
||||
)
|
||||
_mediaContributorReferenceDtoFixture.Create(role: MediaContributorRole.Author)
|
||||
],
|
||||
ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)],
|
||||
includeOptionalProperties: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
AddBookCommand result = request.ToCommand(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
|
||||
-32
@@ -134,38 +134,6 @@ public class BookMetadataDtoMappingTests
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenLanguageIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
language: new LanguageInfoDto("", "English", "English"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenOriginalLanguageIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
originalLanguage: new LanguageInfoDto("", "English", "English"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenIsbnIsInvalid_ShouldReturnError()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user