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
+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