Implements tests for commit 822ccc9adc

This commit is contained in:
BinaryAlley committed 2026-10-27 19:01:12 +02:00
1 parent 941f6c846d
commit 6cadf437de
35 files changed
+4376

No files matched your search

@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="CompleteConsumptionRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class CompleteConsumptionRequestFixture
{
private const double MAXIMUM_DURATION_SECONDS = 36_000;
private readonly Faker _faker = new();
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
/// <summary>
/// Creates a random valid <see cref="CompleteConsumptionRequest"/>.
/// </summary>
/// <param name="position">Optional. The final position reported for the media item.</param>
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
/// <param name="progressFraction">Optional. The fraction of the media item that the client reached. Defaults to a bounded random fraction between zero and one.</param>
/// <param name="includeProgressFraction">Whether the progress fraction should be included, or forced to <see langword="null"/>.</param>
/// <param name="consumedDurationInSeconds">Optional. The active duration consumed by the session, in seconds. Defaults to a bounded random duration.</param>
/// <param name="includeConsumedDurationInSeconds">Whether the consumed duration should be included, or forced to <see langword="null"/>.</param>
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read in the session.</param>
/// <param name="includeConsecutivePagesRead">Whether the optional consecutive pages argument should be supplied at all. When <see langword="false"/>, the argument is omitted, so the record default applies.</param>
/// <returns>The created <see cref="CompleteConsumptionRequest"/>.</returns>
public CompleteConsumptionRequest Create(
MediaPositionRequest? position = null,
bool includePosition = true,
double? progressFraction = null,
bool includeProgressFraction = true,
double? consumedDurationInSeconds = null,
bool includeConsumedDurationInSeconds = true,
int? consecutivePagesRead = null,
bool includeConsecutivePagesRead = true)
{
MediaPositionRequest? resolvedPosition = includePosition ? position ?? _mediaPositionRequestFixture.Create() : null;
double? resolvedProgressFraction = includeProgressFraction ? progressFraction ?? _faker.Random.Double(0, 1) : null;
double? resolvedConsumedDurationInSeconds = includeConsumedDurationInSeconds ? consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS) : null;
if (!includeConsecutivePagesRead)
return new CompleteConsumptionRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds);
return new CompleteConsumptionRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds, consecutivePagesRead);
}
/// <summary>
/// Creates a list of <see cref="CompleteConsumptionRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CompleteConsumptionRequest"/> instances.</returns>
public List<CompleteConsumptionRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="MediaPositionRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaPositionRequestFixture
{
private const double MAXIMUM_OFFSET_SECONDS = 7_200;
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaPositionRequest"/>.
/// </summary>
/// <param name="kind">Optional. The kind of the position, as the name of a <see cref="MediaPositionKind"/> member. Defaults to a random valid kind.</param>
/// <param name="timeOffsetSeconds">Optional. The position within the media item, in seconds. Defaults to a bounded random offset for a time offset position.</param>
/// <param name="location">Optional. The opaque locator within the media item. Defaults to a random word for a location position.</param>
/// <param name="includeKind">Whether the kind should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTimeOffsetSeconds">Whether the time offset should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLocation">Whether the location should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MediaPositionRequest"/>.</returns>
public MediaPositionRequest Create(
string? kind = null,
double? timeOffsetSeconds = null,
string? location = null,
bool includeKind = true,
bool includeTimeOffsetSeconds = true,
bool includeLocation = true)
{
string? resolvedKind = includeKind ? kind ?? _faker.PickRandom<MediaPositionKind>().ToString() : null;
bool isTimeOffset = resolvedKind == nameof(MediaPositionKind.TimeOffset);
double? resolvedTimeOffsetSeconds = includeTimeOffsetSeconds
? timeOffsetSeconds ?? (isTimeOffset ? _faker.Random.Double(0, MAXIMUM_OFFSET_SECONDS) : (double?)null)
: null;
string? resolvedLocation = includeLocation
? location ?? (isTimeOffset ? (string?)null : _faker.Lorem.Word())
: null;
return new MediaPositionRequest(resolvedKind, resolvedTimeOffsetSeconds, resolvedLocation);
}
/// <summary>
/// Creates a list of <see cref="MediaPositionRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaPositionRequest"/> instances.</returns>
public List<MediaPositionRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="ReportConsumptionProgressRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReportConsumptionProgressRequestFixture
{
private const double MAXIMUM_DURATION_SECONDS = 36_000;
private readonly Faker _faker = new();
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
/// <summary>
/// Creates a random valid <see cref="ReportConsumptionProgressRequest"/>.
/// </summary>
/// <param name="position">Optional. The last position reported for the media item.</param>
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
/// <param name="progressFraction">Optional. The fraction of the media item that the client reached. Defaults to a bounded random fraction between zero and one.</param>
/// <param name="includeProgressFraction">Whether the progress fraction should be included, or forced to <see langword="null"/>.</param>
/// <param name="consumedDurationInSeconds">Optional. The active duration consumed by the session, in seconds. Defaults to a bounded random duration.</param>
/// <param name="includeConsumedDurationInSeconds">Whether the consumed duration should be included, or forced to <see langword="null"/>.</param>
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read in the current session.</param>
/// <param name="includeConsecutivePagesRead">Whether the consecutive pages argument should be supplied at all. When <see langword="false"/>, the argument is omitted, so the record default applies.</param>
/// <returns>The created <see cref="ReportConsumptionProgressRequest"/>.</returns>
public ReportConsumptionProgressRequest Create(
MediaPositionRequest? position = null,
bool includePosition = true,
double? progressFraction = null,
bool includeProgressFraction = true,
double? consumedDurationInSeconds = null,
bool includeConsumedDurationInSeconds = true,
int? consecutivePagesRead = null,
bool includeConsecutivePagesRead = true)
{
MediaPositionRequest? resolvedPosition = includePosition ? position ?? _mediaPositionRequestFixture.Create() : null;
double? resolvedProgressFraction = includeProgressFraction ? progressFraction ?? _faker.Random.Double(0, 1) : null;
double? resolvedConsumedDurationInSeconds = includeConsumedDurationInSeconds ? consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS) : null;
if (!includeConsecutivePagesRead)
return new ReportConsumptionProgressRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds);
return new ReportConsumptionProgressRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds, consecutivePagesRead ?? 0);
}
/// <summary>
/// Creates a list of <see cref="ReportConsumptionProgressRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ReportConsumptionProgressRequest"/> instances.</returns>
public List<ReportConsumptionProgressRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="StopConsumptionRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class StopConsumptionRequestFixture
{
private const double MAXIMUM_DURATION_SECONDS = 36_000;
private readonly Faker _faker = new();
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
/// <summary>
/// Creates a random valid <see cref="StopConsumptionRequest"/>.
/// </summary>
/// <param name="position">Optional. The final position reported for the media item.</param>
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
/// <param name="progressFraction">Optional. The fraction of the media item that the client reached. Defaults to a bounded random fraction between zero and one.</param>
/// <param name="includeProgressFraction">Whether the progress fraction should be included, or forced to <see langword="null"/>.</param>
/// <param name="consumedDurationInSeconds">Optional. The active duration consumed by the session, in seconds. Defaults to a bounded random duration.</param>
/// <param name="includeConsumedDurationInSeconds">Whether the consumed duration should be included, or forced to <see langword="null"/>.</param>
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read in the session.</param>
/// <param name="includeConsecutivePagesRead">Whether the optional consecutive pages argument should be supplied at all. When <see langword="false"/>, the argument is omitted, so the record default applies.</param>
/// <returns>The created <see cref="StopConsumptionRequest"/>.</returns>
public StopConsumptionRequest Create(
MediaPositionRequest? position = null,
bool includePosition = true,
double? progressFraction = null,
bool includeProgressFraction = true,
double? consumedDurationInSeconds = null,
bool includeConsumedDurationInSeconds = true,
int? consecutivePagesRead = null,
bool includeConsecutivePagesRead = true)
{
MediaPositionRequest? resolvedPosition = includePosition ? position ?? _mediaPositionRequestFixture.Create() : null;
double? resolvedProgressFraction = includeProgressFraction ? progressFraction ?? _faker.Random.Double(0, 1) : null;
double? resolvedConsumedDurationInSeconds = includeConsumedDurationInSeconds ? consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS) : null;
if (!includeConsecutivePagesRead)
return new StopConsumptionRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds);
return new StopConsumptionRequest(resolvedPosition, resolvedProgressFraction, resolvedConsumedDurationInSeconds, consecutivePagesRead);
}
/// <summary>
/// Creates a list of <see cref="StopConsumptionRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="StopConsumptionRequest"/> instances.</returns>
public List<StopConsumptionRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}