Refactors the add book slice and shared media contributor model across the stack

This commit is contained in:
BinaryAlley committed 2026-09-12 12:12:22 -07:00
1 parent 3a2c80b615
commit 9a71a6d32b
61 files changed
+5223 -1384

No files matched your search

@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
@@ -8,7 +8,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaContributors;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookContributorEntity"/> class.
@@ -24,23 +24,20 @@ public class BookContributorEntityFixture
/// <param name="id">Optional. The Id of the participation.</param>
/// <param name="bookId">Optional. The Id of the book the contributor participated in.</param>
/// <param name="mediaContributorId">Optional. The Id of the media contributor.</param>
/// <param name="roleName">Optional. The display name of the role the contributor played in the book.</param>
/// <param name="roleCategory">Optional. The canonical category of the role the contributor played in the book.</param>
/// <param name="role">Optional. The role the contributor played in the book.</param>
/// <returns>The created <see cref="BookContributorEntity"/>.</returns>
public BookContributorEntity Create(
Guid? id = null,
Guid? bookId = null,
Guid? mediaContributorId = null,
string? roleName = null,
MediaContributorRoleCategory? roleCategory = null)
MediaContributorRole? role = null)
{
return new BookContributorEntity
{
Id = id ?? Guid.NewGuid(),
BookId = bookId ?? Guid.NewGuid(),
MediaContributorId = mediaContributorId ?? Guid.NewGuid(),
RoleName = roleName ?? _faker.Lorem.Word(),
RoleCategory = roleCategory ?? _faker.PickRandom<MediaContributorRoleCategory>(),
Role = role ?? MediaContributorRole.Author,
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = Guid.NewGuid(),
UpdatedOnUtc = null,
@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
using Lumina.Contracts.DTO.MediaContributors;
@@ -11,6 +11,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
@@ -24,7 +25,7 @@ public class AddBookCommandFixture
{
private readonly IsbnDtoFixture _isbnDtoFixture = new();
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
/// <summary>
@@ -53,7 +54,7 @@ public class AddBookCommandFixture
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or forced to <see langword="null"/>.</param>
/// <returns>The created command to add a book.</returns>
public AddBookCommand Create(
Guid? libraryId = null,
string? libraryId = null,
string? path = null,
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
@@ -70,7 +71,7 @@ public class AddBookCommandFixture
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<IsbnDto>? isbns = null,
List<MediaContributorDto>? contributors = null,
List<MediaContributorReferenceDto>? contributors = null,
List<BookRatingDto>? ratings = null,
bool includeMetadata = true,
bool includeOptionalProperties = true)
@@ -97,8 +98,8 @@ public class AddBookCommandFixture
default!,
default!
))
.RuleFor(x => x.LibraryId, libraryId ?? Guid.NewGuid())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.LibraryId, libraryId ?? Guid.NewGuid().ToString())
.RuleFor(x => x.Path, f => path ?? Path.Combine(Path.GetTempPath(), "lumina-books", f.System.FileName()))
.RuleFor(x => x.Metadata, includeMetadata ? (metadata ?? _writtenContentMetadataDtoFixture.Create()) : null)
.RuleFor(x => x.Format, f => format ?? (includeOptionalProperties ? f.PickRandom<BookFormat>() : null))
.RuleFor(x => x.Edition, f => edition ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
@@ -115,7 +116,7 @@ public class AddBookCommandFixture
.RuleFor(x => x.AppleBooksId, f => appleBooksId ?? (includeOptionalProperties ? $"id{f.Random.Number(1, 999999)}" : null))
.RuleFor(p => p.ISBNs, f => isbns ?? (includeOptionalProperties ? [.. _isbnDtoFixture.CreateMany(f.Random.Number(1, 3))] : null))
.RuleFor(p => p.Ratings, f => ratings ?? (includeOptionalProperties ? [.. _bookRatingDtoFixture.CreateMany(f.Random.Number(1, 3))] : null))
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? [.. _mediaContributorDtoFixture.CreateMany(f.Random.Number(1, 3))] : null));
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? [.. _mediaContributorReferenceDtoFixture.CreateMany(f.Random.Number(1, 3))] : null));
}
/// <summary>
@@ -21,35 +21,27 @@ public class MediaContributorDtoFixture
/// Creates a random valid <see cref="MediaContributorDto"/>.
/// </summary>
/// <param name="displayName">Optional. The display name of the media contributor.</param>
/// <param name="roleName">Optional. The name of the role assigned to the media contributor.</param>
/// <param name="roleCategory">Optional. The category of the role.</param>
/// <param name="role">Optional. The canonical role assigned to the media contributor.</param>
/// <param name="legalName">Optional. The legal name of the media contributor.</param>
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeDisplayName">Whether the display name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLegalName">Whether the legal name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeRole">Whether the role should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeRoleName">Whether the role name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeRoleCategory">Whether the role category should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MediaContributorDto"/>.</returns>
public MediaContributorDto Create(
string? displayName = null,
string? roleName = null,
MediaContributorRoleCategory? roleCategory = null,
MediaContributorRole? role = null,
string? legalName = null,
bool includeName = true,
bool includeDisplayName = true,
bool includeLegalName = true,
bool includeRole = true,
bool includeRoleName = true,
bool includeRoleCategory = true)
bool includeRole = true)
{
return new MediaContributorDto(
Name: includeName ? new MediaContributorNameDto(
DisplayName: includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
LegalName: includeLegalName ? legalName : null) : null,
Role: includeRole ? new MediaContributorRoleDto(
Name: includeRoleName ? roleName ?? _faker.Commerce.Department() : null,
Category: includeRoleCategory ? roleCategory ?? _faker.PickRandom<MediaContributorRoleCategory>() : null) : null);
Role: includeRole ? role ?? _faker.PickRandom<MediaContributorRole>() : null);
}
/// <summary>
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
/// <summary>
/// Fixture class for the <see cref="MediaContributorReferenceDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorReferenceDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorReferenceDto"/>.
/// </summary>
/// <param name="contributorId">Optional. The Id of the media contributor.</param>
/// <param name="role">Optional. The role the contributor played.</param>
/// <returns>The created <see cref="MediaContributorReferenceDto"/>.</returns>
public MediaContributorReferenceDto Create(Guid? contributorId = null, MediaContributorRole? role = null)
{
return new MediaContributorReferenceDto(
ContributorId: contributorId ?? Guid.NewGuid(),
Role: role ?? _faker.PickRandom<MediaContributorRole>());
}
/// <summary>
/// Creates a list of <see cref="MediaContributorReferenceDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MediaContributorReferenceDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,44 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
/// <summary>
/// Fixture class for the <see cref="MediaContributorRoleDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorRoleDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorRoleDto"/>.
/// </summary>
/// <param name="name">Optional. The name of the role assigned to the media contributor.</param>
/// <param name="category">Optional. The category of the role.</param>
/// <returns>The created <see cref="MediaContributorRoleDto"/>.</returns>
public MediaContributorRoleDto Create(
string? name = null,
MediaContributorRoleCategory? category = null)
{
return new MediaContributorRoleDto(
name ?? _faker.Commerce.Department(),
category ?? _faker.PickRandom<MediaContributorRoleCategory>());
}
/// <summary>
/// Creates a list of <see cref="MediaContributorRoleDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MediaContributorRoleDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
@@ -11,6 +11,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
@@ -24,13 +25,12 @@ public class AddBookRequestFixture
{
private readonly IsbnDtoFixture _isbnDtoFixture = new();
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
/// <summary>
/// Creates a random valid request to add a book.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the book belongs to.</param>
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="metadata">Optional. The written content metadata of the book.</param>
/// <param name="format">Optional. The format of the book.</param>
@@ -52,7 +52,6 @@ public class AddBookRequestFixture
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or forced to <see langword="null"/>.</param>
/// <returns>The created request to add a book.</returns>
public AddBookRequest Create(
Guid? libraryId = null,
string? path = null,
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
@@ -69,13 +68,12 @@ public class AddBookRequestFixture
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<IsbnDto>? isbns = null,
List<MediaContributorDto>? contributors = null,
List<MediaContributorReferenceDto>? contributors = null,
List<BookRatingDto>? ratings = null,
bool includeOptionalProperties = true)
{
return new Faker<AddBookRequest>()
.CustomInstantiator(f => new AddBookRequest(
default,
default!,
default!,
default,
@@ -95,8 +93,7 @@ public class AddBookRequestFixture
default!,
default!
))
.RuleFor(x => x.LibraryId, libraryId ?? Guid.NewGuid())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.Path, f => path ?? Path.Combine(Path.GetTempPath(), "lumina-books", f.System.FileName()))
.RuleFor(x => x.Metadata, metadata ?? _writtenContentMetadataDtoFixture.Create())
.RuleFor(x => x.Format, f => format ?? (includeOptionalProperties ? f.PickRandom<BookFormat>() : null))
.RuleFor(x => x.Edition, f => edition ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
@@ -113,7 +110,7 @@ public class AddBookRequestFixture
.RuleFor(x => x.AppleBooksId, f => appleBooksId ?? (includeOptionalProperties ? $"id{f.Random.Number(1, 999999)}" : null))
.RuleFor(p => p.ISBNs, f => isbns ?? (includeOptionalProperties ? [.. _isbnDtoFixture.CreateMany(f.Random.Number(1, 3))] : null))
.RuleFor(p => p.Ratings, f => ratings ?? (includeOptionalProperties ? [.. _bookRatingDtoFixture.CreateMany(f.Random.Number(1, 3))] : null))
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? [.. _mediaContributorDtoFixture.CreateMany(f.Random.Number(1, 3))] : null));
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? [.. _mediaContributorReferenceDtoFixture.CreateMany(f.Random.Number(1, 3))] : null));
}
/// <summary>
@@ -24,7 +24,7 @@ public class BookResponseFixture
private readonly Faker _faker = new();
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
private readonly IsbnDtoFixture _isbnDtoFixture = new();
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
private readonly BookSeriesDtoFixture _bookSeriesDtoFixture = new();
@@ -70,7 +70,7 @@ public class BookResponseFixture
_faker.Random.AlphaNumeric(10),
_faker.Random.AlphaNumeric(8),
_isbnDtoFixture.CreateMany(1),
_mediaContributorDtoFixture.CreateMany(1),
_mediaContributorReferenceDtoFixture.CreateMany(1),
_bookRatingDtoFixture.CreateMany(1),
metadataStatus ?? _faker.PickRandom<MetadataStatus>(),
_faker.Date.Recent().ToUniversalTime(),
@@ -1,42 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaContributorRole"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorRoleFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorRole"/>.
/// </summary>
/// <param name="name">Optional. The name of the role. If not provided, a random name is generated.</param>
/// <param name="category">Optional. The category of the role. If not provided, a random category is generated.</param>
/// <returns>The created <see cref="MediaContributorRole"/>.</returns>
public MediaContributorRole Create(string? name = null, MediaContributorRoleCategory? category = null)
{
return MediaContributorRole.Create(
name ?? _faker.Lorem.Word(),
category ?? _faker.PickRandom<MediaContributorRoleCategory>()).Value;
}
/// <summary>
/// Creates multiple <see cref="MediaContributorRole"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaContributorRole"/> instances.</returns>
public List<MediaContributorRole> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
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.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -27,7 +27,6 @@ public class BookFixture
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
private readonly IsbnFixture _isbnFixture = new();
private readonly BookRatingFixture _bookRatingFixture = new();
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="Book"/> domain aggregate.
@@ -70,7 +69,7 @@ public class BookFixture
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<Isbn>? isbns = null,
List<MediaContributorId>? contributors = null,
List<BookMediaContributor>? contributors = null,
List<BookRating>? ratings = null)
{
return Book.Create(
@@ -91,7 +90,7 @@ public class BookFixture
barnesAndNobleId is null ? Optional<string>.Some(_faker.Random.String2(10, "0123456789")) : Optional<string>.Some(barnesAndNobleId),
appleBooksId is null ? Optional<string>.Some($"id{_faker.Random.Number(1, 999999)}") : Optional<string>.Some(appleBooksId),
isbns ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _isbnFixture.Create())],
contributors ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _mediaContributorIdFixture.Create())],
contributors ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => BookMediaContributor.Create(MediaContributorId.CreateUnique(), MediaContributorRole.Author).Value)],
ratings ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _bookRatingFixture.Create())]
).Value;
}
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -14,7 +15,6 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
[ExcludeFromCodeCoverage]
public class MediaContributorDtoFixture
{
private static readonly string[] RoleCategories = ["Author", "Translator", "Illustrator", "Editor", "Narrator"];
private readonly Faker _faker = new();
/// <summary>
@@ -22,16 +22,13 @@ public class MediaContributorDtoFixture
/// </summary>
/// <param name="displayName">Optional. The name by which the contributor is popularly known.</param>
/// <param name="legalName">Optional. The legal name of the contributor.</param>
/// <param name="roleName">Optional. The name of the role of the contributor.</param>
/// <param name="roleCategory">Optional. The category of the role of the contributor.</param>
/// <param name="role">Optional. The canonical role of the contributor.</param>
/// <returns>A configured <see cref="MediaContributorDto"/> instance.</returns>
public MediaContributorDto Create(
string? displayName = null,
string? legalName = null,
string? roleName = null,
string? roleCategory = null)
MediaContributorRole? role = null)
{
string resolvedRoleCategory = roleCategory ?? _faker.Random.ArrayElement(RoleCategories);
return new MediaContributorDto
{
Name = new MediaContributorNameDto
@@ -39,11 +36,7 @@ public class MediaContributorDtoFixture
DisplayName = displayName ?? _faker.Name.FullName(),
LegalName = legalName ?? _faker.Name.FullName()
},
Role = new MediaContributorRoleDto
{
Name = roleName ?? resolvedRoleCategory.ToLowerInvariant(),
Category = resolvedRoleCategory
}
Role = role ?? MediaContributorRole.Author
};
}