mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 14:01:11 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+143
@@ -0,0 +1,143 @@
|
||||
#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 _addBookCommandFixture = 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 = _addBookCommandFixture.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 = _addBookCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
isbns: [],
|
||||
contributors: [],
|
||||
ratings: [],
|
||||
includeFormat: false,
|
||||
includeEdition: false,
|
||||
includeVolumeNumber: false,
|
||||
includeAsin: false,
|
||||
includeGoodreadsId: false,
|
||||
includeLccn: false,
|
||||
includeOclcNumber: false,
|
||||
includeOpenLibraryId: false,
|
||||
includeLibraryThingId: false,
|
||||
includeGoogleBooksId: false,
|
||||
includeBarnesAndNobleId: false,
|
||||
includeAppleBooksId: 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 = _addBookCommandFixture.Create(ratings: [_bookRatingDtoFixture.Create(value: -1, maxValue: 5, includeSource: false, includeVoteCount: 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 = _addBookCommandFixture.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 = _addBookCommandFixture.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);
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
#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;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
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="AddBookRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestMappingTests
|
||||
{
|
||||
private readonly AddBookRequestFixture _addBookRequestFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _addBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
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);
|
||||
Assert.Equal(request.VolumeNumber, result.VolumeNumber);
|
||||
Assert.Equal(request.Series, result.Series);
|
||||
Assert.Equal(request.ASIN, result.ASIN);
|
||||
Assert.Equal(request.GoodreadsId, result.GoodreadsId);
|
||||
Assert.Equal(request.LCCN, result.LCCN);
|
||||
Assert.Equal(request.OCLCNumber, result.OCLCNumber);
|
||||
Assert.Equal(request.OpenLibraryId, result.OpenLibraryId);
|
||||
Assert.Equal(request.LibraryThingId, result.LibraryThingId);
|
||||
Assert.Equal(request.GoogleBooksId, result.GoogleBooksId);
|
||||
Assert.Equal(request.BarnesAndNobleId, result.BarnesAndNobleId);
|
||||
Assert.Equal(request.AppleBooksId, result.AppleBooksId);
|
||||
Assert.Equal(request.ISBNs, result.ISBNs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
Assert.Equal(request.Ratings, result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _addBookRequestFixture.Create(
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
includeFormat: false,
|
||||
includeEdition: false,
|
||||
includeVolumeNumber: false,
|
||||
includeAsin: false,
|
||||
includeGoodreadsId: false,
|
||||
includeLccn: false,
|
||||
includeOclcNumber: false,
|
||||
includeOpenLibraryId: false,
|
||||
includeLibraryThingId: false,
|
||||
includeGoogleBooksId: false,
|
||||
includeBarnesAndNobleId: false,
|
||||
includeAppleBooksId: false,
|
||||
includeIsbns: false,
|
||||
includeRatings: false,
|
||||
includeContributors: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Null(result.Format);
|
||||
Assert.Null(result.Edition);
|
||||
Assert.Null(result.VolumeNumber);
|
||||
Assert.Null(result.Series);
|
||||
Assert.Null(result.ASIN);
|
||||
Assert.Null(result.GoodreadsId);
|
||||
Assert.Null(result.LCCN);
|
||||
Assert.Null(result.OCLCNumber);
|
||||
Assert.Null(result.OpenLibraryId);
|
||||
Assert.Null(result.LibraryThingId);
|
||||
Assert.Null(result.GoogleBooksId);
|
||||
Assert.Null(result.BarnesAndNobleId);
|
||||
Assert.Null(result.AppleBooksId);
|
||||
Assert.Null(result.ISBNs);
|
||||
Assert.Null(result.Contributors);
|
||||
Assert.Null(result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AddBookRequest request = _addBookRequestFixture.Create(
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
isbns: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
contributors:
|
||||
[
|
||||
_mediaContributorReferenceDtoFixture.Create(role: MediaContributorRole.Author)
|
||||
],
|
||||
ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)],
|
||||
includeFormat: false,
|
||||
includeEdition: false,
|
||||
includeVolumeNumber: false,
|
||||
includeAsin: false,
|
||||
includeGoodreadsId: false,
|
||||
includeLccn: false,
|
||||
includeOclcNumber: false,
|
||||
includeOpenLibraryId: false,
|
||||
includeLibraryThingId: false,
|
||||
includeGoogleBooksId: false,
|
||||
includeBarnesAndNobleId: false,
|
||||
includeAppleBooksId: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(request.ISBNs, result.ISBNs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
Assert.Equal(request.Ratings, result.Ratings);
|
||||
}
|
||||
}
|
||||
+446
@@ -0,0 +1,446 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookEntityMappingTests
|
||||
{
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<BookEntity> _paginatedResultDtoFixture = new();
|
||||
private readonly BookArtworkEntityFixture _bookArtworkEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidBookEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Book> result = bookEntity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(bookEntity.Id, result.Value.Id.Value);
|
||||
Assert.Equal(bookEntity.Title, result.Value.Metadata.Title);
|
||||
|
||||
if (bookEntity.OriginalTitle is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(bookEntity.OriginalTitle, result.Value.Metadata.OriginalTitle.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.OriginalTitle.HasValue);
|
||||
|
||||
if (bookEntity.Description is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.Description.HasValue);
|
||||
Assert.Equal(bookEntity.Description, result.Value.Metadata.Description.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.Description.HasValue);
|
||||
|
||||
if (bookEntity.OriginalReleaseDate.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(bookEntity.OriginalReleaseDate.Value, result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
|
||||
if (bookEntity.OriginalReleaseYear.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(bookEntity.OriginalReleaseYear.Value, result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
|
||||
if (bookEntity.ReReleaseDate.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.Equal(bookEntity.ReReleaseDate.Value, result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
|
||||
if (bookEntity.ReReleaseYear.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.Equal(bookEntity.ReReleaseYear.Value, result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
|
||||
if (bookEntity.ReleaseCountry is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.Equal(bookEntity.ReleaseCountry, result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
|
||||
if (bookEntity.ReleaseVersion is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(bookEntity.ReleaseVersion, result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
|
||||
if (bookEntity.LanguageCode is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.Language.HasValue);
|
||||
Assert.Equal(bookEntity.LanguageCode, result.Value.Metadata.Language.Value.LanguageCode);
|
||||
Assert.Equal(bookEntity.LanguageName, result.Value.Metadata.Language.Value.LanguageName);
|
||||
|
||||
if (bookEntity.LanguageNativeName is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.Language.Value.NativeName.HasValue);
|
||||
Assert.Equal(bookEntity.LanguageNativeName, result.Value.Metadata.Language.Value.NativeName.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.Language.Value.NativeName.HasValue);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.Language.HasValue);
|
||||
|
||||
if (bookEntity.OriginalLanguageCode is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.OriginalLanguage.HasValue);
|
||||
Assert.Equal(bookEntity.OriginalLanguageCode, result.Value.Metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(bookEntity.OriginalLanguageName, result.Value.Metadata.OriginalLanguage.Value.LanguageName);
|
||||
|
||||
if (bookEntity.OriginalLanguageNativeName is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue);
|
||||
Assert.Equal(bookEntity.OriginalLanguageNativeName, result.Value.Metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.OriginalLanguage.HasValue);
|
||||
|
||||
if (bookEntity.Publisher is not null)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.Publisher.HasValue);
|
||||
Assert.Equal(bookEntity.Publisher, result.Value.Metadata.Publisher.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.Publisher.HasValue);
|
||||
|
||||
if (bookEntity.PageCount.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Metadata.PageCount.HasValue);
|
||||
Assert.Equal(bookEntity.PageCount.Value, result.Value.Metadata.PageCount.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Metadata.PageCount.HasValue);
|
||||
|
||||
Assert.Equal(bookEntity.Format, result.Value.Format.Value);
|
||||
|
||||
if (bookEntity.Edition is not null)
|
||||
{
|
||||
Assert.True(result.Value.Edition.HasValue);
|
||||
Assert.Equal(bookEntity.Edition, result.Value.Edition.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Edition.HasValue);
|
||||
|
||||
if (bookEntity.VolumeNumber.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.VolumeNumber.HasValue);
|
||||
Assert.Equal(bookEntity.VolumeNumber.Value, result.Value.VolumeNumber.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.VolumeNumber.HasValue);
|
||||
|
||||
if (bookEntity.ASIN is not null)
|
||||
{
|
||||
Assert.True(result.Value.ASIN.HasValue);
|
||||
Assert.Equal(bookEntity.ASIN, result.Value.ASIN.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.ASIN.HasValue);
|
||||
|
||||
if (bookEntity.GoodreadsId is not null)
|
||||
{
|
||||
Assert.True(result.Value.GoodreadsId.HasValue);
|
||||
Assert.Equal(bookEntity.GoodreadsId, result.Value.GoodreadsId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.GoodreadsId.HasValue);
|
||||
|
||||
if (bookEntity.LCCN is not null)
|
||||
{
|
||||
Assert.True(result.Value.LCCN.HasValue);
|
||||
Assert.Equal(bookEntity.LCCN, result.Value.LCCN.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.LCCN.HasValue);
|
||||
|
||||
if (bookEntity.OCLCNumber is not null)
|
||||
{
|
||||
Assert.True(result.Value.OCLCNumber.HasValue);
|
||||
Assert.Equal(bookEntity.OCLCNumber, result.Value.OCLCNumber.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.OCLCNumber.HasValue);
|
||||
|
||||
if (bookEntity.OpenLibraryId is not null)
|
||||
{
|
||||
Assert.True(result.Value.OpenLibraryId.HasValue);
|
||||
Assert.Equal(bookEntity.OpenLibraryId, result.Value.OpenLibraryId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.OpenLibraryId.HasValue);
|
||||
|
||||
if (bookEntity.LibraryThingId is not null)
|
||||
{
|
||||
Assert.True(result.Value.LibraryThingId.HasValue);
|
||||
Assert.Equal(bookEntity.LibraryThingId, result.Value.LibraryThingId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.LibraryThingId.HasValue);
|
||||
|
||||
if (bookEntity.GoogleBooksId is not null)
|
||||
{
|
||||
Assert.True(result.Value.GoogleBooksId.HasValue);
|
||||
Assert.Equal(bookEntity.GoogleBooksId, result.Value.GoogleBooksId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.GoogleBooksId.HasValue);
|
||||
|
||||
if (bookEntity.BarnesAndNobleId is not null)
|
||||
{
|
||||
Assert.True(result.Value.BarnesAndNobleId.HasValue);
|
||||
Assert.Equal(bookEntity.BarnesAndNobleId, result.Value.BarnesAndNobleId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.BarnesAndNobleId.HasValue);
|
||||
|
||||
if (bookEntity.AppleBooksId is not null)
|
||||
{
|
||||
Assert.True(result.Value.AppleBooksId.HasValue);
|
||||
Assert.Equal(bookEntity.AppleBooksId, result.Value.AppleBooksId.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.AppleBooksId.HasValue);
|
||||
|
||||
Assert.Equal(bookEntity.CreatedOnUtc, result.Value.CreatedOnUtc);
|
||||
|
||||
if (bookEntity.UpdatedOnUtc.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.UpdatedOnUtc.HasValue);
|
||||
Assert.Equal(bookEntity.UpdatedOnUtc.Value, result.Value.UpdatedOnUtc!.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.UpdatedOnUtc.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDto_WhenMappingABook_ShouldMapTheConsumptionHistoryRow()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
BookArtworkEntity backArtwork = _bookArtworkEntityFixture.Create(
|
||||
bookId: bookEntity.Id,
|
||||
artworkType: ArtworkType.Back,
|
||||
fileName: "artwork/back.jpg");
|
||||
BookArtworkEntity frontArtwork = _bookArtworkEntityFixture.Create(
|
||||
bookId: bookEntity.Id,
|
||||
artworkType: ArtworkType.Front,
|
||||
fileName: "artwork/front.jpg");
|
||||
BookArtworkEntity coverArtwork = _bookArtworkEntityFixture.Create(
|
||||
bookId: bookEntity.Id,
|
||||
artworkType: ArtworkType.Cover,
|
||||
fileName: "artwork/cover.jpg");
|
||||
bookEntity.Artwork = [backArtwork, frontArtwork, coverArtwork];
|
||||
DateTime lastConsumedOnUtc = new(2026, 5, 6, 7, 8, 9, DateTimeKind.Utc);
|
||||
|
||||
// Act
|
||||
ConsumedItemDto result = bookEntity.ToDto(lastConsumedOnUtc, 6, 2, 180_000, "Author Name");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(MediaKind.Book, result.MediaKind);
|
||||
Assert.Equal(bookEntity.Id, result.MediaItemId);
|
||||
Assert.Equal(bookEntity.LibraryId, result.LibraryId);
|
||||
Assert.True(result.IsAvailable);
|
||||
Assert.Equal(bookEntity.Title, result.Title);
|
||||
Assert.Equal(string.Empty, result.CollectionTitle);
|
||||
Assert.Equal("Author Name", result.CreatorName);
|
||||
Assert.Equal(coverArtwork.FileName, result.CoverPath);
|
||||
Assert.Equal(lastConsumedOnUtc, result.LastConsumedOnUtc);
|
||||
Assert.Equal(6, result.CountedSessionCount);
|
||||
Assert.Equal(2, result.CompletedSessionCount);
|
||||
Assert.Equal(180_000L, result.ConsumedDurationMilliseconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDto_WhenTheBookHasNoArtwork_ShouldMapANullCoverPath()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
bookEntity.Artwork = [];
|
||||
DateTime lastConsumedOnUtc = new(2026, 5, 6, 7, 8, 9, DateTimeKind.Utc);
|
||||
|
||||
// Act
|
||||
ConsumedItemDto result = bookEntity.ToDto(lastConsumedOnUtc, 1, 0, 15_000, "Author Name");
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.CoverPath);
|
||||
Assert.Equal(bookEntity.Id, result.MediaItemId);
|
||||
Assert.Equal(bookEntity.LibraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDto_WhenTheBookHasNoCoverArtwork_ShouldMapANullCoverPath()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
bookEntity.Artwork =
|
||||
[
|
||||
_bookArtworkEntityFixture.Create(bookId: bookEntity.Id, artworkType: ArtworkType.Booklet, fileName: "artwork/booklet.jpg"),
|
||||
_bookArtworkEntityFixture.Create(bookId: bookEntity.Id, artworkType: ArtworkType.Backdrop, fileName: "artwork/backdrop.jpg")
|
||||
];
|
||||
DateTime lastConsumedOnUtc = new(2026, 5, 6, 7, 8, 9, DateTimeKind.Utc);
|
||||
|
||||
// Act
|
||||
ConsumedItemDto result = bookEntity.ToDto(lastConsumedOnUtc, 1, 0, 15_000, "Author Name");
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.CoverPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingBookEntity_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
BookResponse result = bookEntity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookEntity.Id, result.Id);
|
||||
Assert.Equal(bookEntity.Title, result.Metadata.Title);
|
||||
Assert.Equal(bookEntity.OriginalTitle, result.Metadata.OriginalTitle);
|
||||
Assert.Equal(bookEntity.Description, result.Metadata.Description);
|
||||
Assert.Equal(bookEntity.OriginalReleaseDate, result.Metadata.ReleaseInfo!.OriginalReleaseDate);
|
||||
Assert.Equal(bookEntity.OriginalReleaseYear, result.Metadata.ReleaseInfo.OriginalReleaseYear);
|
||||
Assert.Equal(bookEntity.ReReleaseDate, result.Metadata.ReleaseInfo.ReReleaseDate);
|
||||
Assert.Equal(bookEntity.ReReleaseYear, result.Metadata.ReleaseInfo.ReReleaseYear);
|
||||
Assert.Equal(bookEntity.ReleaseCountry, result.Metadata.ReleaseInfo.ReleaseCountry);
|
||||
Assert.Equal(bookEntity.ReleaseVersion, result.Metadata.ReleaseInfo.ReleaseVersion);
|
||||
Assert.NotNull(result.Metadata.Language);
|
||||
Assert.Equal(bookEntity.LanguageCode, result.Metadata.Language!.LanguageCode);
|
||||
Assert.Equal(bookEntity.LanguageName, result.Metadata.Language.LanguageName);
|
||||
Assert.Equal(bookEntity.LanguageNativeName, result.Metadata.Language.NativeName);
|
||||
Assert.NotNull(result.Metadata.OriginalLanguage);
|
||||
Assert.Equal(bookEntity.OriginalLanguageCode, result.Metadata.OriginalLanguage!.LanguageCode);
|
||||
Assert.Equal(bookEntity.OriginalLanguageName, result.Metadata.OriginalLanguage.LanguageName);
|
||||
Assert.Equal(bookEntity.OriginalLanguageNativeName, result.Metadata.OriginalLanguage.NativeName);
|
||||
Assert.Equal(bookEntity.Publisher, result.Metadata.Publisher);
|
||||
Assert.Equal(bookEntity.PageCount, result.Metadata.PageCount);
|
||||
Assert.Equal(bookEntity.Format, result.Format);
|
||||
Assert.Equal(bookEntity.Edition, result.Edition);
|
||||
Assert.Equal(bookEntity.VolumeNumber, result.VolumeNumber);
|
||||
Assert.Equal(bookEntity.ASIN, result.ASIN);
|
||||
Assert.Equal(bookEntity.GoodreadsId, result.GoodreadsId);
|
||||
Assert.Equal(bookEntity.LCCN, result.LCCN);
|
||||
Assert.Equal(bookEntity.OCLCNumber, result.OCLCNumber);
|
||||
Assert.Equal(bookEntity.OpenLibraryId, result.OpenLibraryId);
|
||||
Assert.Equal(bookEntity.LibraryThingId, result.LibraryThingId);
|
||||
Assert.Equal(bookEntity.GoogleBooksId, result.GoogleBooksId);
|
||||
Assert.Equal(bookEntity.BarnesAndNobleId, result.BarnesAndNobleId);
|
||||
Assert.Equal(bookEntity.AppleBooksId, result.AppleBooksId);
|
||||
Assert.Equal(bookEntity.ISBNs.Select(i => _isbnDtoFixture.Create(value: i.Value, format: i.Format)), result.ISBNs);
|
||||
Assert.Equal(bookEntity.Ratings.Select(r => _bookRatingDtoFixture.Create(
|
||||
value: r.Value,
|
||||
maxValue: r.MaxValue,
|
||||
source: r.Source,
|
||||
voteCount: r.VoteCount
|
||||
)), result.Ratings);
|
||||
Assert.Equal(bookEntity.CreatedOnUtc, result.CreatedOnUtc);
|
||||
Assert.Equal(bookEntity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Book>> results = bookEntities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(bookEntities.Count, results.Count());
|
||||
Assert.All(results, result => Assert.False(result.IsFailure));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
|
||||
|
||||
// Act
|
||||
IEnumerable<BookResponse> results = bookEntities.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(bookEntities.Count, results.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingPaginatedBookEntities_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookEntity> paginatedBookEntities = _paginatedResultDtoFixture.Create(
|
||||
data: bookEntities,
|
||||
currentPage: 1,
|
||||
perPage: 10,
|
||||
count: 2,
|
||||
numberOfPages: 1);
|
||||
|
||||
// Act
|
||||
PaginatedResponse<BookResponse> result = paginatedBookEntities.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(paginatedBookEntities.Data.Count, result.Data.Count);
|
||||
Assert.Equal(paginatedBookEntities.CurrentPage, result.CurrentPage);
|
||||
Assert.Equal(paginatedBookEntities.PerPage, result.PerPage);
|
||||
Assert.Equal(paginatedBookEntities.Count, result.Count);
|
||||
Assert.Equal(paginatedBookEntities.NumberOfPages, result.NumberOfPages);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Fixtures.Common.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLiteRowMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLiteRowMappingTests
|
||||
{
|
||||
private readonly BookLiteRowFixture _bookLiteRowFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<BookLiteRow> _paginatedResultDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingBookLiteRow_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookLiteRow readModel = _bookLiteRowFixture.Create();
|
||||
|
||||
// Act
|
||||
BookLiteResponse result = readModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(readModel.Id, result.Id);
|
||||
Assert.Equal(readModel.Title, result.Title);
|
||||
Assert.Equal(readModel.ReleaseYear, result.ReleaseYear);
|
||||
Assert.Equal(readModel.CoverPath, result.CoverPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookLiteRows_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookLiteRow> readModels = _bookLiteRowFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<BookLiteResponse> results = readModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(readModels.Count, results.Count);
|
||||
Assert.Equal(readModels.Select(readModel => readModel.Id), results.Select(response => response.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingPaginatedBookLiteRows_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookLiteRow> readModels = _bookLiteRowFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookLiteRow> paginatedReadModels = _paginatedResultDtoFixture.Create(
|
||||
data: readModels,
|
||||
currentPage: 1,
|
||||
perPage: 10,
|
||||
count: 2,
|
||||
numberOfPages: 1);
|
||||
|
||||
// Act
|
||||
PaginatedResponse<BookLiteResponse> result = paginatedReadModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(paginatedReadModels.Data.Count, result.Data.Count);
|
||||
Assert.Equal(paginatedReadModels.CurrentPage, result.CurrentPage);
|
||||
Assert.Equal(paginatedReadModels.PerPage, result.PerPage);
|
||||
Assert.Equal(paginatedReadModels.Count, result.Count);
|
||||
Assert.Equal(paginatedReadModels.NumberOfPages, result.NumberOfPages);
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookMappingTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBook_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
BookEntity result = book.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(book.Id.Value, result.Id);
|
||||
Assert.Equal(book.Metadata.Title, result.Title);
|
||||
Assert.Equal(book.Metadata.OriginalTitle.HasValue ? book.Metadata.OriginalTitle.Value : null, result.OriginalTitle);
|
||||
Assert.Equal(book.Metadata.Description.HasValue ? book.Metadata.Description.Value : null, result.Description);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null, result.OriginalReleaseDate);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null, result.OriginalReleaseYear);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? book.Metadata.ReleaseInfo.ReReleaseDate.Value : null, result.ReReleaseDate);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? book.Metadata.ReleaseInfo.ReReleaseYear.Value : null, result.ReReleaseYear);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? book.Metadata.ReleaseInfo.ReleaseCountry.Value : null, result.ReleaseCountry);
|
||||
Assert.Equal(book.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? book.Metadata.ReleaseInfo.ReleaseVersion.Value : null, result.ReleaseVersion);
|
||||
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageCode : null, result.LanguageCode);
|
||||
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageName : null, result.LanguageName);
|
||||
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.NativeName.Value : null, result.LanguageNativeName);
|
||||
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageCode : null, result.OriginalLanguageCode);
|
||||
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageName : null, result.OriginalLanguageName);
|
||||
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.NativeName.Value : null, result.OriginalLanguageNativeName);
|
||||
// The repository entity stores tags and genres as sets, so duplicate names in the domain collection collapse into a single entry.
|
||||
Assert.Equal(book.Metadata.Tags.ToRepositoryEntities().Distinct().OrderBy(tag => tag.Name), result.Tags.OrderBy(tag => tag.Name));
|
||||
Assert.Equal(book.Metadata.Genres.ToRepositoryEntities().Distinct().OrderBy(genre => genre.Name), result.Genres.OrderBy(genre => genre.Name));
|
||||
Assert.Equal(book.Metadata.Publisher.HasValue ? book.Metadata.Publisher.Value : null, result.Publisher);
|
||||
Assert.Equal(book.Metadata.PageCount.HasValue ? book.Metadata.PageCount.Value : null, result.PageCount);
|
||||
Assert.Equal(book.Format.HasValue ? book.Format.Value : null, result.Format);
|
||||
Assert.Equal(book.Edition.HasValue ? book.Edition.Value : null, result.Edition);
|
||||
Assert.Equal(book.VolumeNumber.HasValue ? book.VolumeNumber.Value : null, result.VolumeNumber);
|
||||
Assert.Equal(book.ASIN.HasValue ? book.ASIN.Value : null, result.ASIN);
|
||||
Assert.Equal(book.GoodreadsId.HasValue ? book.GoodreadsId.Value : null, result.GoodreadsId);
|
||||
Assert.Equal(book.LCCN.HasValue ? book.LCCN.Value : null, result.LCCN);
|
||||
Assert.Equal(book.OCLCNumber.HasValue ? book.OCLCNumber.Value : null, result.OCLCNumber);
|
||||
Assert.Equal(book.OpenLibraryId.HasValue ? book.OpenLibraryId.Value : null, result.OpenLibraryId);
|
||||
Assert.Equal(book.LibraryThingId.HasValue ? book.LibraryThingId.Value : null, result.LibraryThingId);
|
||||
Assert.Equal(book.GoogleBooksId.HasValue ? book.GoogleBooksId.Value : null, result.GoogleBooksId);
|
||||
Assert.Equal(book.BarnesAndNobleId.HasValue ? book.BarnesAndNobleId.Value : null, result.BarnesAndNobleId);
|
||||
Assert.Equal(book.AppleBooksId.HasValue ? book.AppleBooksId.Value : null, result.AppleBooksId);
|
||||
Assert.Equal(book.ISBNs.ToRepositoryEntities(), result.ISBNs);
|
||||
Assert.Equal(book.Ratings.ToRepositoryEntities(), result.Ratings);
|
||||
Assert.Equal(default, result.CreatedOnUtc);
|
||||
Assert.Null(result.UpdatedOnUtc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadataToEntity_WhenApplyingCompleteBook_ShouldOverwriteTheMetadataFields()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookEntity entity = _bookEntityFixture.Create();
|
||||
BookEntity expectedEntity = book.ToRepositoryEntity();
|
||||
DateTime? initialUpdatedOnUtc = entity.UpdatedOnUtc;
|
||||
Guid? initialUpdatedBy = entity.UpdatedBy;
|
||||
|
||||
// Act
|
||||
entity.ApplyMetadataToEntity(book);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(book.Metadata.Title, entity.Title);
|
||||
Assert.Equal(expectedEntity.OriginalTitle, entity.OriginalTitle);
|
||||
Assert.Equal(expectedEntity.Description, entity.Description);
|
||||
Assert.Equal(expectedEntity.OriginalReleaseDate, entity.OriginalReleaseDate);
|
||||
Assert.Equal(expectedEntity.OriginalReleaseYear, entity.OriginalReleaseYear);
|
||||
Assert.Equal(expectedEntity.ReReleaseDate, entity.ReReleaseDate);
|
||||
Assert.Equal(expectedEntity.ReReleaseYear, entity.ReReleaseYear);
|
||||
Assert.Equal(expectedEntity.ReleaseCountry, entity.ReleaseCountry);
|
||||
Assert.Equal(expectedEntity.ReleaseVersion, entity.ReleaseVersion);
|
||||
Assert.Equal(expectedEntity.LanguageCode, entity.LanguageCode);
|
||||
Assert.Equal(expectedEntity.LanguageName, entity.LanguageName);
|
||||
Assert.Equal(expectedEntity.LanguageNativeName, entity.LanguageNativeName);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageCode, entity.OriginalLanguageCode);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageName, entity.OriginalLanguageName);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageNativeName, entity.OriginalLanguageNativeName);
|
||||
Assert.Equal(expectedEntity.Publisher, entity.Publisher);
|
||||
Assert.Equal(expectedEntity.PageCount, entity.PageCount);
|
||||
Assert.Equal(expectedEntity.Format, entity.Format);
|
||||
Assert.Equal(expectedEntity.Edition, entity.Edition);
|
||||
Assert.Equal(expectedEntity.VolumeNumber, entity.VolumeNumber);
|
||||
Assert.Equal(expectedEntity.ASIN, entity.ASIN);
|
||||
Assert.Equal(expectedEntity.GoodreadsId, entity.GoodreadsId);
|
||||
Assert.Equal(expectedEntity.LCCN, entity.LCCN);
|
||||
Assert.Equal(expectedEntity.OCLCNumber, entity.OCLCNumber);
|
||||
Assert.Equal(expectedEntity.OpenLibraryId, entity.OpenLibraryId);
|
||||
Assert.Equal(expectedEntity.LibraryThingId, entity.LibraryThingId);
|
||||
Assert.Equal(expectedEntity.GoogleBooksId, entity.GoogleBooksId);
|
||||
Assert.Equal(expectedEntity.BarnesAndNobleId, entity.BarnesAndNobleId);
|
||||
Assert.Equal(expectedEntity.AppleBooksId, entity.AppleBooksId);
|
||||
Assert.Equal(initialUpdatedOnUtc, entity.UpdatedOnUtc);
|
||||
Assert.Equal(initialUpdatedBy, entity.UpdatedBy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadataToEntity_WhenApplyingBook_ShouldPreserveIdentityAndCollectionColumns()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookEntity entity = _bookEntityFixture.Create();
|
||||
Guid entityId = entity.Id;
|
||||
Guid libraryId = entity.LibraryId;
|
||||
string path = entity.Path;
|
||||
int isbnsCount = entity.ISBNs.Count;
|
||||
int ratingsCount = entity.Ratings.Count;
|
||||
|
||||
// Act
|
||||
entity.ApplyMetadataToEntity(book);
|
||||
|
||||
// Assert
|
||||
// The identity and the collection columns are not part of the metadata application.
|
||||
Assert.Equal(entityId, entity.Id);
|
||||
Assert.Equal(libraryId, entity.LibraryId);
|
||||
Assert.Equal(path, entity.Path);
|
||||
Assert.Equal(isbnsCount, entity.ISBNs.Count);
|
||||
Assert.Equal(ratingsCount, entity.Ratings.Count);
|
||||
}
|
||||
}
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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.Common;
|
||||
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.Fixtures.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="BookMetadataDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookMetadataDtoMappingTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItToTheBook()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
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);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("The Fellowship of the Ring", book.Metadata.Title);
|
||||
Assert.Equal("3", book.GoodreadsId.Value);
|
||||
Assert.Equal("The first part of J.R.R. Tolkien's epic adventure.", book.Metadata.Description.Value);
|
||||
Assert.Equal(BookFormat.Paperback, book.Format.Value);
|
||||
Assert.Equal("Houghton Mifflin", book.Metadata.Publisher.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenCalledWithInvalidGenres_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "The Fellowship of the Ring",
|
||||
goodreadsId: "3",
|
||||
genres: [_genreDtoFixture.Create(name: "")]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.NotEqual("The Fellowship of the Ring", book.Metadata.Title);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // Missing title.
|
||||
[InlineData("")] // Empty title.
|
||||
[InlineData(" ")] // Whitespace title.
|
||||
public void ApplyMetadata_WhenTitleIsNullOrWhitespace_ShouldReturnTitleCannotBeEmptyError(string? title)
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(includeTitle: title is not null, title: title, includeReleaseInfo: false, includeGenres: false, includeTags: false, includeLanguage: false, includeFormat: false, includeVolumeNumber: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TitleCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenReleaseInfoIsNull_ShouldReturnReleaseInfoCannotBeNullError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(title: "A valid title", includeReleaseInfo: false, includeGenres: false, includeTags: false, includeLanguage: false, includeFormat: false, includeVolumeNumber: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.ReleaseInfoCannotBeNull, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
releaseInfo: _releaseInfoDtoFixture.Create(originalReleaseDate: new DateOnly(2000, 1, 1), originalReleaseYear: 1999));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.OriginalReleaseDateAndYearMustMatch, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenTagsAreInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenIsbnIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [_isbnDtoFixture.Create(value: "not-an-isbn", format: IsbnFormat.Isbn13)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenRatingIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
ratings: [_bookRatingDtoFixture.Create(value: -1m, maxValue: 5m, includeSource: false, includeVoteCount: false)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenOptionalCollectionsAreNull_ShouldApplyMetadataWithoutCollections()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
releaseInfo: _releaseInfoDtoFixture.Create(originalReleaseDate: new DateOnly(2000, 1, 1), originalReleaseYear: 2000),
|
||||
includeGenres: false,
|
||||
includeTags: false,
|
||||
includeLanguage: false,
|
||||
includeFormat: false,
|
||||
includeVolumeNumber: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("A valid title", book.Metadata.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenIsbnsAndRatingsAreValid_ShouldApplyMetadataWithTheCollections()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [_isbnDtoFixture.Create(value: "9780306406157", format: IsbnFormat.Isbn13)],
|
||||
ratings: [_bookRatingDtoFixture.Create(value: 4m, maxValue: 5m, voteCount: 10, includeSource: false)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Single(book.ISBNs);
|
||||
Assert.Single(book.Ratings);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
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="GetBooksLiteRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBooksLiteRequestMappingTests
|
||||
{
|
||||
private readonly GetBooksLiteRequestFixture _getBooksLiteRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetBooksLiteRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
Assert.Equal(request.SearchTerm, result.SearchTerm);
|
||||
Assert.Equal(request.FilterAlphaKey, result.FilterAlphaKey);
|
||||
Assert.Equal(request.ShouldIgnoreThePrefixForAlphaPicker, result.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(request.SortBy, result.SortBy);
|
||||
Assert.Equal(request.SortOrder, result.SortOrder);
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(request.CurrentPage, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(request.PerPage, result.PaginationData.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenLibraryIdIsNotParseable_ShouldMapItAsIs()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
string libraryId = "not-a-library-guid";
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenLibraryIdIsNull_ShouldMapNullLibraryId()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(null);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenNoPaginationProvided_ShouldNotBuildPaginationData()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create(includeCurrentPage: false, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.PaginationData);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenOnlyPerPageProvided_ShouldDefaultCurrentPageToOne()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create(perPage: 25, includeCurrentPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(1, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(25, result.PaginationData.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenOnlyCurrentPageProvided_ShouldDefaultPerPageToTwoHundred()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create(currentPage: 3, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(3, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(200, result.PaginationData.PerPage);
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
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="GetBooksRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBooksRequestMappingTests
|
||||
{
|
||||
private readonly GetBooksRequestFixture _getBooksRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetBooksRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create();
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
Assert.Equal(request.SearchTerm, result.SearchTerm);
|
||||
Assert.Equal(request.SortBy, result.SortBy);
|
||||
Assert.Equal(request.SortOrder, result.SortOrder);
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(request.CurrentPage, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(request.PerPage, result.PaginationData.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenLibraryIdIsNotParseable_ShouldMapItAsIs()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create();
|
||||
string libraryId = "not-a-library-guid";
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenLibraryIdIsNull_ShouldMapNullLibraryId()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(null);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenNoPaginationProvided_ShouldNotBuildPaginationData()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create(includeCurrentPage: false, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.PaginationData);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenOnlyPerPageProvided_ShouldDefaultCurrentPageToOne()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create(perPage: 25, includeCurrentPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(1, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(25, result.PaginationData.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenOnlyCurrentPageProvided_ShouldDefaultPerPageToTwoHundred()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create(currentPage: 3, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
Assert.Equal(3, result.PaginationData!.CurrentPage);
|
||||
Assert.Equal(200, result.PaginationData.PerPage);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ReadingDocumentDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReadingDocumentDtoMappingTests
|
||||
{
|
||||
private readonly ReadingDocumentDtoFixture _readingDocumentDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidDocument_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ReadingDocumentDto document = _readingDocumentDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
ReadingManifestResponse result = document.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(document.Title, result.Title);
|
||||
Assert.Equal(document.Author, result.Author);
|
||||
Assert.Equal(document.CoverResourceKey, result.CoverResourceKey);
|
||||
Assert.Equal(document.TableOfContents.Count, result.TableOfContents.Count);
|
||||
Assert.Equal(document.Spine.Select(item => item.LocationRef), result.Spine.Select(item => item.LocationRef));
|
||||
Assert.Equal(document.Spine.Select(item => item.Title), result.Spine.Select(item => item.Title));
|
||||
Assert.Equal(document.Resources.Keys, result.ResourceKeys);
|
||||
Assert.Equal(document.HasTextContent, result.HasTextContent);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ReadingTocEntryDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReadingTocEntryDtoMappingTests
|
||||
{
|
||||
private readonly ReadingTocEntryDtoFixture _readingTocEntryDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntry_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ReadingTocEntryDto entry = _readingTocEntryDtoFixture.Create(children: [_readingTocEntryDtoFixture.Create()]);
|
||||
|
||||
// Act
|
||||
ReadingTocEntryResponse result = entry.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entry.Label, result.Label);
|
||||
Assert.Equal(entry.LocationRef, result.LocationRef);
|
||||
Assert.Equal(entry.Children.Count, result.Children.Count);
|
||||
Assert.Equal(entry.Children.Select(child => child.Label), result.Children.Select(child => child.Label));
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBook;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBook;
|
||||
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="UpdateBookCommandMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookCommandMappingTests
|
||||
{
|
||||
private readonly UpdateBookCommandFixture _updateBookCommandFixture = new();
|
||||
private readonly BookEntityFixture _bookEntityFixture = 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();
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookCommand command = _updateBookCommandFixture.Create(libraryId: libraryId.ToString(), bookId: bookId.ToString());
|
||||
BookEntity existingBook = _bookEntityFixture.Create(id: bookId, libraryId: libraryId, path: "/books/the-book.epub");
|
||||
DateTime createdOnUtc = existingBook.CreatedOnUtc;
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(existingBook);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(bookId, result.Value.Id.Value);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId.Value);
|
||||
Assert.Equal(existingBook.Path, result.Value.Path);
|
||||
Assert.Equal(createdOnUtc, result.Value.CreatedOnUtc);
|
||||
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();
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookCommand command = _updateBookCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
bookId: bookId.ToString(),
|
||||
isbns: [],
|
||||
contributors: [],
|
||||
ratings: [],
|
||||
includeFormat: false,
|
||||
includeEdition: false,
|
||||
includeVolumeNumber: false,
|
||||
includeAsin: false,
|
||||
includeGoodreadsId: false,
|
||||
includeLccn: false,
|
||||
includeOclcNumber: false,
|
||||
includeOpenLibraryId: false,
|
||||
includeLibraryThingId: false,
|
||||
includeGoogleBooksId: false,
|
||||
includeBarnesAndNobleId: false,
|
||||
includeAppleBooksId: false);
|
||||
BookEntity existingBook = _bookEntityFixture.Create(id: bookId, libraryId: libraryId, path: "/books/the-book.epub");
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(existingBook);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(bookId, result.Value.Id.Value);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId.Value);
|
||||
Assert.Equal(existingBook.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
|
||||
UpdateBookCommand command = _updateBookCommandFixture.Create(ratings: [_bookRatingDtoFixture.Create(value: -1, maxValue: 5, includeSource: false, includeVoteCount: false)]);
|
||||
BookEntity existingBook = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(existingBook);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.Metadata.RatingValueMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenIsbnCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookCommand command = _updateBookCommandFixture.Create(isbns: [_isbnDtoFixture.Create(value: "invalid", format: IsbnFormat.Isbn13)]);
|
||||
BookEntity existingBook = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(existingBook);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMetadataCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookCommand command = _updateBookCommandFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: "")]));
|
||||
BookEntity existingBook = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Book> result = command.ToDomainEntity(existingBook);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains(result.Errors, error => error.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBookCover;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBookCover;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
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="UpdateBookCoverCommandMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookCoverCommandMappingTests
|
||||
{
|
||||
private readonly UpdateBookCoverCommandFixture _updateBookCoverCommandFixture = new();
|
||||
private readonly BookArtworkEntityFixture _bookArtworkEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenBookHasNoCover_ShouldReturnANewEnrichedCoverArtwork()
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookCoverCommand command = _updateBookCoverCommandFixture.Create(bookId: bookId.ToString());
|
||||
string storedCoverPath = "/media/books/cover.jpg";
|
||||
|
||||
// Act
|
||||
BookArtworkEntity cover = command.ToRepositoryEntity(null, bookId, storedCoverPath);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(bookId, cover.BookId);
|
||||
Assert.Equal(ArtworkType.Cover, cover.ArtworkType);
|
||||
Assert.Equal(0, cover.Ordinal);
|
||||
Assert.Equal(storedCoverPath, cover.FileName);
|
||||
Assert.Equal(ArtworkStatus.Enriched, cover.Status);
|
||||
Assert.Equal(Guid.Empty, cover.CreatedBy);
|
||||
Assert.Equal(default, cover.CreatedOnUtc);
|
||||
Assert.Null(cover.UpdatedBy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenBookHasAnExistingCover_ShouldReplaceAndReturnTheStoredCover()
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookCoverCommand command = _updateBookCoverCommandFixture.Create(bookId: bookId.ToString());
|
||||
BookArtworkEntity existingCover = _bookArtworkEntityFixture.Create(bookId: bookId, artworkType: ArtworkType.Cover, fileName: "/media/books/old-cover.jpg", status: ArtworkStatus.Pending);
|
||||
DateTime? initialUpdatedOnUtc = existingCover.UpdatedOnUtc;
|
||||
Guid? initialUpdatedBy = existingCover.UpdatedBy;
|
||||
string storedCoverPath = "/media/books/cover.jpg";
|
||||
|
||||
// Act
|
||||
BookArtworkEntity cover = command.ToRepositoryEntity(existingCover, bookId, storedCoverPath);
|
||||
|
||||
// Assert
|
||||
Assert.Same(existingCover, cover);
|
||||
Assert.Equal(storedCoverPath, cover.FileName);
|
||||
Assert.Equal(ArtworkStatus.Enriched, cover.Status);
|
||||
Assert.Equal(initialUpdatedOnUtc, cover.UpdatedOnUtc);
|
||||
Assert.Equal(initialUpdatedBy, cover.UpdatedBy);
|
||||
Assert.NotNull(cover.LastUpdateUtc);
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBook;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
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="UpdateBookRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookRequestMappingTests
|
||||
{
|
||||
private readonly UpdateBookRequestFixture _updateBookRequestFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
UpdateBookCommand result = request.ToCommand(libraryId.ToString(), bookId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId.ToString(), result.LibraryId);
|
||||
Assert.Equal(bookId.ToString(), result.BookId);
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Equal(request.Format, result.Format);
|
||||
Assert.Equal(request.Edition, result.Edition);
|
||||
Assert.Equal(request.VolumeNumber, result.VolumeNumber);
|
||||
Assert.Equal(request.Series, result.Series);
|
||||
Assert.Equal(request.ASIN, result.ASIN);
|
||||
Assert.Equal(request.GoodreadsId, result.GoodreadsId);
|
||||
Assert.Equal(request.LCCN, result.LCCN);
|
||||
Assert.Equal(request.OCLCNumber, result.OCLCNumber);
|
||||
Assert.Equal(request.OpenLibraryId, result.OpenLibraryId);
|
||||
Assert.Equal(request.LibraryThingId, result.LibraryThingId);
|
||||
Assert.Equal(request.GoogleBooksId, result.GoogleBooksId);
|
||||
Assert.Equal(request.BarnesAndNobleId, result.BarnesAndNobleId);
|
||||
Assert.Equal(request.AppleBooksId, result.AppleBooksId);
|
||||
Assert.Equal(request.ISBNs, result.ISBNs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
Assert.Equal(request.Ratings, result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create(includeFormat: false, includeEdition: false, includeVolumeNumber: false, includeAsin: false, includeGoodreadsId: false, includeLccn: false, includeOclcNumber: false, includeOpenLibraryId: false, includeLibraryThingId: false, includeGoogleBooksId: false, includeBarnesAndNobleId: false, includeAppleBooksId: false, includeIsbns: false, includeRatings: false, includeContributors: false);
|
||||
|
||||
// Act
|
||||
UpdateBookCommand result = request.ToCommand(libraryId.ToString(), bookId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookId.ToString(), result.BookId);
|
||||
Assert.NotNull(result.Metadata);
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Null(result.Format);
|
||||
Assert.Null(result.Edition);
|
||||
Assert.Null(result.VolumeNumber);
|
||||
Assert.Null(result.Series);
|
||||
Assert.Null(result.ASIN);
|
||||
Assert.Null(result.GoodreadsId);
|
||||
Assert.Null(result.LCCN);
|
||||
Assert.Null(result.OCLCNumber);
|
||||
Assert.Null(result.OpenLibraryId);
|
||||
Assert.Null(result.LibraryThingId);
|
||||
Assert.Null(result.GoogleBooksId);
|
||||
Assert.Null(result.BarnesAndNobleId);
|
||||
Assert.Null(result.AppleBooksId);
|
||||
Assert.Null(result.ISBNs);
|
||||
Assert.Null(result.Contributors);
|
||||
Assert.Null(result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid bookId = Guid.NewGuid();
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create(
|
||||
isbns: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
contributors:
|
||||
[
|
||||
_mediaContributorReferenceDtoFixture.Create(role: MediaContributorRole.Author)
|
||||
],
|
||||
ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)],
|
||||
includeFormat: false,
|
||||
includeEdition: false,
|
||||
includeVolumeNumber: false,
|
||||
includeAsin: false,
|
||||
includeGoodreadsId: false,
|
||||
includeLccn: false,
|
||||
includeOclcNumber: false,
|
||||
includeOpenLibraryId: false,
|
||||
includeLibraryThingId: false,
|
||||
includeGoogleBooksId: false,
|
||||
includeBarnesAndNobleId: false,
|
||||
includeAppleBooksId: false
|
||||
);
|
||||
|
||||
// Act
|
||||
UpdateBookCommand result = request.ToCommand(libraryId.ToString(), bookId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(request.ISBNs, result.ISBNs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
Assert.Equal(request.Ratings, result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenRouteValuesAreNotParseable_ShouldMapThemAsIs()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create(includeFormat: false, includeEdition: false, includeVolumeNumber: false, includeAsin: false, includeGoodreadsId: false, includeLccn: false, includeOclcNumber: false, includeOpenLibraryId: false, includeLibraryThingId: false, includeGoogleBooksId: false, includeBarnesAndNobleId: false, includeAppleBooksId: false, includeIsbns: false, includeRatings: false, includeContributors: false);
|
||||
|
||||
// Act
|
||||
UpdateBookCommand result = request.ToCommand("not-a-library-guid", "not-a-guid");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("not-a-library-guid", result.LibraryId);
|
||||
Assert.Equal("not-a-guid", result.BookId);
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.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.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingDtoMappingTests
|
||||
{
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingCompleteBookRatinDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(dto.Value!.Value, result.Value.Value);
|
||||
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
|
||||
|
||||
if (dto.Source.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.Source.HasValue);
|
||||
Assert.Equal(dto.Source.Value, result.Value.Source.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.Source.HasValue);
|
||||
|
||||
if (dto.VoteCount.HasValue)
|
||||
{
|
||||
Assert.True(result.Value.VoteCount.HasValue);
|
||||
Assert.Equal(dto.VoteCount.Value, result.Value.VoteCount.Value);
|
||||
}
|
||||
else
|
||||
Assert.False(result.Value.VoteCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingMinimalBookRatingDto_ShouldMapRequiredPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create(includeSource: false, includeVoteCount: false);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(dto.Value!.Value, result.Value.Value);
|
||||
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
|
||||
Assert.False(result.Value.Source.HasValue);
|
||||
Assert.False(result.Value.VoteCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingInvalidBookRatingDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create(value: 10, maxValue: 5);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidBookRatingDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingDto> dtos =
|
||||
[
|
||||
_bookRatingDtoFixture.Create(),
|
||||
_bookRatingDtoFixture.Create(includeSource: false, includeVoteCount: false)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(dtos.Count, results.Count());
|
||||
|
||||
List<Result<BookRating>> resultList = [.. results];
|
||||
foreach (Result<BookRating> result in resultList)
|
||||
Assert.False(result.IsFailure);
|
||||
|
||||
// Complete rating.
|
||||
Assert.Equal(dtos[0].Value!.Value, resultList[0].Value.Value);
|
||||
Assert.Equal(dtos[0].MaxValue!.Value, resultList[0].Value.MaxValue);
|
||||
Assert.Equal(dtos[0].Source!.Value, resultList[0].Value.Source.Value);
|
||||
Assert.Equal(dtos[0].VoteCount!.Value, resultList[0].Value.VoteCount.Value);
|
||||
|
||||
// Minimal rating.
|
||||
Assert.Equal(dtos[1].Value!.Value, resultList[1].Value.Value);
|
||||
Assert.Equal(dtos[1].MaxValue!.Value, resultList[1].Value.MaxValue);
|
||||
Assert.False(resultList[1].Value.Source.HasValue);
|
||||
Assert.False(resultList[1].Value.VoteCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidBookRatingDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingDto> dtos =
|
||||
[
|
||||
_bookRatingDtoFixture.Create(),
|
||||
_bookRatingDtoFixture.Create(value: 10, maxValue: 5),
|
||||
_bookRatingDtoFixture.Create(includeSource: false, includeVoteCount: false)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(dtos.Count, results.Count());
|
||||
|
||||
List<Result<BookRating>> resultList = [.. results];
|
||||
|
||||
Assert.False(resultList[0].IsFailure);
|
||||
Assert.True(resultList[1].IsFailure);
|
||||
Assert.False(resultList[2].IsFailure);
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingEntityMappingTests
|
||||
{
|
||||
private readonly BookRatingEntityFixture _bookRatingEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
BookRatingDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entity.Value!.Value, result.Value);
|
||||
Assert.Equal(entity.MaxValue!.Value, result.MaxValue);
|
||||
Assert.Equal(entity.Source, result.Source);
|
||||
Assert.Equal(entity.VoteCount, result.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.Create(includeValues: false);
|
||||
|
||||
// Act
|
||||
BookRatingDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(0, result.Value);
|
||||
Assert.Equal(0, result.MaxValue);
|
||||
Assert.Equal(entity.Source, result.Source);
|
||||
Assert.Equal(entity.VoteCount, result.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities = _bookRatingEntityFixture.CreateMany(2);
|
||||
// Act
|
||||
IEnumerable<BookRatingDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(entities.Count, results.Count());
|
||||
foreach (BookRatingDto result in results)
|
||||
{
|
||||
Assert.NotNull(result);
|
||||
Assert.InRange(result.Value!.Value, 1, 5);
|
||||
Assert.Equal(5, result.MaxValue);
|
||||
Assert.InRange(result.VoteCount!.Value, 1, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(entity.Value, result.Value.Value);
|
||||
Assert.Equal(entity.MaxValue, result.Value.MaxValue);
|
||||
Assert.Equal(entity.Source, result.Value.Source.Value);
|
||||
Assert.Equal(entity.VoteCount, result.Value.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.Create(includeValues: false);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(default, result.Value.Value);
|
||||
Assert.Equal(default, result.Value.MaxValue);
|
||||
Assert.False(result.Value.Source.HasValue);
|
||||
Assert.False(result.Value.VoteCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities = _bookRatingEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(entities.Count, results.Count());
|
||||
foreach (Result<BookRating> result in results)
|
||||
{
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.InRange(result.Value.Value, 1, 5);
|
||||
Assert.Equal(5, result.Value.MaxValue);
|
||||
Assert.True(result.Value.Source.HasValue);
|
||||
Assert.InRange(result.Value.VoteCount.Value, 1, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingMappingTests
|
||||
{
|
||||
private readonly BookRatingFixture _bookRatingFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBookRating_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.Create();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookRating.Value, result.Value);
|
||||
Assert.Equal(bookRating.MaxValue, result.MaxValue);
|
||||
Assert.Equal(bookRating.Source.Value, result.Source);
|
||||
Assert.Equal(bookRating.VoteCount.Value, result.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutSource_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.Create(source: Optional<BookRatingSource>.None());
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookRating.Value, result.Value);
|
||||
Assert.Equal(bookRating.MaxValue, result.MaxValue);
|
||||
Assert.Null(result.Source);
|
||||
Assert.Equal(bookRating.VoteCount.Value, result.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutVoteCount_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.Create(voteCount: Optional<int>.None());
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookRating.Value, result.Value);
|
||||
Assert.Equal(bookRating.MaxValue, result.MaxValue);
|
||||
Assert.Equal(bookRating.Source.Value, result.Source);
|
||||
Assert.Null(result.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleBookRatings_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRating> bookRatings =
|
||||
[
|
||||
_bookRatingFixture.Create(),
|
||||
_bookRatingFixture.Create(source: Optional<BookRatingSource>.None()),
|
||||
_bookRatingFixture.Create(voteCount: Optional<int>.None())
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookRatingEntity> results = bookRatings.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(bookRatings.Count, results.Count());
|
||||
|
||||
List<BookRatingEntity> resultList = [.. results];
|
||||
|
||||
// Complete rating.
|
||||
Assert.Equal(bookRatings[0].Value, resultList[0].Value);
|
||||
Assert.Equal(bookRatings[0].MaxValue, resultList[0].MaxValue);
|
||||
Assert.Equal(bookRatings[0].Source.Value, resultList[0].Source);
|
||||
Assert.Equal(bookRatings[0].VoteCount.Value, resultList[0].VoteCount);
|
||||
|
||||
// Rating without source.
|
||||
Assert.Equal(bookRatings[1].Value, resultList[1].Value);
|
||||
Assert.Equal(bookRatings[1].MaxValue, resultList[1].MaxValue);
|
||||
Assert.Null(resultList[1].Source);
|
||||
Assert.Equal(bookRatings[1].VoteCount.Value, resultList[1].VoteCount);
|
||||
|
||||
// Rating without vote count.
|
||||
Assert.Equal(bookRatings[2].Value, resultList[2].Value);
|
||||
Assert.Equal(bookRatings[2].MaxValue, resultList[2].MaxValue);
|
||||
Assert.Equal(bookRatings[2].Source.Value, resultList[2].Source);
|
||||
Assert.Null(resultList[2].VoteCount);
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.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.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnDtoMappingTests
|
||||
{
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidIsbn10Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create(format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(dto.Value, result.Value.Value);
|
||||
Assert.Equal(dto.Format!.Value, result.Value.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidIsbn13Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create(format: IsbnFormat.Isbn13);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(dto.Value, result.Value.Value);
|
||||
Assert.Equal(dto.Format!.Value, result.Value.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingDtoWithoutFormat_ShouldUseDefaultFormat()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(dto.Value, result.Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn13, result.Value.Format); // Default format.
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingInvalidIsbnDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create("invalid-isbn", IsbnFormat.Isbn13);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidIsbnDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnDto> dtos =
|
||||
[
|
||||
_isbnDtoFixture.Create(format: IsbnFormat.Isbn10),
|
||||
_isbnDtoFixture.Create(format: IsbnFormat.Isbn13),
|
||||
_isbnDtoFixture.Create(),
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(dtos.Count, results.Count());
|
||||
|
||||
List<Result<Isbn>> resultList = [.. results];
|
||||
Assert.All(resultList, result => Assert.False(result.IsFailure));
|
||||
|
||||
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
|
||||
Assert.Equal(dtos[0].Format!.Value, resultList[0].Value.Format);
|
||||
|
||||
Assert.Equal(dtos[1].Value, resultList[1].Value.Value);
|
||||
Assert.Equal(dtos[1].Format!.Value, resultList[1].Value.Format);
|
||||
|
||||
Assert.Equal(dtos[2].Value, resultList[2].Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn13, resultList[2].Value.Format); // Default format.
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidIsbnDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnDto> dtos =
|
||||
[
|
||||
_isbnDtoFixture.Create(format: IsbnFormat.Isbn10),
|
||||
_isbnDtoFixture.Create("invalid-isbn", IsbnFormat.Isbn13),
|
||||
_isbnDtoFixture.Create(format: IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(dtos.Count, results.Count());
|
||||
|
||||
List<Result<Isbn>> resultList = [.. results];
|
||||
|
||||
Assert.False(resultList[0].IsFailure);
|
||||
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
|
||||
|
||||
Assert.True(resultList[1].IsFailure);
|
||||
|
||||
Assert.False(resultList[2].IsFailure);
|
||||
Assert.Equal(dtos[2].Value, resultList[2].Value.Value);
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityMappingTests
|
||||
{
|
||||
private readonly IsbnEntityFixture _isbnEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entity.Value, result.Value);
|
||||
Assert.Equal(entity.Format, result.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-7475-3269-9", IsbnFormat.Isbn10)]
|
||||
[InlineData("978-0-7475-3269-9", IsbnFormat.Isbn13)]
|
||||
public void ToResponse_WhenMappingDifferentValidIsbnEntities_ShouldMapCorrectly(string value, IsbnFormat format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(value, result.Value);
|
||||
Assert.Equal(format, result.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", null)]
|
||||
[InlineData(" ", null)]
|
||||
[InlineData(null, null)]
|
||||
public void ToResponse_WhenMappingInvalidIsbnEntity_ShouldPreserveValues(string? value, IsbnFormat? format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format, includeValue: value is not null, includeFormat: false);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, result.Value);
|
||||
Assert.Equal(format, result.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(entity.Value, result.Value.Value);
|
||||
Assert.Equal(entity.Format, result.Value.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainValueObject_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: invalidValue, includeValue: invalidValue is not null);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
_isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10),
|
||||
_isbnEntityFixture.Create(value: "978-0-7475-3269-9", format: IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(entities.Count, results.Count());
|
||||
|
||||
List<Result<Isbn>> resultList = [.. results];
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
Assert.False(resultList[i].IsFailure);
|
||||
Assert.Equal(entities[i].Value, resultList[i].Value.Value);
|
||||
Assert.Equal(entities[i].Format, resultList[i].Value.Format);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
_isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10),
|
||||
_isbnEntityFixture.Create(value: "978-0-7475-3269-9", format: IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(entities.Count, results.Count());
|
||||
|
||||
List<IsbnDto> resultList = [.. results];
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
Assert.Equal(entities[i].Value, resultList[i].Value);
|
||||
Assert.Equal(entities[i].Format, resultList[i].Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnMappingTests
|
||||
{
|
||||
private readonly IsbnFixture _isbnFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn10_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.Create(format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(isbn.Value, result.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn10, result.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn13_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.Create(format: IsbnFormat.Isbn13);
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(isbn.Value, result.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn13, result.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleIsbns_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns =
|
||||
[
|
||||
_isbnFixture.Create(format: IsbnFormat.Isbn10),
|
||||
_isbnFixture.Create(format: IsbnFormat.Isbn13),
|
||||
_isbnFixture.Create(format: IsbnFormat.Isbn10)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(isbns.Count, results.Count());
|
||||
|
||||
List<IsbnEntity> resultList = [.. results];
|
||||
for (int i = 0; i < isbns.Count; i++)
|
||||
{
|
||||
Assert.Equal(isbns[i].Value, resultList[i].Value);
|
||||
Assert.Equal(isbns[i].Format, resultList[i].Format);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingEmptyCollection_ShouldReturnEmptyCollection()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns = [];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Empty(results);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WrittenContentMetadataDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WrittenContentMetadataDtoMappingTests
|
||||
{
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingCompleteWrittenContentMetadataDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(dto.Title, result.Value.Title);
|
||||
Assert.True(result.Value.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, result.Value.OriginalTitle.Value);
|
||||
Assert.True(result.Value.Description.HasValue);
|
||||
Assert.Equal(dto.Description, result.Value.Description.Value);
|
||||
Assert.Equal(dto.Genres!.Count, result.Value.Genres.Count);
|
||||
Assert.Equal(dto.Tags!.Count, result.Value.Tags.Count);
|
||||
Assert.True(result.Value.Language.HasValue);
|
||||
Assert.Equal(dto.Language!.LanguageCode!.ToLowerInvariant(), result.Value.Language.Value.LanguageCode);
|
||||
Assert.True(result.Value.OriginalLanguage.HasValue);
|
||||
Assert.Equal(dto.OriginalLanguage!.LanguageCode!.ToLowerInvariant(), result.Value.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.True(result.Value.Publisher.HasValue);
|
||||
Assert.Equal(dto.Publisher, result.Value.Publisher.Value);
|
||||
Assert.True(result.Value.PageCount.HasValue);
|
||||
Assert.Equal(dto.PageCount!.Value, result.Value.PageCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenOptionalValuesAreMissing_ShouldMapWithoutOptionalValues()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(
|
||||
includeOriginalTitle: false,
|
||||
includeDescription: false,
|
||||
includeLanguage: false,
|
||||
includeOriginalLanguage: false,
|
||||
includePublisher: false,
|
||||
includePageCount: false);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.OriginalTitle.HasValue);
|
||||
Assert.False(result.Value.Description.HasValue);
|
||||
Assert.False(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
Assert.False(result.Value.Publisher.HasValue);
|
||||
Assert.False(result.Value.PageCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenReleaseInfoCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(
|
||||
releaseInfo: _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2025, 1, 1),
|
||||
originalReleaseYear: 2024));
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenGenreCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: "")]);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenTagCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: "")]);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user