Implements tests for commit 00d7eff777

Covers genre consumption and delete-item-history across application, contracts, API, and Web. Changes the new string-bound request pipelines to return validation problems instead of 500 for malformed values.
This commit is contained in:
BinaryAlley committed 2026-10-28 12:27:34 +02:00
1 parent 968061e89a
commit 1afb078efc
91 files changed
+14499 -50

No files matched your search

@@ -0,0 +1,69 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
/// <summary>
/// Fixture class for the <see cref="DeleteConsumptionItemHistoryCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteConsumptionItemHistoryCommandFixture
{
private readonly Faker _faker = new();
private readonly MediaKind[] _supportedMediaKinds =
[
MediaKind.MusicTrack,
MediaKind.PodcastEpisode,
MediaKind.Audiobook,
MediaKind.Movie,
MediaKind.TvEpisode,
MediaKind.Book,
MediaKind.Photo,
MediaKind.Video
];
/// <summary>
/// Creates a random valid <see cref="DeleteConsumptionItemHistoryCommand"/>.
/// </summary>
/// <param name="targetUserId">Optional. The Id of the user the records must belong to. Defaults to a random user Id.</param>
/// <param name="mediaKind">Optional. The name of the kind of the consumed media item. Defaults to the name of a random supported kind.</param>
/// <param name="mediaItemId">Optional. The Id of the consumed media item. Defaults to a random Id.</param>
/// <param name="libraryId">Optional. The Id of the media library that contains the media item. Defaults to a random Id.</param>
/// <param name="includeTargetUserId">Whether the target user Id should be included, or forced to <see langword="null"/> so that the current user is targeted.</param>
/// <param name="includeMediaKind">Whether the media kind name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMediaItemId">Whether the media item Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="DeleteConsumptionItemHistoryCommand"/>.</returns>
public DeleteConsumptionItemHistoryCommand Create(
string? targetUserId = null,
string? mediaKind = null,
string? mediaItemId = null,
string? libraryId = null,
bool includeTargetUserId = true,
bool includeMediaKind = true,
bool includeMediaItemId = true,
bool includeLibraryId = true)
{
return new DeleteConsumptionItemHistoryCommand(
includeTargetUserId ? targetUserId ?? _faker.Random.Guid().ToString() : null,
includeMediaKind ? mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds).ToString() : null,
includeMediaItemId ? mediaItemId ?? _faker.Random.Guid().ToString() : null,
includeLibraryId ? libraryId ?? _faker.Random.Guid().ToString() : null);
}
/// <summary>
/// Creates a list of <see cref="DeleteConsumptionItemHistoryCommand"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="DeleteConsumptionItemHistoryCommand"/> instances.</returns>
public List<DeleteConsumptionItemHistoryCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,79 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaConsumption.Queries.GetGenreConsumption;
/// <summary>
/// Fixture class for the <see cref="GetGenreConsumptionQuery"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetGenreConsumptionQueryFixture
{
private readonly Faker _faker = new();
private readonly MediaKind[] _supportedMediaKinds =
[
MediaKind.MusicTrack,
MediaKind.PodcastEpisode,
MediaKind.Audiobook,
MediaKind.Movie,
MediaKind.TvEpisode,
MediaKind.Book,
MediaKind.Photo,
MediaKind.Video
];
/// <summary>
/// Creates a random valid <see cref="GetGenreConsumptionQuery"/>.
/// </summary>
/// <param name="targetUserId">Optional. The Id of the user whose statistics are retrieved. Defaults to a random Id.</param>
/// <param name="libraryId">Optional. The Id of the media library to restrict the statistics to. Defaults to a random Id.</param>
/// <param name="mediaKind">Optional. The name of the kind of media to restrict the statistics to. Defaults to the name of a random supported kind.</param>
/// <param name="fromUtc">Optional. The inclusive start of the date range. Defaults to a bounded UTC moment in the past, as a text value.</param>
/// <param name="toUtc">Optional. The inclusive end of the date range. Defaults to a bounded UTC moment in the future, as a text value.</param>
/// <param name="includeTargetUserId">Whether the target user Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMediaKind">Whether the media kind name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeFromUtc">Whether the start of the date range should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeToUtc">Whether the end of the date range should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="GetGenreConsumptionQuery"/>.</returns>
public GetGenreConsumptionQuery Create(
string? targetUserId = null,
string? libraryId = null,
string? mediaKind = null,
string? fromUtc = null,
string? toUtc = null,
bool includeTargetUserId = true,
bool includeLibraryId = true,
bool includeMediaKind = true,
bool includeFromUtc = true,
bool includeToUtc = true)
{
string resolvedFromUtc = fromUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).ToString("o", CultureInfo.InvariantCulture);
string resolvedToUtc = toUtc ?? DateTime.UtcNow.AddDays(_faker.Random.Int(1, 30)).ToString("o", CultureInfo.InvariantCulture);
return new GetGenreConsumptionQuery(
includeTargetUserId ? targetUserId ?? _faker.Random.Guid().ToString() : null,
includeLibraryId ? libraryId ?? _faker.Random.Guid().ToString() : null,
includeMediaKind ? mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds).ToString() : null,
includeFromUtc ? resolvedFromUtc : null,
includeToUtc ? resolvedToUtc : null);
}
/// <summary>
/// Creates a list of <see cref="GetGenreConsumptionQuery"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="GetGenreConsumptionQuery"/> instances.</returns>
public List<GetGenreConsumptionQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}