Adds book editing tests and parameterizes the shared test fixtures

This commit is contained in:
BinaryAlley committed 2026-09-06 09:37:55 -07:00
1 parent 1bfa07ba5d
commit 145185d715
354 files changed
+7118 -1743

No files matched your search

@@ -22,16 +22,22 @@ public class LanguageInfoDtoFixture
/// <param name="languageCode">Optional. The ISO code of the language.</param>
/// <param name="languageName">Optional. The name of the language in English.</param>
/// <param name="nativeName">Optional. The native name of the language.</param>
/// <param name="includeLanguageCode">Whether the language code should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLanguageName">Whether the language name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeNativeName">Whether the native name should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="LanguageInfoDto"/>.</returns>
public LanguageInfoDto Create(
string? languageCode = null,
string? languageName = null,
string? nativeName = null)
string? languageCode = null,
string? languageName = null,
string? nativeName = null,
bool includeLanguageCode = true,
bool includeLanguageName = true,
bool includeNativeName = true)
{
return new LanguageInfoDto(
languageCode ?? _faker.Random.String2(2),
languageName ?? _faker.Lorem.Word(),
nativeName ?? _faker.Lorem.Word());
includeLanguageCode ? (languageCode ?? _faker.Random.String2(2)) : null,
includeLanguageName ? (languageName ?? _faker.Lorem.Word()) : null,
includeNativeName ? (nativeName ?? _faker.Lorem.Word()) : null);
}
/// <summary>
@@ -15,7 +15,7 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.Common;
public class ReleaseInfoDtoFixture
{
/// <summary>
/// Creates an <see cref="ReleaseInfoDto"/>, preserving the values that are not provided as <see langword="null"/>.
/// Creates a <see cref="ReleaseInfoDto"/>, preserving the values that are not provided as <see langword="null"/>.
/// </summary>
/// <param name="originalReleaseDate">Optional. The original release date of the content.</param>
/// <param name="originalReleaseYear">Optional. The original release year of the content.</param>
@@ -23,6 +23,12 @@ public class ReleaseInfoDtoFixture
/// <param name="reReleaseYear">Optional. The re-release year of the content.</param>
/// <param name="releaseCountry">Optional. The country where the content was released.</param>
/// <param name="releaseVersion">Optional. The version or edition of the content's release.</param>
/// <param name="includeOriginalReleaseDate">Whether the original release date should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOriginalReleaseYear">Whether the original release year should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReReleaseDate">Whether the re-release date should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReReleaseYear">Whether the re-release year should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReleaseCountry">Whether the release country should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReleaseVersion">Whether the release version should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="ReleaseInfoDto"/>.</returns>
public ReleaseInfoDto Create(
DateOnly? originalReleaseDate = null,
@@ -30,15 +36,21 @@ public class ReleaseInfoDtoFixture
DateOnly? reReleaseDate = null,
int? reReleaseYear = null,
string? releaseCountry = null,
string? releaseVersion = null)
string? releaseVersion = null,
bool includeOriginalReleaseDate = true,
bool includeOriginalReleaseYear = true,
bool includeReReleaseDate = true,
bool includeReReleaseYear = true,
bool includeReleaseCountry = true,
bool includeReleaseVersion = true)
{
return new ReleaseInfoDto(
originalReleaseDate,
originalReleaseYear,
reReleaseDate,
reReleaseYear,
releaseCountry,
releaseVersion);
includeOriginalReleaseDate ? originalReleaseDate : null,
includeOriginalReleaseYear ? originalReleaseYear : null,
includeReReleaseDate ? reReleaseDate : null,
includeReReleaseYear ? reReleaseYear : null,
includeReleaseCountry ? releaseCountry : null,
includeReleaseVersion ? releaseVersion : null);
}
/// <summary>
@@ -23,15 +23,33 @@ public class MediaContributorDtoFixture
/// <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="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)
MediaContributorRoleCategory? roleCategory = null,
string? legalName = null,
bool includeName = true,
bool includeDisplayName = true,
bool includeLegalName = true,
bool includeRole = true,
bool includeRoleName = true,
bool includeRoleCategory = true)
{
return new MediaContributorDto(
Name: new MediaContributorNameDto(DisplayName: displayName ?? _faker.Name.FullName(), LegalName: null),
Role: new MediaContributorRoleDto(Name: roleName ?? _faker.Commerce.Department(), Category: roleCategory ?? _faker.PickRandom<MediaContributorRoleCategory>()));
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);
}
/// <summary>
@@ -3,6 +3,7 @@ using Bogus;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.Common;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
@@ -19,6 +20,10 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.
public class BookMetadataDtoFixture
{
private readonly Faker _faker = new();
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
private readonly GenreDtoFixture _genreDtoFixture = new();
private readonly TagDtoFixture _tagDtoFixture = new();
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
/// <summary>
/// Creates a random valid <see cref="BookMetadataDto"/>.
@@ -51,7 +56,7 @@ public class BookMetadataDtoFixture
/// <param name="ratings">Optional. The ratings of the book.</param>
/// <param name="coverImagePath">Optional. The path of the cover image of the book.</param>
/// <param name="includeTitle">Whether the title should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or left <see langword="null"/>.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="BookMetadataDto"/>.</returns>
public BookMetadataDto Create(
string? title = null,
@@ -89,10 +94,13 @@ public class BookMetadataDtoFixture
includeTitle ? title ?? (includeOptionalProperties ? _faker.Lorem.Sentence(3) : null) : null,
originalTitle,
description,
releaseInfo ?? (includeOptionalProperties ? new ReleaseInfoDto(new DateOnly(releaseYear, 1, 1), releaseYear, null, null, _faker.Address.CountryCode(), null) : null),
genres ?? (includeOptionalProperties ? [new GenreDto(_faker.Lorem.Word())] : null),
tags ?? (includeOptionalProperties ? [new TagDto(_faker.Lorem.Word())] : null),
language ?? (includeOptionalProperties ? new LanguageInfoDto("en", "English", "English") : null),
releaseInfo ?? (includeOptionalProperties ? _releaseInfoDtoFixture.Create(
originalReleaseDate: new DateOnly(releaseYear, 1, 1),
originalReleaseYear: releaseYear,
releaseCountry: _faker.Address.CountryCode()) : null),
genres ?? (includeOptionalProperties ? [_genreDtoFixture.Create()] : null),
tags ?? (includeOptionalProperties ? [_tagDtoFixture.Create()] : null),
language ?? (includeOptionalProperties ? _languageInfoDtoFixture.Create() : null),
originalLanguage,
publisher,
pageCount,
@@ -26,7 +26,7 @@ public class BookRatingDtoFixture
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
/// <param name="source">Optional. The rating source.</param>
/// <param name="voteCount">Optional. The number of votes.</param>
/// <param name="includeOptionalProperties">Whether the optional source and vote count should be included.</param>
/// <param name="includeOptionalProperties">Whether the optional source and vote count should be randomized, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="BookRatingDto"/>.</returns>
public BookRatingDto Create(
decimal? value = null,
@@ -38,8 +38,8 @@ public class BookRatingDtoFixture
return new BookRatingDto(
value ?? _random.Next(1, 5),
maxValue ?? 5,
includeOptionalProperties ? (source ?? _fixture.Create<BookRatingSource>()) : null,
includeOptionalProperties ? (voteCount ?? _random.Next(1, 1000)) : null
source ?? (includeOptionalProperties ? _fixture.Create<BookRatingSource>() : null),
voteCount ?? (includeOptionalProperties ? _random.Next(1, 1000) : null)
);
}
@@ -28,7 +28,7 @@ public class IsbnDtoFixture
string resolvedValue = value ?? (format == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13());
return new IsbnDto(
resolvedValue,
format
format ?? (resolvedValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10)
);
}
@@ -42,6 +42,10 @@ public class IsbnDtoFixture
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Generates a valid ISBN-10 with the correct checksum.
/// </summary>
/// <returns>A valid ISBN-10 value.</returns>
private string GenerateValidIsbn10()
{
int[] digits = new int[9];
@@ -58,6 +62,10 @@ public class IsbnDtoFixture
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
}
/// <summary>
/// Generates a valid ISBN-13 with the correct checksum.
/// </summary>
/// <returns>A valid ISBN-13 value.</returns>
private string GenerateValidIsbn13()
{
string prefix = _random.Next(2) == 0 ? "978" : "979";
@@ -1,6 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -14,8 +17,14 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
[ExcludeFromCodeCoverage]
public class WrittenContentMetadataDtoFixture
{
private readonly Faker _faker = new();
private readonly Random _random = new();
private readonly GenreDtoFixture _genreDtoFixture = new();
private readonly TagDtoFixture _tagDtoFixture = new();
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
/// <summary>
/// Creates a <see cref="WrittenContentMetadataDto"/> with the requested values, leaving unspecified properties as <see langword="null"/>.
/// Creates a random valid <see cref="WrittenContentMetadataDto"/>.
/// </summary>
/// <param name="title">Optional. The title of the written content.</param>
/// <param name="originalTitle">Optional. The original title of the written content.</param>
@@ -27,6 +36,16 @@ public class WrittenContentMetadataDtoFixture
/// <param name="originalLanguage">Optional. The original language of the written content.</param>
/// <param name="publisher">Optional. The name of the publisher of the written content.</param>
/// <param name="pageCount">Optional. The number of pages in the written content.</param>
/// <param name="includeTitle">Whether the title should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOriginalTitle">Whether the original title should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReleaseInfo">Whether the release information should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeGenres">Whether the genres should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTags">Whether the tags should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLanguage">Whether the language should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOriginalLanguage">Whether the original language should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePublisher">Whether the publisher should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePageCount">Whether the page count should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="WrittenContentMetadataDto"/>.</returns>
public WrittenContentMetadataDto Create(
string? title = null,
@@ -38,19 +57,29 @@ public class WrittenContentMetadataDtoFixture
LanguageInfoDto? language = null,
LanguageInfoDto? originalLanguage = null,
string? publisher = null,
int? pageCount = null)
int? pageCount = null,
bool includeTitle = true,
bool includeOriginalTitle = true,
bool includeDescription = true,
bool includeReleaseInfo = true,
bool includeGenres = true,
bool includeTags = true,
bool includeLanguage = true,
bool includeOriginalLanguage = true,
bool includePublisher = true,
bool includePageCount = true)
{
return new WrittenContentMetadataDto(
title,
originalTitle,
description,
releaseInfo,
genres,
tags,
language,
originalLanguage,
publisher,
pageCount);
includeTitle ? (title ?? _faker.Commerce.ProductName()) : null,
includeOriginalTitle ? (originalTitle ?? _faker.Commerce.ProductName()) : null,
includeDescription ? (description ?? _faker.Lorem.Paragraph()) : null,
includeReleaseInfo ? (releaseInfo ?? CreateReleaseInfo()) : null,
includeGenres ? (genres ?? [_genreDtoFixture.Create(), _genreDtoFixture.Create()]) : null,
includeTags ? (tags ?? [_tagDtoFixture.Create(), _tagDtoFixture.Create()]) : null,
includeLanguage ? (language ?? _languageInfoDtoFixture.Create()) : null,
includeOriginalLanguage ? (originalLanguage ?? _languageInfoDtoFixture.Create()) : null,
includePublisher ? (publisher ?? _faker.Company.CompanyName()) : null,
includePageCount ? (pageCount ?? _faker.Random.Int(1, 1000)) : null);
}
/// <summary>
@@ -62,4 +91,21 @@ public class WrittenContentMetadataDtoFixture
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates a random valid <see cref="ReleaseInfoDto"/> with consistent dates and years.
/// </summary>
/// <returns>The created <see cref="ReleaseInfoDto"/>.</returns>
private ReleaseInfoDto CreateReleaseInfo()
{
int originalReleaseYear = _random.Next(1900, 2026);
int reReleaseYear = _random.Next(originalReleaseYear, 2026);
return new ReleaseInfoDto(
new DateOnly(originalReleaseYear, 1, 1),
originalReleaseYear,
new DateOnly(reReleaseYear, 1, 1),
reReleaseYear,
_faker.Address.CountryCode(),
_faker.Random.String2(_faker.Random.Number(1, 50)));
}
}