Replaces ErrorOr library with a custom implementation.

This commit is contained in:
BinaryAlley committed 2026-08-14 03:04:28 -07:00
1 parent 8fe90a4dde
commit 3b772d68ca
436 files changed
+4234 -3922

No files matched your search

@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -45,7 +45,7 @@ public class DomainLibraryFixture
"F:/Content"
];
ErrorOr<Library> library = Library.Create(
Result<Library> library = Library.Create(
UserId.CreateUnique(),
_faker.Random.String2(_faker.Random.Number(1, 50)),
_faker.PickRandom<LibraryType>(),
@@ -76,7 +76,7 @@ public class DomainLibraryFixture
bool shouldSkipUnchangedDirectoriesDuringScan = false,
IEnumerable<Guid>? scanIds = null)
{
ErrorOr<Library> library = id is null ?
Result<Library> library = id is null ?
Library.Create(
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
@@ -12,8 +11,9 @@ using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.Books
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -66,10 +66,10 @@ public class AddBookCommandHandlerTests
.Returns(Result.Created);
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsType<BookResponse>(result.Value);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -85,10 +85,10 @@ public class AddBookCommandHandlerTests
.Returns(Errors.WrittenContent.BookAlreadyExists);
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(Errors.WrittenContent.BookAlreadyExists, result.Errors);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -102,10 +102,10 @@ public class AddBookCommandHandlerTests
bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] };
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -119,10 +119,10 @@ public class AddBookCommandHandlerTests
bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] };
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.RatingValueMustBePositive.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -142,10 +142,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -165,10 +165,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.TagNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -195,10 +195,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -218,10 +218,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -241,10 +241,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -409,7 +409,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = string.Empty } : genre).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = string.Empty } : genre)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -423,7 +423,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(51) } : genre).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(51) } : genre)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -441,7 +441,7 @@ public class AddBookCommandValidatorTests
{
Metadata = bookCommand.Metadata! with
{
Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(50) } : genre).ToList()
Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(50) } : genre)]
}
};
@@ -471,7 +471,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = string.Empty } : tag).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = string.Empty } : tag)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -485,7 +485,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(51) } : tag).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(51) } : tag)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -503,7 +503,7 @@ public class AddBookCommandValidatorTests
{
Metadata = bookCommand.Metadata! with
{
Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(50) } : tag).ToList()
Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(50) } : tag)]
}
};
@@ -1569,7 +1569,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null! } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null! } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1583,7 +1583,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1597,7 +1597,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1611,7 +1611,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1625,7 +1625,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "0-306-40615-2", Format = IsbnFormat.Isbn10 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "0-306-40615-2", Format = IsbnFormat.Isbn10 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1639,7 +1639,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "978-3-16-148410-0", Format = IsbnFormat.Isbn13 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "978-3-16-148410-0", Format = IsbnFormat.Isbn13 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1667,7 +1667,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1681,7 +1681,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(101) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(101) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1695,7 +1695,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1709,7 +1709,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(101) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(101) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1723,7 +1723,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null! } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null! } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1737,7 +1737,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1751,7 +1751,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = new Faker().Random.String2(51) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = new Faker().Random.String2(51) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1765,7 +1765,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1779,7 +1779,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = new Faker().Random.String2(51) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = new Faker().Random.String2(51) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1807,7 +1807,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1821,7 +1821,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 6, MaxValue = 5 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 6, MaxValue = 5 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1835,7 +1835,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1849,7 +1849,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1865,9 +1865,9 @@ public class AddBookCommandValidatorTests
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with
{
Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating
Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating
with
{ Value = 4, MaxValue = 5, VoteCount = 100 } : rating).ToList()
{ Value = 4, MaxValue = 5, VoteCount = 100 } : rating)]
};
// Act
@@ -1882,7 +1882,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
@@ -9,6 +9,7 @@ using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Boo
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -24,6 +25,8 @@ namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.B
public class BookFixture
{
private readonly Fixture _fixture;
private readonly IsbnFixture _isbnFixture;
private readonly BookRatingFixture _bookRatingFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookFixture"/> class.
@@ -33,6 +36,8 @@ public class BookFixture
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_isbnFixture = new IsbnFixture();
_bookRatingFixture = new BookRatingFixture();
ConfigureCustomDomainTypes();
}
@@ -106,16 +111,8 @@ public class BookFixture
_fixture.Create<Optional<int>>()
).Value);
_fixture.Register(() => Isbn.Create(
_fixture.Create<string>(),
_fixture.Create<IsbnFormat>()
).Value);
_fixture.Register(() => _isbnFixture.CreateIsbn13());
_fixture.Register(() => BookRating.Create(
_fixture.Create<decimal>(),
_fixture.Create<decimal>(),
_fixture.Create<Optional<BookRatingSource>>(),
_fixture.Create<Optional<int>>()
).Value);
_fixture.Register(() => _bookRatingFixture.CreateBookRating());
}
}