mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 05:01:10 +00:00
Replaces MVC with FastEndpoints in Lumina.Presentation.Api
This commit is contained in:
1 parent
b1a20716df
commit
c7b8bc2f1c
519 files changed
+15329
-8539
No files matched your search
+166
@@ -0,0 +1,166 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddBookRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestMappingTests
|
||||
{
|
||||
private readonly AddBookRequestFixture _requestFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public AddBookRequestMappingTests()
|
||||
{
|
||||
_requestFixture = new AddBookRequestFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = _requestFixture.CreateRequestBook();
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Metadata.Should().BeEquivalentTo(request.Metadata);
|
||||
result.Format.Should().Be(request.Format);
|
||||
result.Edition.Should().Be(request.Edition);
|
||||
result.VolumeNumber.Should().Be(request.VolumeNumber);
|
||||
result.Series.Should().BeEquivalentTo(request.Series);
|
||||
result.ASIN.Should().Be(request.ASIN);
|
||||
result.GoodreadsId.Should().Be(request.GoodreadsId);
|
||||
result.LCCN.Should().Be(request.LCCN);
|
||||
result.OCLCNumber.Should().Be(request.OCLCNumber);
|
||||
result.OpenLibraryId.Should().Be(request.OpenLibraryId);
|
||||
result.LibraryThingId.Should().Be(request.LibraryThingId);
|
||||
result.GoogleBooksId.Should().Be(request.GoogleBooksId);
|
||||
result.BarnesAndNobleId.Should().Be(request.BarnesAndNobleId);
|
||||
result.AppleBooksId.Should().Be(request.AppleBooksId);
|
||||
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
|
||||
result.Contributors.Should().BeEquivalentTo(request.Contributors);
|
||||
result.Ratings.Should().BeEquivalentTo(request.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
Metadata: new WrittenContentMetadataEntity(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: null,
|
||||
Contributors: null,
|
||||
Ratings: null);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Metadata.Should().BeEquivalentTo(request.Metadata);
|
||||
result.Format.Should().BeNull();
|
||||
result.Edition.Should().BeNull();
|
||||
result.VolumeNumber.Should().BeNull();
|
||||
result.Series.Should().BeNull();
|
||||
result.ASIN.Should().BeNull();
|
||||
result.GoodreadsId.Should().BeNull();
|
||||
result.LCCN.Should().BeNull();
|
||||
result.OCLCNumber.Should().BeNull();
|
||||
result.OpenLibraryId.Should().BeNull();
|
||||
result.LibraryThingId.Should().BeNull();
|
||||
result.GoogleBooksId.Should().BeNull();
|
||||
result.BarnesAndNobleId.Should().BeNull();
|
||||
result.AppleBooksId.Should().BeNull();
|
||||
result.ISBNs.Should().BeNull();
|
||||
result.Contributors.Should().BeNull();
|
||||
result.Ratings.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
Metadata: new WrittenContentMetadataEntity(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
Contributors:
|
||||
[
|
||||
new(
|
||||
new MediaContributorNameEntity("John Doe", "John Smith Doe"),
|
||||
new MediaContributorRoleEntity("Author", "Writing")
|
||||
)
|
||||
],
|
||||
Ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)]);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
|
||||
result.Contributors.Should().BeEquivalentTo(request.Contributors);
|
||||
result.Ratings.Should().BeEquivalentTo(request.Ratings);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookMappingTests
|
||||
{
|
||||
private readonly DomainBookFixture _bookFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookMappingTests()
|
||||
{
|
||||
_bookFixture = new DomainBookFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBook_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.CreateDomainBook();
|
||||
|
||||
// Act
|
||||
BookEntity result = book.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(book.Id.Value);
|
||||
result.Title.Should().Be(book.Metadata.Title);
|
||||
result.OriginalTitle.Should().Be(book.Metadata.OriginalTitle.HasValue ? book.Metadata.OriginalTitle.Value : null);
|
||||
result.Description.Should().Be(book.Metadata.Description.HasValue ? book.Metadata.Description.Value : null);
|
||||
result.OriginalReleaseDate.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null);
|
||||
result.OriginalReleaseYear.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null);
|
||||
result.ReReleaseDate.Should().Be(book.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? book.Metadata.ReleaseInfo.ReReleaseDate.Value : null);
|
||||
result.ReReleaseYear.Should().Be(book.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? book.Metadata.ReleaseInfo.ReReleaseYear.Value : null);
|
||||
result.ReleaseCountry.Should().Be(book.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? book.Metadata.ReleaseInfo.ReleaseCountry.Value : null);
|
||||
result.ReleaseVersion.Should().Be(book.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? book.Metadata.ReleaseInfo.ReleaseVersion.Value : null);
|
||||
result.LanguageCode.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageCode : null);
|
||||
result.LanguageName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageName : null);
|
||||
result.LanguageNativeName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.NativeName.Value : null);
|
||||
result.OriginalLanguageCode.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageCode : null);
|
||||
result.OriginalLanguageName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageName : null);
|
||||
result.OriginalLanguageNativeName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.NativeName.Value : null);
|
||||
result.Tags.Should().BeEquivalentTo(book.Metadata.Tags.ToRepositoryEntities());
|
||||
result.Genres.Should().BeEquivalentTo(book.Metadata.Genres.ToRepositoryEntities());
|
||||
result.Publisher.Should().Be(book.Metadata.Publisher.HasValue ? book.Metadata.Publisher.Value : null);
|
||||
result.PageCount.Should().Be(book.Metadata.PageCount.HasValue ? book.Metadata.PageCount.Value : null);
|
||||
result.Format.Should().Be(book.Format.ToString());
|
||||
result.Edition.Should().Be(book.Edition.HasValue ? book.Edition.Value : null);
|
||||
result.VolumeNumber.Should().Be(book.VolumeNumber.HasValue ? book.VolumeNumber.Value : null);
|
||||
result.ASIN.Should().Be(book.ASIN.HasValue ? book.ASIN.Value : null);
|
||||
result.GoodreadsId.Should().Be(book.GoodreadsId.HasValue ? book.GoodreadsId.Value : null);
|
||||
result.LCCN.Should().Be(book.LCCN.HasValue ? book.LCCN.Value : null);
|
||||
result.OCLCNumber.Should().Be(book.OCLCNumber.HasValue ? book.OCLCNumber.Value : null);
|
||||
result.OpenLibraryId.Should().Be(book.OpenLibraryId.HasValue ? book.OpenLibraryId.Value : null);
|
||||
result.LibraryThingId.Should().Be(book.LibraryThingId.HasValue ? book.LibraryThingId.Value : null);
|
||||
result.GoogleBooksId.Should().Be(book.GoogleBooksId.HasValue ? book.GoogleBooksId.Value : null);
|
||||
result.BarnesAndNobleId.Should().Be(book.BarnesAndNobleId.HasValue ? book.BarnesAndNobleId.Value : null);
|
||||
result.AppleBooksId.Should().Be(book.AppleBooksId.HasValue ? book.AppleBooksId.Value : null);
|
||||
result.ISBNs.Should().BeEquivalentTo(book.ISBNs.ToRepositoryEntities());
|
||||
result.Ratings.Should().BeEquivalentTo(book.Ratings.ToRepositoryEntities());
|
||||
result.Created.Should().Be(book.Created);
|
||||
result.Updated.Should().Be(book.Updated.HasValue ? book.Updated.Value : null);
|
||||
}
|
||||
}
|
||||
+350
@@ -0,0 +1,350 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookModelMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookModelMappingTests
|
||||
{
|
||||
private readonly BookEntityFixture _bookEntityFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookModelMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookModelMappingTests()
|
||||
{
|
||||
_bookEntityFixture = new BookEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingValidBookEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.CreateBook();
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = bookEntity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Id.Value.Should().Be(bookEntity.Id);
|
||||
result.Value.Metadata.Title.Should().Be(bookEntity.Title);
|
||||
|
||||
if (bookEntity.OriginalTitle is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalTitle.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalTitle.Value.Should().Be(bookEntity.OriginalTitle);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalTitle.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.Description is not null)
|
||||
{
|
||||
result.Value.Metadata.Description.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Description.Value.Should().Be(bookEntity.Description);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Description.HasValue.Should().BeFalse();
|
||||
if (bookEntity.OriginalReleaseDate.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value.Should().Be(bookEntity.OriginalReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OriginalReleaseYear.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value.Should().Be(bookEntity.OriginalReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReReleaseDate.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value.Should().Be(bookEntity.ReReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReReleaseYear.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value.Should().Be(bookEntity.ReReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReleaseCountry is not null)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value.Should().Be(bookEntity.ReleaseCountry);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReleaseVersion is not null)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value.Should().Be(bookEntity.ReleaseVersion);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LanguageCode is not null)
|
||||
{
|
||||
result.Value.Metadata.Language.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Language.Value.LanguageCode.Should().Be(bookEntity.LanguageCode);
|
||||
result.Value.Metadata.Language.Value.LanguageName.Should().Be(bookEntity.LanguageName);
|
||||
|
||||
if (bookEntity.LanguageNativeName is not null)
|
||||
{
|
||||
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Language.Value.NativeName.Value.Should().Be(bookEntity.LanguageNativeName);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeFalse();
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Language.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OriginalLanguageCode is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalLanguage.Value.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
|
||||
result.Value.Metadata.OriginalLanguage.Value.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
|
||||
|
||||
if (bookEntity.OriginalLanguageNativeName is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.Value.Should().Be(bookEntity.OriginalLanguageNativeName);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeFalse();
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.Publisher is not null)
|
||||
{
|
||||
result.Value.Metadata.Publisher.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Publisher.Value.Should().Be(bookEntity.Publisher);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Publisher.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.PageCount.HasValue)
|
||||
{
|
||||
result.Value.Metadata.PageCount.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.PageCount.Value.Should().Be(bookEntity.PageCount.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.PageCount.HasValue.Should().BeFalse();
|
||||
|
||||
result.Value.Format.Value.Should().Be(Enum.Parse<BookFormat>(bookEntity.Format));
|
||||
|
||||
if (bookEntity.Edition is not null)
|
||||
{
|
||||
result.Value.Edition.HasValue.Should().BeTrue();
|
||||
result.Value.Edition.Value.Should().Be(bookEntity.Edition);
|
||||
}
|
||||
else
|
||||
result.Value.Edition.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.VolumeNumber.HasValue)
|
||||
{
|
||||
result.Value.VolumeNumber.HasValue.Should().BeTrue();
|
||||
result.Value.VolumeNumber.Value.Should().Be(bookEntity.VolumeNumber.Value);
|
||||
}
|
||||
else
|
||||
result.Value.VolumeNumber.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ASIN is not null)
|
||||
{
|
||||
result.Value.ASIN.HasValue.Should().BeTrue();
|
||||
result.Value.ASIN.Value.Should().Be(bookEntity.ASIN);
|
||||
}
|
||||
else
|
||||
result.Value.ASIN.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.GoodreadsId is not null)
|
||||
{
|
||||
result.Value.GoodreadsId.HasValue.Should().BeTrue();
|
||||
result.Value.GoodreadsId.Value.Should().Be(bookEntity.GoodreadsId);
|
||||
}
|
||||
else
|
||||
result.Value.GoodreadsId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LCCN is not null)
|
||||
{
|
||||
result.Value.LCCN.HasValue.Should().BeTrue();
|
||||
result.Value.LCCN.Value.Should().Be(bookEntity.LCCN);
|
||||
}
|
||||
else
|
||||
result.Value.LCCN.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OCLCNumber is not null)
|
||||
{
|
||||
result.Value.OCLCNumber.HasValue.Should().BeTrue();
|
||||
result.Value.OCLCNumber.Value.Should().Be(bookEntity.OCLCNumber);
|
||||
}
|
||||
else
|
||||
result.Value.OCLCNumber.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OpenLibraryId is not null)
|
||||
{
|
||||
result.Value.OpenLibraryId.HasValue.Should().BeTrue();
|
||||
result.Value.OpenLibraryId.Value.Should().Be(bookEntity.OpenLibraryId);
|
||||
}
|
||||
else
|
||||
result.Value.OpenLibraryId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LibraryThingId is not null)
|
||||
{
|
||||
result.Value.LibraryThingId.HasValue.Should().BeTrue();
|
||||
result.Value.LibraryThingId.Value.Should().Be(bookEntity.LibraryThingId);
|
||||
}
|
||||
else
|
||||
result.Value.LibraryThingId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.GoogleBooksId is not null)
|
||||
{
|
||||
result.Value.GoogleBooksId.HasValue.Should().BeTrue();
|
||||
result.Value.GoogleBooksId.Value.Should().Be(bookEntity.GoogleBooksId);
|
||||
}
|
||||
else
|
||||
result.Value.GoogleBooksId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.BarnesAndNobleId is not null)
|
||||
{
|
||||
result.Value.BarnesAndNobleId.HasValue.Should().BeTrue();
|
||||
result.Value.BarnesAndNobleId.Value.Should().Be(bookEntity.BarnesAndNobleId);
|
||||
}
|
||||
else
|
||||
result.Value.BarnesAndNobleId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.AppleBooksId is not null)
|
||||
{
|
||||
result.Value.AppleBooksId.HasValue.Should().BeTrue();
|
||||
result.Value.AppleBooksId.Value.Should().Be(bookEntity.AppleBooksId);
|
||||
}
|
||||
else
|
||||
result.Value.AppleBooksId.HasValue.Should().BeFalse();
|
||||
|
||||
result.Value.Created.Should().Be(bookEntity.Created);
|
||||
|
||||
if (bookEntity.Updated.HasValue)
|
||||
{
|
||||
result.Value.Updated.HasValue.Should().BeTrue();
|
||||
result.Value.Updated!.Value.Should().Be(bookEntity.Updated.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Updated.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingBookEntity_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.CreateBook();
|
||||
|
||||
// Act
|
||||
BookResponse result = bookEntity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(bookEntity.Id);
|
||||
result.Metadata.Title.Should().Be(bookEntity.Title);
|
||||
result.Metadata.OriginalTitle.Should().Be(bookEntity.OriginalTitle);
|
||||
result.Metadata.Description.Should().Be(bookEntity.Description);
|
||||
result.Metadata.ReleaseInfo!.OriginalReleaseDate.Should().Be(bookEntity.OriginalReleaseDate);
|
||||
result.Metadata.ReleaseInfo.OriginalReleaseYear.Should().Be(bookEntity.OriginalReleaseYear);
|
||||
result.Metadata.ReleaseInfo.ReReleaseDate.Should().Be(bookEntity.ReReleaseDate);
|
||||
result.Metadata.ReleaseInfo.ReReleaseYear.Should().Be(bookEntity.ReReleaseYear);
|
||||
result.Metadata.ReleaseInfo.ReleaseCountry.Should().Be(bookEntity.ReleaseCountry);
|
||||
result.Metadata.ReleaseInfo.ReleaseVersion.Should().Be(bookEntity.ReleaseVersion);
|
||||
result.Metadata.Language.Should().NotBeNull();
|
||||
result.Metadata.Language!.LanguageCode.Should().Be(bookEntity.LanguageCode);
|
||||
result.Metadata.Language.LanguageName.Should().Be(bookEntity.LanguageName);
|
||||
result.Metadata.Language.NativeName.Should().Be(bookEntity.LanguageNativeName);
|
||||
result.Metadata.OriginalLanguage.Should().NotBeNull();
|
||||
result.Metadata.OriginalLanguage!.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
|
||||
result.Metadata.OriginalLanguage.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
|
||||
result.Metadata.OriginalLanguage.NativeName.Should().Be(bookEntity.OriginalLanguageNativeName);
|
||||
result.Metadata.Publisher.Should().Be(bookEntity.Publisher);
|
||||
result.Metadata.PageCount.Should().Be(bookEntity.PageCount);
|
||||
result.Format.Should().Be(Enum.Parse<BookFormat>(bookEntity.Format));
|
||||
result.Edition.Should().Be(bookEntity.Edition);
|
||||
result.VolumeNumber.Should().Be(bookEntity.VolumeNumber);
|
||||
result.ASIN.Should().Be(bookEntity.ASIN);
|
||||
result.GoodreadsId.Should().Be(bookEntity.GoodreadsId);
|
||||
result.LCCN.Should().Be(bookEntity.LCCN);
|
||||
result.OCLCNumber.Should().Be(bookEntity.OCLCNumber);
|
||||
result.OpenLibraryId.Should().Be(bookEntity.OpenLibraryId);
|
||||
result.LibraryThingId.Should().Be(bookEntity.LibraryThingId);
|
||||
result.GoogleBooksId.Should().Be(bookEntity.GoogleBooksId);
|
||||
result.BarnesAndNobleId.Should().Be(bookEntity.BarnesAndNobleId);
|
||||
result.AppleBooksId.Should().Be(bookEntity.AppleBooksId);
|
||||
result.ISBNs.Should().BeEquivalentTo(bookEntity.ISBNs);
|
||||
result.Ratings.Should().BeEquivalentTo(bookEntity.Ratings);
|
||||
result.Created.Should().Be(bookEntity.Created);
|
||||
result.Updated.Should().Be(bookEntity.Updated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities =
|
||||
[
|
||||
_bookEntityFixture.CreateBook(),
|
||||
_bookEntityFixture.CreateBook()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Book>> results = bookEntities.ToDomainModels();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookEntities.Count);
|
||||
results.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities =
|
||||
[
|
||||
_bookEntityFixture.CreateBook(),
|
||||
_bookEntityFixture.CreateBook()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookResponse> results = bookEntities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookEntities.Count);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingMappingTests
|
||||
{
|
||||
private readonly BookRatingFixture _bookRatingFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookRatingMappingTests()
|
||||
{
|
||||
_bookRatingFixture = new BookRatingFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBookRating_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRating();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().Be(bookRating.Source.Value);
|
||||
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutSource_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutSource();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().BeNull();
|
||||
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutVoteCount_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutVoteCount();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().Be(bookRating.Source.Value);
|
||||
result.VoteCount.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleBookRatings_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRating> bookRatings =
|
||||
[
|
||||
_bookRatingFixture.CreateBookRating(),
|
||||
_bookRatingFixture.CreateBookRatingWithoutSource(),
|
||||
_bookRatingFixture.CreateBookRatingWithoutVoteCount()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookRatingEntity> results = bookRatings.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookRatings.Count);
|
||||
|
||||
List<BookRatingEntity> resultList = results.ToList();
|
||||
|
||||
// Complete rating
|
||||
resultList[0].Value.Should().Be(bookRatings[0].Value);
|
||||
resultList[0].MaxValue.Should().Be(bookRatings[0].MaxValue);
|
||||
resultList[0].Source.Should().Be(bookRatings[0].Source.Value);
|
||||
resultList[0].VoteCount.Should().Be(bookRatings[0].VoteCount.Value);
|
||||
|
||||
// Rating without source
|
||||
resultList[1].Value.Should().Be(bookRatings[1].Value);
|
||||
resultList[1].MaxValue.Should().Be(bookRatings[1].MaxValue);
|
||||
resultList[1].Source.Should().BeNull();
|
||||
resultList[1].VoteCount.Should().Be(bookRatings[1].VoteCount.Value);
|
||||
|
||||
// Rating without vote count
|
||||
resultList[2].Value.Should().Be(bookRatings[2].Value);
|
||||
resultList[2].MaxValue.Should().Be(bookRatings[2].MaxValue);
|
||||
resultList[2].Source.Should().Be(bookRatings[2].Source.Value);
|
||||
resultList[2].VoteCount.Should().BeNull();
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingModelMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingModelMappingTests
|
||||
{
|
||||
private readonly BookRatingEntityFixture _bookRatingEntityFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingModelMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookRatingModelMappingTests()
|
||||
{
|
||||
_bookRatingEntityFixture = new BookRatingEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingCompleteBookRatingEntity_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.CreateComplete();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value!.Value);
|
||||
result.Value.MaxValue.Should().Be(entity.MaxValue!.Value);
|
||||
|
||||
if (entity.Source.HasValue)
|
||||
{
|
||||
result.Value.Source.HasValue.Should().BeTrue();
|
||||
result.Value.Source.Value.Should().Be(entity.Source.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Source.HasValue.Should().BeFalse();
|
||||
|
||||
if (entity.VoteCount.HasValue)
|
||||
{
|
||||
result.Value.VoteCount.HasValue.Should().BeTrue();
|
||||
result.Value.VoteCount.Value.Should().Be(entity.VoteCount.Value);
|
||||
}
|
||||
else
|
||||
result.Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingMinimalBookRatingEntity_ShouldMapRequiredPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.CreateMinimal();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value!.Value);
|
||||
result.Value.MaxValue.Should().Be(entity.MaxValue!.Value);
|
||||
result.Value.Source.HasValue.Should().BeFalse();
|
||||
result.Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingInvalidBookRatingEntity_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _bookRatingEntityFixture.CreateInvalid();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities =
|
||||
[
|
||||
_bookRatingEntityFixture.CreateComplete(),
|
||||
_bookRatingEntityFixture.CreateMinimal()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainModels();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<BookRating>> resultList = results.ToList();
|
||||
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
|
||||
// Complete rating
|
||||
resultList[0].Value.Value.Should().Be(entities[0].Value!.Value);
|
||||
resultList[0].Value.MaxValue.Should().Be(entities[0].MaxValue!.Value);
|
||||
resultList[0].Value.Source.Value.Should().Be(entities[0].Source!.Value);
|
||||
resultList[0].Value.VoteCount.Value.Should().Be(entities[0].VoteCount!.Value);
|
||||
|
||||
// Minimal rating
|
||||
resultList[1].Value.Value.Should().Be(entities[1].Value!.Value);
|
||||
resultList[1].Value.MaxValue.Should().Be(entities[1].MaxValue!.Value);
|
||||
resultList[1].Value.Source.HasValue.Should().BeFalse();
|
||||
resultList[1].Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidBookRatingEntities_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities =
|
||||
[
|
||||
_bookRatingEntityFixture.CreateComplete(),
|
||||
_bookRatingEntityFixture.CreateInvalid(),
|
||||
_bookRatingEntityFixture.CreateMinimal()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainModels();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<BookRating>> resultList = results.ToList();
|
||||
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnMappingTests
|
||||
{
|
||||
private readonly IsbnFixture _isbnFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IsbnMappingTests"/> class.
|
||||
/// </summary>
|
||||
public IsbnMappingTests()
|
||||
{
|
||||
_isbnFixture = new IsbnFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn10_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.CreateIsbn10();
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(isbn.Value);
|
||||
result.Format.Should().Be(IsbnFormat.Isbn10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn13_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.CreateIsbn13();
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(isbn.Value);
|
||||
result.Format.Should().Be(IsbnFormat.Isbn13);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleIsbns_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns =
|
||||
[
|
||||
_isbnFixture.CreateIsbn10(),
|
||||
_isbnFixture.CreateIsbn13(),
|
||||
_isbnFixture.CreateIsbn10()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(isbns.Count);
|
||||
|
||||
List<IsbnEntity> resultList = results.ToList();
|
||||
for (int i = 0; i < isbns.Count; i++)
|
||||
{
|
||||
resultList[i].Value.Should().Be(isbns[i].Value);
|
||||
resultList[i].Format.Should().Be(isbns[i].Format);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingEmptyCollection_ShouldReturnEmptyCollection()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns = [];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnModelMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnModelMappingTests
|
||||
{
|
||||
private readonly IsbnEntityFixture _isbnEntityFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IsbnModelMappingTests"/> class.
|
||||
/// </summary>
|
||||
public IsbnModelMappingTests()
|
||||
{
|
||||
_isbnEntityFixture = new IsbnEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingValidIsbn10Entity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.CreateIsbn10();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value);
|
||||
result.Value.Format.Should().Be(entity.Format!.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingValidIsbn13Entity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.CreateIsbn13();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value);
|
||||
result.Value.Format.Should().Be(entity.Format!.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingEntityWithoutFormat_ShouldUseDefaultFormat()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.CreateWithoutFormat();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value);
|
||||
result.Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModel_WhenMappingInvalidIsbnEntity_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.CreateInvalid();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainModel();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
_isbnEntityFixture.CreateIsbn10(),
|
||||
_isbnEntityFixture.CreateIsbn13(),
|
||||
_isbnEntityFixture.CreateWithoutFormat()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainModels();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<Isbn>> resultList = results.ToList();
|
||||
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
|
||||
resultList[0].Value.Value.Should().Be(entities[0].Value);
|
||||
resultList[0].Value.Format.Should().Be(entities[0].Format!.Value);
|
||||
|
||||
resultList[1].Value.Value.Should().Be(entities[1].Value);
|
||||
resultList[1].Value.Format.Should().Be(entities[1].Format!.Value);
|
||||
|
||||
resultList[2].Value.Value.Should().Be(entities[2].Value);
|
||||
resultList[2].Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidIsbnEntities_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
_isbnEntityFixture.CreateIsbn10(),
|
||||
_isbnEntityFixture.CreateInvalid(),
|
||||
_isbnEntityFixture.CreateIsbn13()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainModels();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<Isbn>> resultList = results.ToList();
|
||||
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[0].Value.Value.Should().Be(entities[0].Value);
|
||||
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
resultList[2].Value.Value.Should().Be(entities[2].Value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user