mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11: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
+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)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user