Standardizes test conventions and documentation

This commit is contained in:
BinaryAlley committed 2026-08-24 14:20:08 -07:00
1 parent 7aeed04255
commit f42dc709de
190 files changed
+2180 -2814

No files matched your search

@@ -9,6 +9,7 @@ using Lumina.Contracts.Fixtures.Common.Setup;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
@@ -37,8 +38,48 @@ public class AddBookRequestFixture
/// <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>
/// <param name="edition">Optional. The edition of the book.</param>
/// <param name="volumeNumber">Optional. The volume or book number in the series.</param>
/// <param name="series">Optional. The series the book is part of.</param>
/// <param name="asin">Optional. The ASIN of the book.</param>
/// <param name="goodreadsId">Optional. The Goodreads Id of the book.</param>
/// <param name="lccn">Optional. The LCCN of the book.</param>
/// <param name="oclcNumber">Optional. The OCLC number of the book.</param>
/// <param name="openLibraryId">Optional. The Open Library Id of the book.</param>
/// <param name="libraryThingId">Optional. The LibraryThing Id of the book.</param>
/// <param name="googleBooksId">Optional. The Google Books Id of the book.</param>
/// <param name="barnesAndNobleId">Optional. The Barnes and Noble Id of the book.</param>
/// <param name="appleBooksId">Optional. The Apple Books Id of the book.</param>
/// <param name="isbns">Optional. The ISBNs of the book.</param>
/// <param name="contributors">Optional. The contributors of the book.</param>
/// <param name="ratings">Optional. The ratings of the book.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or left <see langword="null"/>.</param>
/// <returns>The created request to add a book.</returns>
public AddBookRequest Create()
public AddBookRequest Create(
Guid? libraryId = null,
string? path = null,
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
string? edition = null,
float? volumeNumber = null,
BookSeriesDto? series = null,
string? asin = null,
string? goodreadsId = null,
string? lccn = null,
string? oclcNumber = null,
string? openLibraryId = null,
string? libraryThingId = null,
string? googleBooksId = null,
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<IsbnDto>? isbns = null,
List<MediaContributorDto>? contributors = null,
List<BookRatingDto>? ratings = null,
bool includeOptionalProperties = true)
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -128,7 +169,7 @@ public class AddBookRequestFixture
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
Faker<WrittenContentMetadataDto> metadataFaker = new Faker<WrittenContentMetadataDto>()
.CustomInstantiator(f => new WrittenContentMetadataDto(
default!,
default,
@@ -210,62 +251,91 @@ public class AddBookRequestFixture
default!,
default!
))
.RuleFor(x => x.LibraryId, _fixture.Create<Guid>())
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Metadata, metadata)
.RuleFor(x => x.Format, _fixture.Create<BookFormat>())
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
.RuleFor(x => x.LCCN, f =>
{
string letters = new([.. Enumerable.Range(0, f.Random.Number(0, 3)).Select(_ => f.Random.Char('a', 'z'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
})
.RuleFor(x => x.OCLCNumber, f =>
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = f.Random.ArrayElement(prefixes);
string number;
switch (prefix)
{
case "ocm":
number = f.Random.String2(8, "0123456789");
break;
case "ocn":
number = f.Random.String2(f.Random.Number(9, 11), "0123456789");
break;
case "on":
number = f.Random.String2(10, "0123456789");
break;
case "(OCoLC)":
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
break;
default:
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return number;
}
return prefix + number;
})
.RuleFor(x => x.OpenLibraryId, f =>
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
})
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.GoogleBooksId, f =>
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
})
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
.RuleFor(x => x.LibraryId, libraryId ?? _fixture.Create<Guid>())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.Metadata, metadata ?? metadataFaker)
.RuleFor(x => x.Format, format ?? (includeOptionalProperties ? _fixture.Create<BookFormat>() : null))
.RuleFor(x => x.Edition, f => edition ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
.RuleFor(x => x.VolumeNumber, volumeNumber ?? (includeOptionalProperties ? (float?)_random.Next(1, 3) : null))
.RuleFor(x => x.Series, series)
.RuleFor(x => x.ASIN, f => asin ?? (includeOptionalProperties ? f.Random.String2(10) : null))
.RuleFor(x => x.GoodreadsId, goodreadsId ?? (includeOptionalProperties ? _random.Next(100000, 500000).ToString() : null))
.RuleFor(x => x.LCCN, f => lccn ?? (includeOptionalProperties ? CreateLccn(f) : null))
.RuleFor(x => x.OCLCNumber, f => oclcNumber ?? (includeOptionalProperties ? CreateOclcNumber(f) : null))
.RuleFor(x => x.OpenLibraryId, f => openLibraryId ?? (includeOptionalProperties ? CreateOpenLibraryId(f) : null))
.RuleFor(x => x.LibraryThingId, f => libraryThingId ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
.RuleFor(x => x.GoogleBooksId, f => googleBooksId ?? (includeOptionalProperties ? CreateGoogleBooksId(f) : null))
.RuleFor(x => x.BarnesAndNobleId, f => barnesAndNobleId ?? (includeOptionalProperties ? f.Random.String2(10, "0123456789") : null))
.RuleFor(x => x.AppleBooksId, f => appleBooksId ?? (includeOptionalProperties ? $"id{f.Random.Number(1, 999999)}" : null))
.RuleFor(p => p.ISBNs, f => isbns ?? (includeOptionalProperties ? isbn.Generate(f.Random.Number(1, 5)) : null))
.RuleFor(p => p.Ratings, f => ratings ?? (includeOptionalProperties ? rating.Generate(f.Random.Number(1, 5)) : null))
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? mediaContributor.Generate(f.Random.Number(1, 5)) : null));
}
/// <summary>
/// Generates a random LCCN (Library of Congress Control Number).
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated LCCN.</returns>
private static string CreateLccn(Faker faker)
{
string letters = new([.. Enumerable.Range(0, faker.Random.Number(0, 3)).Select(_ => faker.Random.Char('a', 'z'))]);
string digits = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
return letters + digits;
}
/// <summary>
/// Generates a random OCLC number (WorldCat identifier).
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated OCLC number.</returns>
private static string CreateOclcNumber(Faker faker)
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = faker.Random.ArrayElement(prefixes);
string number;
switch (prefix)
{
case "ocm":
number = faker.Random.String2(8, "0123456789");
break;
case "ocn":
number = faker.Random.String2(faker.Random.Number(9, 11), "0123456789");
break;
case "on":
number = faker.Random.String2(10, "0123456789");
break;
case "(OCoLC)":
number = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
break;
default:
number = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
return number;
}
return prefix + number;
}
/// <summary>
/// Generates a random Open Library Id.
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated Open Library Id.</returns>
private static string CreateOpenLibraryId(Faker faker)
{
int firstDigit = faker.Random.Number(1, 9);
string remainingDigits = faker.Random.String2(faker.Random.Number(0, 6), "0123456789");
char suffix = faker.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
}
/// <summary>
/// Generates a random Google Books Id.
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated Google Books Id.</returns>
private static string CreateGoogleBooksId(Faker faker)
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[faker.Random.Number(VALID_CHARS.Length - 1)])]);
}
}
@@ -26,7 +26,7 @@ public class GetBooksLiteRequestFixture
/// <param name="perPage">Optional. The maximum number of books to retrieve per page.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <returns>The created <see cref="GetBooksLiteRequest"/>.</returns>
@@ -36,7 +36,7 @@ public class GetBooksLiteRequestFixture
int? perPage = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool ignoreThePrefixForAlphaPicker = false,
bool shouldIgnoreThePrefixForAlphaPicker = false,
string? sortBy = null,
SortOrder? sortOrder = null)
{
@@ -46,7 +46,7 @@ public class GetBooksLiteRequestFixture
PerPage: perPage ?? _faker.Random.Number(1, 200),
SearchTerm: searchTerm ?? _faker.Lorem.Word(),
FilterAlphaKey: filterAlphaKey,
IgnoreThePrefixForAlphaPicker: ignoreThePrefixForAlphaPicker,
ShouldIgnoreThePrefixForAlphaPicker: shouldIgnoreThePrefixForAlphaPicker,
SortBy: sortBy ?? _faker.Lorem.Word(),
SortOrder: sortOrder ?? _faker.PickRandom<SortOrder>()
);