mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Adds book editing tests and parameterizes the shared test fixtures
This commit is contained in:
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>
|
||||
|
||||
+21
-3
@@ -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>
|
||||
|
||||
+13
-5
@@ -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,
|
||||
|
||||
+3
-3
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -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";
|
||||
|
||||
+58
-12
@@ -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)));
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -20,9 +20,11 @@ public class GetDirectoriesRequestFixture
|
||||
/// Creates a <see cref="GetDirectoriesRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path for which to get the directories.</param>
|
||||
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>The created <see cref="GetDirectoriesRequest"/>.</returns>
|
||||
public GetDirectoriesRequest Create(string? path = null, bool? includeHiddenElements = null)
|
||||
public GetDirectoriesRequest Create(
|
||||
string? path = null,
|
||||
bool? includeHiddenElements = null)
|
||||
{
|
||||
return new GetDirectoriesRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
|
||||
+4
-2
@@ -20,9 +20,11 @@ public class GetFilesRequestFixture
|
||||
/// Creates a <see cref="GetFilesRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path for which to get the files.</param>
|
||||
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>The created <see cref="GetFilesRequest"/>.</returns>
|
||||
public GetFilesRequest Create(string? path = null, bool? includeHiddenElements = null)
|
||||
public GetFilesRequest Create(
|
||||
string? path = null,
|
||||
bool? includeHiddenElements = null)
|
||||
{
|
||||
return new GetFilesRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
|
||||
+4
-2
@@ -20,9 +20,11 @@ public class GetTreeFilesRequestFixture
|
||||
/// Creates a <see cref="GetTreeFilesRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path for which to get the tree files.</param>
|
||||
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>The created <see cref="GetTreeFilesRequest"/>.</returns>
|
||||
public GetTreeFilesRequest Create(string? path = null, bool? includeHiddenElements = null)
|
||||
public GetTreeFilesRequest Create(
|
||||
string? path = null,
|
||||
bool? includeHiddenElements = null)
|
||||
{
|
||||
return new GetTreeFilesRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
|
||||
+4
-2
@@ -20,9 +20,11 @@ public class CheckPathExistsRequestFixture
|
||||
/// Creates a <see cref="CheckPathExistsRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The path to check.</param>
|
||||
/// <param name="includeHiddenElements">Optional. Whether to include hidden elements.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>The created <see cref="CheckPathExistsRequest"/>.</returns>
|
||||
public CheckPathExistsRequest Create(string? path = null, bool? includeHiddenElements = null)
|
||||
public CheckPathExistsRequest Create(
|
||||
string? path = null,
|
||||
bool? includeHiddenElements = null)
|
||||
{
|
||||
return new CheckPathExistsRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
|
||||
+17
-174
@@ -1,14 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Fixtures.Common.Setup;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -23,18 +22,10 @@ namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLib
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestFixture
|
||||
{
|
||||
private readonly Fixture _fixture = new();
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookRequestFixture"/> class.
|
||||
/// </summary>
|
||||
public AddBookRequestFixture()
|
||||
{
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
}
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid request to add a book.
|
||||
@@ -58,7 +49,7 @@ public class AddBookRequestFixture
|
||||
/// <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>
|
||||
/// <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,
|
||||
@@ -82,154 +73,6 @@ public class AddBookRequestFixture
|
||||
List<BookRatingDto>? ratings = null,
|
||||
bool includeOptionalProperties = true)
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoDto releaseInfo = new Faker<ReleaseInfoDto>()
|
||||
.CustomInstantiator(f => new ReleaseInfoDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
|
||||
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
|
||||
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
|
||||
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreDto> genre = new Faker<GenreDto>()
|
||||
.CustomInstantiator(f => new GenreDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagDto> tag = new Faker<TagDto>()
|
||||
.CustomInstantiator(f => new TagDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleDto> mediaContributorRole = new Faker<MediaContributorRoleDto>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.PickRandom<MediaContributorRoleCategory>());
|
||||
|
||||
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
|
||||
.CustomInstantiator(f => new BookRatingDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.Value, _random.Next(1, 5))
|
||||
.RuleFor(e => e.MaxValue, 5)
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoDto> originalLanguage = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataDto> metadataFaker = new Faker<WrittenContentMetadataDto>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataDto(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.ReleaseInfo, releaseInfo)
|
||||
.RuleFor(p => p.Genres, f => genre.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Tags, f => tag.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Language, language)
|
||||
.RuleFor(x => x.OriginalLanguage, originalLanguage)
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnDto> isbn = new Faker<IsbnDto>()
|
||||
.CustomInstantiator(f => new IsbnDto(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(i => i.Value, f =>
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
{
|
||||
string prefix = f.Random.Bool() ? "978" : "979";
|
||||
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = f.Random.Number(0, 9);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
})
|
||||
.RuleFor(i => i.Format, (f, i) => i.Value!.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
|
||||
|
||||
return new Faker<AddBookRequest>()
|
||||
.CustomInstantiator(f => new AddBookRequest(
|
||||
default,
|
||||
@@ -246,21 +89,21 @@ public class AddBookRequestFixture
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.LibraryId, libraryId ?? _fixture.Create<Guid>())
|
||||
.RuleFor(x => x.LibraryId, libraryId ?? Guid.NewGuid())
|
||||
.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.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))
|
||||
.RuleFor(x => x.VolumeNumber, volumeNumber ?? (includeOptionalProperties ? (float?)_random.Next(1, 3) : null))
|
||||
.RuleFor(x => x.VolumeNumber, f => volumeNumber ?? (includeOptionalProperties ? (float?)f.Random.Number(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.GoodreadsId, f => goodreadsId ?? (includeOptionalProperties ? f.Random.Number(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))
|
||||
@@ -268,9 +111,9 @@ public class AddBookRequestFixture
|
||||
.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));
|
||||
.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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+7
-3
@@ -29,6 +29,8 @@ public class GetBooksLiteRequestFixture
|
||||
/// <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>
|
||||
/// <param name="includeCurrentPage">Whether the current page should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePerPage">Whether the per page count should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetBooksLiteRequest"/>.</returns>
|
||||
public GetBooksLiteRequest Create(
|
||||
Guid? libraryId = null,
|
||||
@@ -38,12 +40,14 @@ public class GetBooksLiteRequestFixture
|
||||
string? filterAlphaKey = null,
|
||||
bool shouldIgnoreThePrefixForAlphaPicker = false,
|
||||
string? sortBy = null,
|
||||
SortOrder? sortOrder = null)
|
||||
SortOrder? sortOrder = null,
|
||||
bool includeCurrentPage = true,
|
||||
bool includePerPage = true)
|
||||
{
|
||||
return new GetBooksLiteRequest(
|
||||
LibraryId: libraryId ?? _faker.Random.Guid(),
|
||||
CurrentPage: currentPage ?? _faker.Random.Number(1, 100),
|
||||
PerPage: perPage ?? _faker.Random.Number(1, 200),
|
||||
CurrentPage: includeCurrentPage ? (currentPage ?? _faker.Random.Number(1, 100)) : null,
|
||||
PerPage: includePerPage ? (perPage ?? _faker.Random.Number(1, 200)) : null,
|
||||
SearchTerm: searchTerm ?? _faker.Lorem.Word(),
|
||||
FilterAlphaKey: filterAlphaKey,
|
||||
ShouldIgnoreThePrefixForAlphaPicker: shouldIgnoreThePrefixForAlphaPicker,
|
||||
|
||||
+7
-3
@@ -27,6 +27,8 @@ public class GetBooksRequestFixture
|
||||
/// <param name="searchTerm">Optional. The search term used to filter results.</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>
|
||||
/// <param name="includeCurrentPage">Whether the current page should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePerPage">Whether the per page count should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetBooksRequest"/>.</returns>
|
||||
public GetBooksRequest Create(
|
||||
Guid? libraryId = null,
|
||||
@@ -34,12 +36,14 @@ public class GetBooksRequestFixture
|
||||
int? perPage = null,
|
||||
string? searchTerm = null,
|
||||
string? sortBy = null,
|
||||
SortOrder? sortOrder = null)
|
||||
SortOrder? sortOrder = null,
|
||||
bool includeCurrentPage = true,
|
||||
bool includePerPage = true)
|
||||
{
|
||||
return new GetBooksRequest(
|
||||
LibraryId: libraryId ?? _faker.Random.Guid(),
|
||||
CurrentPage: currentPage ?? _faker.Random.Number(1, 100),
|
||||
PerPage: perPage ?? _faker.Random.Number(1, 200),
|
||||
CurrentPage: includeCurrentPage ? (currentPage ?? _faker.Random.Number(1, 100)) : null,
|
||||
PerPage: includePerPage ? (perPage ?? _faker.Random.Number(1, 200)) : null,
|
||||
SearchTerm: searchTerm ?? _faker.Lorem.Word(),
|
||||
SortBy: sortBy ?? _faker.Lorem.Word(),
|
||||
SortOrder: sortOrder ?? _faker.PickRandom<SortOrder>()
|
||||
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
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
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UpdateBookRequest"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookRequestFixture
|
||||
{
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid request to update a book.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the book to update.</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 forced to <see langword="null"/>.</param>
|
||||
/// <param name="rawId">Optional. The raw string value of the Id of the book to update. Takes precedence over <paramref name="id"/>.</param>
|
||||
/// <param name="includeId">Whether the Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created request to update a book.</returns>
|
||||
public UpdateBookRequest Create(
|
||||
Guid? id = 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,
|
||||
string? rawId = null,
|
||||
bool includeId = true)
|
||||
{
|
||||
return new Faker<UpdateBookRequest>()
|
||||
.CustomInstantiator(f => new UpdateBookRequest(
|
||||
default,
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.Id, f => includeId ? (rawId ?? id?.ToString() ?? Guid.NewGuid().ToString()) : null)
|
||||
.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))
|
||||
.RuleFor(x => x.VolumeNumber, f => volumeNumber ?? (includeOptionalProperties ? (float?)f.Random.Number(1, 3) : null))
|
||||
.RuleFor(x => x.Series, series)
|
||||
.RuleFor(x => x.ASIN, f => asin ?? (includeOptionalProperties ? f.Random.String2(10) : null))
|
||||
.RuleFor(x => x.GoodreadsId, f => goodreadsId ?? (includeOptionalProperties ? f.Random.Number(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 ? [.. _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));
|
||||
}
|
||||
|
||||
/// <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)])]);
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -24,18 +24,22 @@ public class BookLiteResponseFixture
|
||||
/// <param name="title">Optional. The title of the book.</param>
|
||||
/// <param name="releaseYear">Optional. The release year of the book.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the cover of the book.</param>
|
||||
/// <param name="includeReleaseYear">Whether the release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="BookLiteResponse"/>.</returns>
|
||||
public BookLiteResponse Create(
|
||||
Guid? id = null,
|
||||
string? title = null,
|
||||
int? releaseYear = null,
|
||||
string? coverPath = null)
|
||||
string? coverPath = null,
|
||||
bool includeReleaseYear = true,
|
||||
bool includeCoverPath = true)
|
||||
{
|
||||
return new BookLiteResponse(
|
||||
id ?? Guid.NewGuid(),
|
||||
title ?? _faker.Commerce.ProductName(),
|
||||
releaseYear ?? _faker.Random.Int(1900, 2024),
|
||||
coverPath ?? _faker.System.FilePath()
|
||||
includeReleaseYear ? (releaseYear ?? _faker.Random.Int(1900, 2024)) : null,
|
||||
includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -28,10 +28,10 @@ public class ThemeResponseFixture
|
||||
/// <param name="author">Optional. The author of the theme.</param>
|
||||
/// <param name="version">Optional. The version of the theme.</param>
|
||||
/// <param name="previewPath">Optional. The preview image path of the theme, or <see langword="null"/> when the theme has no preview.</param>
|
||||
/// <param name="includePreviewPath">Whether to set <paramref name="previewPath"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="includePreviewPath">Whether the preview path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="installSource">Optional. The source the theme was installed from.</param>
|
||||
/// <param name="isCurrent">Optional. Whether the theme is the currently active one.</param>
|
||||
/// <param name="includeIsCurrent">Whether to set <paramref name="isCurrent"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="includeIsCurrent">Whether the currently active flag should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="installedAtUtc">Optional. The UTC timestamp when the theme was installed.</param>
|
||||
/// <param name="isDeleted">Optional. Whether the theme was deleted by the user.</param>
|
||||
/// <returns>The created <see cref="ThemeResponse"/>.</returns>
|
||||
|
||||
Reference in new issue
Block a user