Hardens test assertions and adds missing test coverage.

This commit is contained in:
BinaryAlley committed 2026-08-18 08:28:16 -07:00
1 parent 6b86fd5805
commit 1189bbaf36
489 files changed
+39982 -512

No files matched your search

@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
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.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
/// <summary>
/// Fixture class for the <see cref="BookSeries"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookSeriesFixture
{
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
/// <summary>
/// Creates a random valid <see cref="BookSeries"/>.
/// </summary>
/// <param name="id">Optional. The unique identifier of the book series.</param>
/// <param name="isComplete">Whether the book series is complete.</param>
/// <returns>The created <see cref="BookSeries"/>.</returns>
public BookSeries Create(
Guid? id = null,
bool isComplete = false)
{
return BookSeries.Create(
id is null ? BookSeriesId.CreateUnique() : _bookSeriesIdFixture.Create(id.Value),
_writtenContentMetadataFixture.Create(),
isComplete,
[]).Value;
}
/// <summary>
/// Creates multiple <see cref="BookSeries"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookSeries"/> instances.</returns>
public List<BookSeries> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookId"/>.</returns>
public BookId Create(Guid? value = null)
{
return value is null ? BookId.CreateUnique() : BookId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="BookId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookId"/> instances.</returns>
public List<BookId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookLibraryId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookLibraryIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookLibraryId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookLibraryId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookLibraryId"/>.</returns>
public BookLibraryId Create(Guid? value = null)
{
return value is null ? BookLibraryId.CreateUnique().Value : BookLibraryId.Create(value.Value).Value;
}
/// <summary>
/// Creates multiple <see cref="BookLibraryId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookLibraryId"/> instances.</returns>
public List<BookLibraryId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookSeriesId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookSeriesIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookSeriesId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookSeriesId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookSeriesId"/>.</returns>
public BookSeriesId Create(Guid? value = null)
{
return value is null ? BookSeriesId.CreateUnique() : BookSeriesId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="BookSeriesId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookSeriesId"/> instances.</returns>
public List<BookSeriesId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
@@ -19,13 +20,23 @@ public class IsbnFixture
/// <summary>
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
/// </summary>
/// <param name="value">Optional. The ISBN value to use. If not provided, a random valid value is generated for the requested format.</param>
/// <param name="format">Optional. The requested <see cref="IsbnFormat"/>. If not provided, a random format is selected.</param>
/// <returns>The created <see cref="Isbn"/>.</returns>
public Isbn Create(IsbnFormat? format = null)
public Isbn Create(string? value = null, IsbnFormat? format = null)
{
IsbnFormat targetFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
string isbn = targetFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
return Isbn.Create(isbn, targetFormat).Value;
if (value is not null)
{
IsbnFormat targetFormat = format ?? IsbnFormat.Isbn10;
Result<Isbn> result = Isbn.Create(value, targetFormat);
if (result.IsFailure)
throw new InvalidOperationException("Failed to create Isbn: " + string.Join(", ", result.Errors));
return result.Value;
}
IsbnFormat requestedFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
string isbn = requestedFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
return Isbn.Create(isbn, requestedFormat).Value;
}
/// <summary>
@@ -0,0 +1,75 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="WrittenContentMetadata"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class WrittenContentMetadataFixture
{
private readonly Faker _faker = new();
private readonly GenreFixture _genreFixture = new();
private readonly TagFixture _tagFixture = new();
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
private readonly LanguageInfoFixture _languageInfoFixture = new();
/// <summary>
/// Creates a random valid <see cref="WrittenContentMetadata"/>.
/// </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. The description of the written content.</param>
/// <param name="releaseInfo">Optional. The release information of the written content.</param>
/// <param name="genres">Optional. The genres of the written content.</param>
/// <param name="tags">Optional. The tags associated with the written content.</param>
/// <param name="language">Optional. The language of the written content.</param>
/// <param name="originalLanguage">Optional. The original language of the written content.</param>
/// <param name="publisher">Optional. The publisher of the written content.</param>
/// <param name="pageCount">Optional. The number of pages in the written content.</param>
/// <returns>The created <see cref="WrittenContentMetadata"/>.</returns>
public WrittenContentMetadata Create(
string? title = null,
Optional<string>? originalTitle = null,
Optional<string>? description = null,
ReleaseInfo? releaseInfo = null,
List<Genre>? genres = null,
List<Tag>? tags = null,
Optional<LanguageInfo>? language = null,
Optional<LanguageInfo>? originalLanguage = null,
Optional<string>? publisher = null,
Optional<int>? pageCount = null)
{
return WrittenContentMetadata.Create(
title ?? _faker.Commerce.ProductName(),
originalTitle ?? Optional<string>.None(),
description ?? Optional<string>.Some(_faker.Lorem.Sentence()),
releaseInfo ?? _releaseInfoFixture.Create(),
genres ?? [_genreFixture.Create(), _genreFixture.Create()],
tags ?? [_tagFixture.Create(), _tagFixture.Create()],
language ?? Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
originalLanguage ?? Optional<LanguageInfo>.None(),
publisher ?? Optional<string>.Some(_faker.Company.CompanyName()),
pageCount ?? Optional<int>.Some(_faker.Random.Int(1, 1000))).Value;
}
/// <summary>
/// Creates multiple <see cref="WrittenContentMetadata"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="WrittenContentMetadata"/> instances.</returns>
public List<WrittenContentMetadata> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}