mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 22:11:10 +00:00
Refactors the get books and get books lite slices across the stack
This commit is contained in:
1 parent
001146eefc
commit
1d35cd01db
44 files changed
+1681
-418
No files matched your search
-69
@@ -365,73 +365,4 @@ public class BookEntityMappingTests
|
||||
Assert.Equal(paginatedBookEntities.Count, result.Count);
|
||||
Assert.Equal(paginatedBookEntities.NumberOfPages, result.NumberOfPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToLiteResponse_WhenMappingBookEntity_ShouldMapIdTitleAndReleaseYear()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
BookLiteResponse result = bookEntity.ToLiteResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bookEntity.Id, result.Id);
|
||||
Assert.Equal(bookEntity.Title, result.Title);
|
||||
Assert.Equal(bookEntity.ReReleaseYear ?? bookEntity.OriginalReleaseYear, result.ReleaseYear);
|
||||
Assert.Null(result.CoverPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToLiteResponse_WhenBookHasNoReReleaseYear_ShouldFallBackToOriginalReleaseYear()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.Create();
|
||||
bookEntity.ReReleaseYear = null;
|
||||
|
||||
// Act
|
||||
BookLiteResponse result = bookEntity.ToLiteResponse();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(bookEntity.OriginalReleaseYear, result.ReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToLiteResponses_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<BookLiteResponse> results = bookEntities.ToLiteResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(bookEntities.Count, results.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToLiteResponses_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<BookLiteResponse> result = paginatedBookEntities.ToLiteResponses();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
+43
-7
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookL
|
||||
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
|
||||
|
||||
@@ -21,14 +22,17 @@ public class GetBooksLiteRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery();
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(request.LibraryId, result.Filter.LibraryId);
|
||||
Assert.Equal(request.SearchTerm, result.Filter.SearchTerm);
|
||||
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);
|
||||
@@ -36,19 +40,49 @@ public class GetBooksLiteRequestMappingTests
|
||||
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();
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.PaginationData);
|
||||
Assert.Equal(request.LibraryId, result.Filter.LibraryId);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -56,9 +90,10 @@ public class GetBooksLiteRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create(perPage: 25, includeCurrentPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery();
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
@@ -71,9 +106,10 @@ public class GetBooksLiteRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create(currentPage: 3, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksLiteQuery result = request.ToQuery();
|
||||
GetBooksLiteQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
|
||||
+41
-7
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookL
|
||||
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
|
||||
|
||||
@@ -21,14 +22,15 @@ public class GetBooksRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create();
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery();
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(request.LibraryId, result.Filter.LibraryId);
|
||||
Assert.Equal(request.SearchTerm, result.Filter.SearchTerm);
|
||||
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);
|
||||
@@ -36,19 +38,49 @@ public class GetBooksRequestMappingTests
|
||||
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();
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.PaginationData);
|
||||
Assert.Equal(request.LibraryId, result.Filter.LibraryId);
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -56,9 +88,10 @@ public class GetBooksRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create(perPage: 25, includeCurrentPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery();
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
@@ -71,9 +104,10 @@ public class GetBooksRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksRequest request = _getBooksRequestFixture.Create(currentPage: 3, includePerPage: false);
|
||||
string libraryId = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
GetBooksQuery result = request.ToQuery();
|
||||
GetBooksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.PaginationData);
|
||||
|
||||
Reference in new issue
Block a user