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
@@ -267,6 +267,24 @@ public class StubApiHttpClient : IApiHttpClient
|
||||
throw new InvalidOperationException($"No PUT response is registered for the endpoint '{endpoint}'.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload.</param>
|
||||
/// <param name="fileName">The name of the file to upload.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
public Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
PutRequests.Add((endpoint, fileName));
|
||||
if (_putResponseFactories.TryGetValue(endpoint, out Func<object, object>? responseFactory))
|
||||
return Task.FromResult((TResponse)responseFactory(fileName));
|
||||
throw new InvalidOperationException($"No PUT response is registered for the endpoint '{endpoint}'.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GenreDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GenreDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the genre.</param>
|
||||
/// <returns>A configured <see cref="GenreDto"/> instance.</returns>
|
||||
public GenreDto Create(string? name = null)
|
||||
{
|
||||
return new GenreDto
|
||||
{
|
||||
Name = name ?? _faker.Lorem.Word()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="GenreDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="GenreDto"/> instances.</returns>
|
||||
public List<GenreDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LanguageInfoDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LanguageInfoDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LanguageInfoDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="languageCode">Optional. The ISO 639-1 two-letter language code.</param>
|
||||
/// <param name="languageName">Optional. The name of the language in English.</param>
|
||||
/// <param name="nativeName">Optional. The native name of the language.</param>
|
||||
/// <returns>A configured <see cref="LanguageInfoDto"/> instance.</returns>
|
||||
public LanguageInfoDto Create(
|
||||
string? languageCode = null,
|
||||
string? languageName = null,
|
||||
string? nativeName = null)
|
||||
{
|
||||
return new LanguageInfoDto
|
||||
{
|
||||
LanguageCode = languageCode ?? _faker.Random.String2(2, "abcdefghijklmnopqrstuvwxyz"),
|
||||
LanguageName = languageName ?? _faker.Address.Country(),
|
||||
NativeName = nativeName ?? _faker.Lorem.Word()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="LanguageInfoDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LanguageInfoDto"/> instances.</returns>
|
||||
public List<LanguageInfoDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ReleaseInfoDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReleaseInfoDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ReleaseInfoDto"/> instance with randomized test data.
|
||||
/// </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>
|
||||
/// <param name="reReleaseDate">Optional. The re-release date of the content.</param>
|
||||
/// <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>
|
||||
/// <returns>A configured <see cref="ReleaseInfoDto"/> instance.</returns>
|
||||
public ReleaseInfoDto Create(
|
||||
DateOnly? originalReleaseDate = null,
|
||||
int? originalReleaseYear = null,
|
||||
DateOnly? reReleaseDate = null,
|
||||
int? reReleaseYear = null,
|
||||
string? releaseCountry = null,
|
||||
string? releaseVersion = null)
|
||||
{
|
||||
int resolvedOriginalReleaseYear = originalReleaseYear ?? (originalReleaseDate?.Year ?? _random.Next(1900, 2026));
|
||||
DateOnly resolvedOriginalReleaseDate = originalReleaseDate ?? new DateOnly(resolvedOriginalReleaseYear, 1, 1);
|
||||
int resolvedReReleaseYear = reReleaseYear ?? (reReleaseDate?.Year ?? _random.Next(resolvedOriginalReleaseYear, resolvedOriginalReleaseYear + 100));
|
||||
DateOnly resolvedReReleaseDate = reReleaseDate ?? new DateOnly(resolvedReReleaseYear, 1, 1);
|
||||
|
||||
return new ReleaseInfoDto
|
||||
{
|
||||
OriginalReleaseDate = resolvedOriginalReleaseDate,
|
||||
OriginalReleaseYear = resolvedOriginalReleaseYear,
|
||||
ReReleaseDate = resolvedReReleaseDate,
|
||||
ReReleaseYear = resolvedReReleaseYear,
|
||||
ReleaseCountry = releaseCountry ?? _faker.Address.CountryCode(),
|
||||
ReleaseVersion = releaseVersion ?? _faker.Random.String2(_faker.Random.Number(1, 50))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ReleaseInfoDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ReleaseInfoDto"/> instances.</returns>
|
||||
public List<ReleaseInfoDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="TagDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="TagDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the tag.</param>
|
||||
/// <returns>A configured <see cref="TagDto"/> instance.</returns>
|
||||
public TagDto Create(string? name = null)
|
||||
{
|
||||
return new TagDto
|
||||
{
|
||||
Name = name ?? _faker.Lorem.Word()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="TagDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="TagDto"/> instances.</returns>
|
||||
public List<TagDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ public class DirectoryDtoFixture
|
||||
/// <param name="path">Optional. The full path to the directory.</param>
|
||||
/// <param name="name">Optional. The name of the directory.</param>
|
||||
/// <param name="items">Optional. The children items of the directory.</param>
|
||||
/// <param name="includeItems">Whether the directory should include children items, or an empty collection.</param>
|
||||
/// <param name="includeItems">Whether the children items should be included, or forced to an empty collection.</param>
|
||||
/// <returns>The created <see cref="DirectoryDto"/>.</returns>
|
||||
public DirectoryDto Create(
|
||||
string? path = null,
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="MediaContributorDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorDtoFixture
|
||||
{
|
||||
private static readonly string[] RoleCategories = ["Author", "Translator", "Illustrator", "Editor", "Narrator"];
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaContributorDto"/> instance with randomized test data.
|
||||
/// </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>
|
||||
/// <returns>A configured <see cref="MediaContributorDto"/> instance.</returns>
|
||||
public MediaContributorDto Create(
|
||||
string? displayName = null,
|
||||
string? legalName = null,
|
||||
string? roleName = null,
|
||||
string? roleCategory = null)
|
||||
{
|
||||
string resolvedRoleCategory = roleCategory ?? _faker.Random.ArrayElement(RoleCategories);
|
||||
return new MediaContributorDto
|
||||
{
|
||||
Name = new MediaContributorNameDto
|
||||
{
|
||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
||||
LegalName = legalName ?? _faker.Name.FullName()
|
||||
},
|
||||
Role = new MediaContributorRoleDto
|
||||
{
|
||||
Name = roleName ?? resolvedRoleCategory.ToLowerInvariant(),
|
||||
Category = resolvedRoleCategory
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="MediaContributorDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaContributorDto"/> instances.</returns>
|
||||
public List<MediaContributorDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -22,8 +22,8 @@ public class PluginSettingsDtoFixture
|
||||
/// Creates a new <see cref="PluginSettingsDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Optional unique identifier of the plugin.</param>
|
||||
/// <param name="includeSettings">Whether to populate the current settings values, or leave them null.</param>
|
||||
/// <param name="includeSchema">Whether to populate the settings schema, or leave it empty.</param>
|
||||
/// <param name="includeSettings">Whether the current settings values should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSchema">Whether the settings schema should be included, or forced to an empty collection.</param>
|
||||
/// <returns>A configured <see cref="PluginSettingsDto"/> instance.</returns>
|
||||
public PluginSettingsDto Create(
|
||||
Guid? pluginId = null,
|
||||
|
||||
+2
-2
@@ -21,9 +21,9 @@ public class ThemeNavEntryDtoFixture
|
||||
/// </summary>
|
||||
/// <param name="label">Optional label of the entry.</param>
|
||||
/// <param name="url">Optional URL of the link, or <see langword="null"/> for a submenu.</param>
|
||||
/// <param name="includeUrl">Whether to set <paramref name="url"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="includeUrl">Whether the URL should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="cssClass">Optional CSS classes of the link.</param>
|
||||
/// <param name="includeCssClass">Whether to set <paramref name="cssClass"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="includeCssClass">Whether the CSS class should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="children">Optional child links of a submenu.</param>
|
||||
/// <returns>The created <see cref="ThemeNavEntryDto"/>.</returns>
|
||||
public ThemeNavEntryDto Create(
|
||||
|
||||
+2
-2
@@ -28,10 +28,10 @@ public class ThemeResponseDtoFixture
|
||||
/// <param name="author">Optional author of the theme.</param>
|
||||
/// <param name="version">Optional semantic version of the theme.</param>
|
||||
/// <param name="previewPath">Optional 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 source the theme was installed from.</param>
|
||||
/// <param name="isCurrent">Optional value indicating whether the theme is the 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 UTC timestamp at which the theme was installed.</param>
|
||||
/// <param name="isDeleted">Optional value indicating whether the theme was deleted by the user.</param>
|
||||
/// <returns>A configured <see cref="ThemeResponseDto"/> instance.</returns>
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="BookDetailsDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookDetailsDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="BookDetailsDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional Id of the book.</param>
|
||||
/// <param name="libraryId">Optional Id of the media library the book belongs to.</param>
|
||||
/// <param name="path">Optional file system path of the book.</param>
|
||||
/// <param name="metadata">Optional written content metadata of the book.</param>
|
||||
/// <param name="includeMetadata">Whether the written content metadata should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>A configured <see cref="BookDetailsDto"/> instance.</returns>
|
||||
public BookDetailsDto Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
WrittenContentMetadataDto? metadata = null,
|
||||
bool includeMetadata = true)
|
||||
{
|
||||
return new BookDetailsDto
|
||||
{
|
||||
Id = id ?? _faker.Random.Guid(),
|
||||
LibraryId = libraryId ?? _faker.Random.Guid(),
|
||||
Path = path ?? _faker.System.FilePath(),
|
||||
Metadata = metadata ?? (includeMetadata ? _writtenContentMetadataDtoFixture.Create() : null),
|
||||
Format = _faker.PickRandom<BookFormat>(),
|
||||
Edition = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
VolumeNumber = _faker.Random.Number(1, 3),
|
||||
ASIN = _faker.Random.String2(10),
|
||||
GoodreadsId = _faker.Random.Number(100000, 500000).ToString(),
|
||||
LCCN = "n78890351",
|
||||
OCLCNumber = "ocm12345678",
|
||||
OpenLibraryId = "OL123456M",
|
||||
LibraryThingId = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
GoogleBooksId = CreateGoogleBooksId(),
|
||||
BarnesAndNobleId = _faker.Random.String2(10, "0123456789"),
|
||||
AppleBooksId = $"id{_faker.Random.Number(1, 999999)}",
|
||||
ISBNs = [.. _isbnDtoFixture.CreateMany(_faker.Random.Number(1, 3))],
|
||||
Contributors = [.. _mediaContributorDtoFixture.CreateMany(_faker.Random.Number(1, 3))],
|
||||
Ratings = [.. _bookRatingDtoFixture.CreateMany(_faker.Random.Number(1, 3))],
|
||||
MetadataStatus = _faker.Random.String2(_faker.Random.Number(1, 20)),
|
||||
LastMetadataUpdateUtc = _faker.Date.Recent(),
|
||||
MetadataProvider = _faker.Random.String2(_faker.Random.Number(1, 20)),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
UpdatedOnUtc = _faker.Date.Recent(),
|
||||
CoverPath = _faker.System.FilePath()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="BookDetailsDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="BookDetailsDto"/> instances.</returns>
|
||||
public List<BookDetailsDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a valid Google Books Id.
|
||||
/// </summary>
|
||||
/// <returns>The generated Google Books Id.</returns>
|
||||
private string CreateGoogleBooksId()
|
||||
{
|
||||
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[_faker.Random.Number(VALID_CHARS.Length - 1)])]);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="BookRatingDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="BookRatingDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The rating value.</param>
|
||||
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
|
||||
/// <param name="voteCount">Optional. The number of votes the rating is based on.</param>
|
||||
/// <param name="source">Optional. The source of the rating.</param>
|
||||
/// <returns>A configured <see cref="BookRatingDto"/> instance.</returns>
|
||||
public BookRatingDto Create(
|
||||
decimal? value = null,
|
||||
decimal? maxValue = null,
|
||||
int? voteCount = null,
|
||||
BookRatingSource? source = null)
|
||||
{
|
||||
return new BookRatingDto
|
||||
{
|
||||
Value = value ?? _faker.Random.Decimal(1, 5),
|
||||
MaxValue = maxValue ?? 5,
|
||||
VoteCount = voteCount ?? _faker.Random.Number(1, 1000),
|
||||
Source = source ?? _faker.PickRandom<BookRatingSource>()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="BookRatingDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="BookRatingDto"/> instances.</returns>
|
||||
public List<BookRatingDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="BookSeriesDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookSeriesDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="BookSeriesDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="title">Optional. The title of the book series.</param>
|
||||
/// <returns>A configured <see cref="BookSeriesDto"/> instance.</returns>
|
||||
public BookSeriesDto Create(string? title = null)
|
||||
{
|
||||
return new BookSeriesDto
|
||||
{
|
||||
Title = title ?? _faker.Lorem.Sentence(3)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="BookSeriesDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="BookSeriesDto"/> instances.</returns>
|
||||
public List<BookSeriesDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="IsbnDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnDtoFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IsbnDto"/> instance with a random or explicitly requested format.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The ISBN value. If not provided, a valid ISBN is generated.</param>
|
||||
/// <param name="format">Optional. The ISBN format. If not provided, the format is derived from the value.</param>
|
||||
/// <returns>A configured <see cref="IsbnDto"/> instance.</returns>
|
||||
public IsbnDto Create(string? value = null, IsbnFormat? format = null)
|
||||
{
|
||||
string resolvedValue = value ?? (format == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13());
|
||||
return new IsbnDto
|
||||
{
|
||||
Value = resolvedValue,
|
||||
Format = format ?? (resolvedValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="IsbnDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="IsbnDto"/> instances.</returns>
|
||||
public List<IsbnDto> CreateMany(int count = 3)
|
||||
{
|
||||
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];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = _random.Next(0, 10);
|
||||
|
||||
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}";
|
||||
}
|
||||
|
||||
/// <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";
|
||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = _random.Next(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}";
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="WrittenContentMetadataDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WrittenContentMetadataDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="WrittenContentMetadataDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="title">Optional. The title of the written content.</param>
|
||||
/// <param name="originalTitle">Optional. The original title of the written content.</param>
|
||||
/// <param name="description">Optional. A brief description or summary of the written content.</param>
|
||||
/// <param name="releaseInfo">Optional. The release information of the written content.</param>
|
||||
/// <param name="genres">Optional. The genres associated with the written content.</param>
|
||||
/// <param name="tags">Optional. The tags that describe or categorize the written content.</param>
|
||||
/// <param name="language">Optional. The language in which the written content is written.</param>
|
||||
/// <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>
|
||||
/// <returns>A configured <see cref="WrittenContentMetadataDto"/> instance.</returns>
|
||||
public WrittenContentMetadataDto Create(
|
||||
string? title = null,
|
||||
string? originalTitle = null,
|
||||
string? description = null,
|
||||
ReleaseInfoDto? releaseInfo = null,
|
||||
List<GenreDto>? genres = null,
|
||||
List<TagDto>? tags = null,
|
||||
LanguageInfoDto? language = null,
|
||||
LanguageInfoDto? originalLanguage = null,
|
||||
string? publisher = null,
|
||||
int? pageCount = null)
|
||||
{
|
||||
return new WrittenContentMetadataDto
|
||||
{
|
||||
Title = title ?? _faker.Lorem.Sentence(3),
|
||||
OriginalTitle = originalTitle ?? _faker.Lorem.Sentence(3),
|
||||
Description = description ?? _faker.Lorem.Paragraph(),
|
||||
ReleaseInfo = releaseInfo ?? _releaseInfoDtoFixture.Create(),
|
||||
Genres = genres ?? [.. _genreDtoFixture.CreateMany(_faker.Random.Number(1, 3))],
|
||||
Tags = tags ?? [.. _tagDtoFixture.CreateMany(_faker.Random.Number(1, 3))],
|
||||
Language = language ?? _languageInfoDtoFixture.Create(),
|
||||
OriginalLanguage = originalLanguage ?? _languageInfoDtoFixture.Create(),
|
||||
Publisher = publisher ?? _faker.Company.CompanyName(),
|
||||
PageCount = pageCount ?? _faker.Random.Int(100, 1000)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="WrittenContentMetadataDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="WrittenContentMetadataDto"/> instances.</returns>
|
||||
public List<WrittenContentMetadataDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -17,9 +17,11 @@ public class GetDirectoriesRequestFixture
|
||||
/// Creates a new <see cref="GetDirectoriesRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional file system path whose directories are retrieved.</param>
|
||||
/// <param name="includeHiddenElements">Whether hidden file system elements are included or not.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>A configured <see cref="GetDirectoriesRequest"/> instance.</returns>
|
||||
public GetDirectoriesRequest Create(string? path = null, bool includeHiddenElements = false)
|
||||
public GetDirectoriesRequest Create(
|
||||
string? path = null,
|
||||
bool includeHiddenElements = false)
|
||||
{
|
||||
return new GetDirectoriesRequest(
|
||||
Path: path ?? $"/media/{System.Guid.NewGuid():N}",
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GetBookRequest"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBookRequestFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GetBookRequest"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional unique identifier of the book to retrieve.</param>
|
||||
/// <returns>A configured <see cref="GetBookRequest"/> instance.</returns>
|
||||
public GetBookRequest Create(
|
||||
Guid? id = null)
|
||||
{
|
||||
return new GetBookRequest(id?.ToString() ?? Guid.NewGuid().ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetBookRequest"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="GetBookRequest"/> instances.</returns>
|
||||
public List<GetBookRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="UpdateBookRequest"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly BookSeriesDtoFixture _bookSeriesDtoFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly MediaContributorDtoFixture _mediaContributorDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="UpdateBookRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional Id of the book to update.</param>
|
||||
/// <param name="metadata">Optional written content metadata 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>
|
||||
/// <returns>A configured <see cref="UpdateBookRequest"/> instance.</returns>
|
||||
public UpdateBookRequest Create(
|
||||
Guid? id = null,
|
||||
WrittenContentMetadataDto? metadata = null,
|
||||
bool includeOptionalProperties = true)
|
||||
{
|
||||
return new UpdateBookRequest
|
||||
{
|
||||
Id = id?.ToString() ?? Guid.NewGuid().ToString(),
|
||||
Metadata = metadata ?? (includeOptionalProperties ? _writtenContentMetadataDtoFixture.Create() : null),
|
||||
Format = includeOptionalProperties ? _faker.PickRandom<BookFormat>() : null,
|
||||
Edition = includeOptionalProperties ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
VolumeNumber = includeOptionalProperties ? _faker.Random.Number(1, 3) : null,
|
||||
Series = includeOptionalProperties ? _bookSeriesDtoFixture.Create() : null,
|
||||
ASIN = includeOptionalProperties ? _faker.Random.String2(10) : null,
|
||||
GoodreadsId = includeOptionalProperties ? _faker.Random.Number(100000, 500000).ToString() : null,
|
||||
LCCN = includeOptionalProperties ? "n78890351" : null,
|
||||
OCLCNumber = includeOptionalProperties ? "ocm12345678" : null,
|
||||
OpenLibraryId = includeOptionalProperties ? "OL123456M" : null,
|
||||
LibraryThingId = includeOptionalProperties ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
GoogleBooksId = includeOptionalProperties ? CreateGoogleBooksId() : null,
|
||||
BarnesAndNobleId = includeOptionalProperties ? _faker.Random.String2(10, "0123456789") : null,
|
||||
AppleBooksId = includeOptionalProperties ? $"id{_faker.Random.Number(1, 999999)}" : null,
|
||||
ISBNs = includeOptionalProperties ? [.. _isbnDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
|
||||
Contributors = includeOptionalProperties ? [.. _mediaContributorDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null,
|
||||
Ratings = includeOptionalProperties ? [.. _bookRatingDtoFixture.CreateMany(_faker.Random.Number(1, 3))] : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="UpdateBookRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="UpdateBookRequest"/> instances.</returns>
|
||||
public List<UpdateBookRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a valid Google Books Id.
|
||||
/// </summary>
|
||||
/// <returns>The generated Google Books Id.</returns>
|
||||
private string CreateGoogleBooksId()
|
||||
{
|
||||
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[_faker.Random.Number(VALID_CHARS.Length - 1)])]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user