mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17: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
+1
-1
@@ -28,7 +28,7 @@ public class FileFixture
|
||||
/// <param name="dateModified">Optional. The file's modification date. If not provided, a recent date is generated.</param>
|
||||
/// <param name="size">Optional. The file size. If not provided, a random size is generated.</param>
|
||||
/// <param name="status">Optional. The file's status. If not provided, a random status is assigned.</param>
|
||||
/// <param name="includeDates">Whether the file should include creation and modification dates.</param>
|
||||
/// <param name="includeDates">Whether the creation and modification dates should be included, or left unset.</param>
|
||||
/// <returns>The created <see cref="File"/>.</returns>
|
||||
public File Create(
|
||||
string? path = null,
|
||||
|
||||
+12
-6
@@ -2,9 +2,11 @@
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -22,6 +24,9 @@ public class LibraryFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly Random _random = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Library"/> domain aggregate.
|
||||
@@ -32,7 +37,7 @@ public class LibraryFixture
|
||||
/// <param name="libraryType">Optional. The library type.</param>
|
||||
/// <param name="contentLocations">Optional. The content locations of the library.</param>
|
||||
/// <param name="coverImage">Optional. The cover image of the library.</param>
|
||||
/// <param name="includeCoverImage">Whether to include a cover image or not.</param>
|
||||
/// <param name="includeCoverImage">Whether the cover image should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="isEnabled">Whether the library is enabled.</param>
|
||||
/// <param name="isLocked">Whether the library is locked.</param>
|
||||
/// <param name="canDownloadMetadataFromWeb">Whether metadata download from the web is enabled.</param>
|
||||
@@ -63,12 +68,13 @@ public class LibraryFixture
|
||||
"F:/Content"
|
||||
];
|
||||
|
||||
List<ScanId> resolvedScanIds = scanIds is null ? [ScanId.CreateUnique(), ScanId.CreateUnique()] : [.. scanIds.Select(scanId => ScanId.Create(scanId))];
|
||||
UserId resolvedUserId = userId is null ? _userIdFixture.Create() : _userIdFixture.Create(userId.Value);
|
||||
List<ScanId> resolvedScanIds = scanIds is null ? [.. _scanIdFixture.CreateMany(2)] : [.. scanIds.Select(scanId => _scanIdFixture.Create(scanId))];
|
||||
string? resolvedCoverImage = includeCoverImage ? (coverImage ?? _faker.System.FilePath()) : null;
|
||||
|
||||
Result<Library> library = id is null ?
|
||||
Library.Create(
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
resolvedUserId,
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? _faker.PickRandom<LibraryType>(),
|
||||
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
|
||||
@@ -81,8 +87,8 @@ public class LibraryFixture
|
||||
resolvedScanIds
|
||||
) :
|
||||
Library.Create(
|
||||
LibraryId.Create(id.Value),
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
_libraryIdFixture.Create(id.Value),
|
||||
resolvedUserId,
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? _faker.PickRandom<LibraryType>(),
|
||||
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class LibraryScanFailedDomainEventFixture
|
||||
/// <param name="mediaLibraryScanCompositeId">Optional. The composite identifier of the media library scan that has failed.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <param name="errorMessage">Optional. The descriptive message of the failure.</param>
|
||||
/// <param name="includeErrorMessage">Whether to include an error message in the domain event. When false, the error message is left unset.</param>
|
||||
/// <param name="includeErrorMessage">Whether the error message should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="LibraryScanFailedDomainEvent"/>.</returns>
|
||||
public LibraryScanFailedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
|
||||
+63
-80
@@ -1,13 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Common.Setup;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
@@ -24,46 +23,76 @@ namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookFixture
|
||||
{
|
||||
private readonly Fixture _fixture = new();
|
||||
private readonly Faker _faker = new();
|
||||
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
|
||||
private readonly IsbnFixture _isbnFixture = new();
|
||||
private readonly BookRatingFixture _bookRatingFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookFixture"/> class.
|
||||
/// </summary>
|
||||
public BookFixture()
|
||||
{
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
ConfigureCustomDomainTypes();
|
||||
}
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Book"/> domain aggregate.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Optional. The Id of the media library this book belongs to.</param>
|
||||
/// <param name="path">Optional. The file system path of the book.</param>
|
||||
/// <param name="metadata">Optional. The written content metadata of the book.</param>
|
||||
/// <param name="format">Optional. The format of the book.</param>
|
||||
/// <param name="edition">Optional. The edition of the book.</param>
|
||||
/// <param name="volumeNumber">Optional. The volume or book number in the series.</param>
|
||||
/// <param name="series">Optional. The series the book is part of.</param>
|
||||
/// <param name="asin">Optional. The ASIN of the book.</param>
|
||||
/// <param name="goodreadsId">Optional. The Goodreads Id of the book.</param>
|
||||
/// <param name="lccn">Optional. The LCCN of the book.</param>
|
||||
/// <param name="oclcNumber">Optional. The OCLC number of the book.</param>
|
||||
/// <param name="openLibraryId">Optional. The Open Library Id of the book.</param>
|
||||
/// <param name="libraryThingId">Optional. The LibraryThing Id of the book.</param>
|
||||
/// <param name="googleBooksId">Optional. The Google Books Id of the book.</param>
|
||||
/// <param name="barnesAndNobleId">Optional. The Barnes and Noble Id of the book.</param>
|
||||
/// <param name="appleBooksId">Optional. The Apple Books Id of the book.</param>
|
||||
/// <param name="isbns">Optional. The ISBNs of the book.</param>
|
||||
/// <param name="contributors">Optional. The media contributors of the book.</param>
|
||||
/// <param name="ratings">Optional. The ratings of the book.</param>
|
||||
/// <returns>The created <see cref="Book"/> domain aggregate.</returns>
|
||||
public Book Create()
|
||||
public Book Create(
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
WrittenContentMetadata? metadata = null,
|
||||
BookFormat? format = null,
|
||||
string? edition = null,
|
||||
float? volumeNumber = null,
|
||||
BookSeries? 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<Isbn>? isbns = null,
|
||||
List<MediaContributorId>? contributors = null,
|
||||
List<BookRating>? ratings = null)
|
||||
{
|
||||
return Book.Create(
|
||||
LibraryId.Create(_fixture.Create<Guid>()),
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<WrittenContentMetadata>(),
|
||||
_fixture.Create<BookFormat>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<float>>(),
|
||||
_fixture.Create<Optional<BookSeries>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<List<Isbn>>(),
|
||||
_fixture.Create<List<MediaContributorId>>(),
|
||||
_fixture.Create<List<BookRating>>()
|
||||
libraryId is null ? LibraryId.Create(Guid.NewGuid()) : LibraryId.Create(libraryId.Value),
|
||||
path ?? _faker.System.FilePath(),
|
||||
metadata ?? _writtenContentMetadataFixture.Create(),
|
||||
format ?? _faker.PickRandom<BookFormat>(),
|
||||
edition is null ? Optional<string>.Some(_faker.Commerce.ProductName()) : Optional<string>.Some(edition),
|
||||
volumeNumber is null ? Optional<float>.None() : Optional<float>.Some(volumeNumber.Value),
|
||||
series is null ? Optional<BookSeries>.None() : Optional<BookSeries>.Some(series),
|
||||
asin is null ? Optional<string>.Some(_faker.Random.String2(10)) : Optional<string>.Some(asin),
|
||||
goodreadsId is null ? Optional<string>.Some(_faker.Random.Number(100000, 500000).ToString()) : Optional<string>.Some(goodreadsId),
|
||||
lccn is null ? Optional<string>.Some(_faker.Random.String2(_faker.Random.Number(8, 10))) : Optional<string>.Some(lccn),
|
||||
oclcNumber is null ? Optional<string>.Some($"ocm{_faker.Random.String2(8, "0123456789")}") : Optional<string>.Some(oclcNumber),
|
||||
openLibraryId is null ? Optional<string>.Some($"OL{_faker.Random.Number(100000, 999999)}{_faker.Random.ArrayElement(['A', 'M', 'W'])}") : Optional<string>.Some(openLibraryId),
|
||||
libraryThingId is null ? Optional<string>.Some(_faker.Random.String2(_faker.Random.Number(1, 50))) : Optional<string>.Some(libraryThingId),
|
||||
googleBooksId is null ? Optional<string>.Some(_faker.Random.String2(12)) : Optional<string>.Some(googleBooksId),
|
||||
barnesAndNobleId is null ? Optional<string>.Some(_faker.Random.String2(10, "0123456789")) : Optional<string>.Some(barnesAndNobleId),
|
||||
appleBooksId is null ? Optional<string>.Some($"id{_faker.Random.Number(1, 999999)}") : Optional<string>.Some(appleBooksId),
|
||||
isbns ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _isbnFixture.Create())],
|
||||
contributors ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _mediaContributorIdFixture.Create())],
|
||||
ratings ?? [.. Enumerable.Range(0, _faker.Random.Number(1, 4)).Select(_ => _bookRatingFixture.Create())]
|
||||
).Value;
|
||||
}
|
||||
|
||||
@@ -76,50 +105,4 @@ public class BookFixture
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
private void ConfigureCustomDomainTypes()
|
||||
{
|
||||
_fixture.Register(() => Optional<string>.Some(_fixture.Create<string>()));
|
||||
_fixture.Register(() => Optional<int>.Some(_fixture.Create<int>()));
|
||||
|
||||
_fixture.Register(() =>
|
||||
{
|
||||
int originalYear = Random.Shared.Next(1900, 2026);
|
||||
int reReleaseYear = Random.Shared.Next(originalYear, 2026);
|
||||
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(originalYear, 1, 1))),
|
||||
Optional<int>.Some(originalYear),
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(reReleaseYear, 1, 1))),
|
||||
Optional<int>.Some(reReleaseYear),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>()
|
||||
).Value;
|
||||
});
|
||||
|
||||
_fixture.Register(() => Genre.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Tag.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => WrittenContentMetadata.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<ReleaseInfo>(),
|
||||
_fixture.Create<List<Genre>>(),
|
||||
_fixture.Create<List<Tag>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => _isbnFixture.Create());
|
||||
|
||||
_fixture.Register(() => _bookRatingFixture.Create());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user