mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Implements tests for commit 822ccc9adc
This commit is contained in:
1 parent
941f6c846d
commit
6cadf437de
35 files changed
+4376
No files matched your search
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ConsumedItemResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ConsumedItemResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
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="ConsumedItemResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The kind of the consumed media item. Defaults to a random supported kind.</param>
|
||||
/// <param name="mediaItemId">Optional. The Id of the consumed media item.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the media item.</param>
|
||||
/// <param name="isAvailable">Optional. Whether the media item is still available.</param>
|
||||
/// <param name="title">Optional. The title of the media item.</param>
|
||||
/// <param name="collectionTitle">Optional. The title of the collection that contains the media item.</param>
|
||||
/// <param name="creatorName">Optional. The name of the creator of the media item.</param>
|
||||
/// <param name="coverPath">Optional. The path of the cover art of the media item.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="lastConsumedOnUtc">Optional. The date and time when the media item was last consumed.</param>
|
||||
/// <param name="countedSessionCount">Optional. The number of consumption sessions that count towards statistics.</param>
|
||||
/// <param name="completedSessionCount">Optional. The number of consumption sessions that completed.</param>
|
||||
/// <param name="consumedDurationInSeconds">Optional. The active duration consumed in the media item, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <returns>The created <see cref="ConsumedItemResponse"/>.</returns>
|
||||
public ConsumedItemResponse Create(
|
||||
MediaKind? mediaKind = null,
|
||||
Guid? mediaItemId = null,
|
||||
Guid? libraryId = null,
|
||||
bool? isAvailable = null,
|
||||
string? title = null,
|
||||
string? collectionTitle = null,
|
||||
string? creatorName = null,
|
||||
string? coverPath = null,
|
||||
bool includeCoverPath = true,
|
||||
DateTime? lastConsumedOnUtc = null,
|
||||
int? countedSessionCount = null,
|
||||
int? completedSessionCount = null,
|
||||
double? consumedDurationInSeconds = null)
|
||||
{
|
||||
return new ConsumedItemResponse(
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
mediaItemId ?? _faker.Random.Guid(),
|
||||
libraryId ?? _faker.Random.Guid(),
|
||||
isAvailable ?? _faker.Random.Bool(),
|
||||
title ?? _faker.Commerce.ProductName(),
|
||||
collectionTitle ?? _faker.Commerce.Department(),
|
||||
creatorName ?? _faker.Name.FullName(),
|
||||
includeCoverPath ? coverPath ?? _faker.System.FilePath() : null,
|
||||
lastConsumedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 720)),
|
||||
countedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ConsumedItemResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ConsumedItemResponse"/> instances.</returns>
|
||||
public List<ConsumedItemResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ConsumptionRecordResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ConsumptionRecordResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionResponseFixture _mediaPositionResponseFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
private readonly ConsumptionStatus[] _statuses =
|
||||
[
|
||||
ConsumptionStatus.InProgress,
|
||||
ConsumptionStatus.Completed,
|
||||
ConsumptionStatus.Stopped
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ConsumptionRecordResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the consumption record.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">Optional. The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that was consumed. Defaults to a random supported kind.</param>
|
||||
/// <param name="status">Optional. The state of the consumption session. Defaults to a random valid status.</param>
|
||||
/// <param name="startedOnUtc">Optional. The date and time when the session started. Defaults to a moment in the past.</param>
|
||||
/// <param name="lastActivityOnUtc">Optional. The date and time when the session last received activity. Defaults to a moment at or after the start.</param>
|
||||
/// <param name="endedOnUtc">Optional. The date and time when the session ended. Defaults to no value for an in-progress session, and to a moment at or after the last activity for a terminal session.</param>
|
||||
/// <param name="includeEndedOnUtc">Whether the end time 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="lastPosition">Optional. The last known position. Defaults to a position matching the position kind of the media kind, and to no position for a photo.</param>
|
||||
/// <param name="includeLastPosition">Whether the last position should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The latest reported progress fraction. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read. Defaults to a bounded random count for a book, and to zero for every other kind.</param>
|
||||
/// <returns>The created <see cref="ConsumptionRecordResponse"/>.</returns>
|
||||
public ConsumptionRecordResponse Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
Guid? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
ConsumptionStatus? status = null,
|
||||
DateTime? startedOnUtc = null,
|
||||
DateTime? lastActivityOnUtc = null,
|
||||
DateTime? endedOnUtc = null,
|
||||
bool includeEndedOnUtc = true,
|
||||
double? consumedDurationInSeconds = null,
|
||||
MediaPositionResponse? lastPosition = null,
|
||||
bool includeLastPosition = true,
|
||||
double? lastProgressFraction = null,
|
||||
int? consecutivePagesRead = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
|
||||
ConsumptionStatus resolvedStatus = status ?? _faker.Random.ArrayElement(_statuses);
|
||||
DateTime resolvedStartedOnUtc = startedOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).AddMinutes(-_faker.Random.Int(0, 59));
|
||||
DateTime resolvedLastActivityOnUtc = lastActivityOnUtc ?? resolvedStartedOnUtc.AddMinutes(_faker.Random.Int(0, 120));
|
||||
DateTime? resolvedEndedOnUtc = includeEndedOnUtc
|
||||
? endedOnUtc ?? (resolvedStatus == ConsumptionStatus.InProgress
|
||||
? null
|
||||
: resolvedLastActivityOnUtc.AddMinutes(_faker.Random.Int(0, 60)))
|
||||
: null;
|
||||
MediaPositionKind? defaultPositionKind = ResolveDefaultPositionKind(resolvedMediaKind);
|
||||
MediaPositionResponse? resolvedLastPosition = includeLastPosition && (lastPosition is not null || defaultPositionKind.HasValue)
|
||||
? lastPosition ?? _mediaPositionResponseFixture.Create(kind: defaultPositionKind)
|
||||
: null;
|
||||
|
||||
return new ConsumptionRecordResponse(
|
||||
id ?? _faker.Random.Guid(),
|
||||
libraryId ?? _faker.Random.Guid(),
|
||||
mediaItemId ?? _faker.Random.Guid(),
|
||||
resolvedMediaKind,
|
||||
resolvedStatus,
|
||||
resolvedStartedOnUtc,
|
||||
resolvedLastActivityOnUtc,
|
||||
resolvedEndedOnUtc,
|
||||
consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS),
|
||||
resolvedLastPosition,
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
consecutivePagesRead ?? (resolvedMediaKind == MediaKind.Book ? _faker.Random.Int(0, 100) : 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ConsumptionRecordResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ConsumptionRecordResponse"/> instances.</returns>
|
||||
public List<ConsumptionRecordResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the default kind of position used by a media kind.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">The kind of media.</param>
|
||||
/// <returns>The position kind that a session of the media kind reports, or <see langword="null"/> when the kind carries no position.</returns>
|
||||
private static MediaPositionKind? ResolveDefaultPositionKind(MediaKind mediaKind)
|
||||
{
|
||||
if (mediaKind == MediaKind.Photo)
|
||||
return null;
|
||||
return mediaKind == MediaKind.Book ? MediaPositionKind.Location : MediaPositionKind.TimeOffset;
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ConsumptionSummaryResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ConsumptionSummaryResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaKindConsumptionSummaryResponseFixture _mediaKindConsumptionSummaryResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ConsumptionSummaryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The Id of the user the statistics belong to.</param>
|
||||
/// <param name="totalConsumedDurationInSeconds">Optional. The total consumed duration, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <param name="countedSessionCount">Optional. The number of sessions that count towards statistics.</param>
|
||||
/// <param name="completedSessionCount">Optional. The number of sessions that completed.</param>
|
||||
/// <param name="stoppedSessionCount">Optional. The number of sessions that stopped before they completed.</param>
|
||||
/// <param name="completionRate">Optional. The completion rate. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="mediaKindSummaries">Optional. The statistics broken down by media kind. Defaults to a single random summary.</param>
|
||||
/// <param name="includeMediaKindSummaries">Whether the media kind summaries should be included, or forced to an empty list.</param>
|
||||
/// <returns>The created <see cref="ConsumptionSummaryResponse"/>.</returns>
|
||||
public ConsumptionSummaryResponse Create(
|
||||
Guid? userId = null,
|
||||
double? totalConsumedDurationInSeconds = null,
|
||||
int? countedSessionCount = null,
|
||||
int? completedSessionCount = null,
|
||||
int? stoppedSessionCount = null,
|
||||
double? completionRate = null,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryResponse>? mediaKindSummaries = null,
|
||||
bool includeMediaKindSummaries = true)
|
||||
{
|
||||
IReadOnlyList<MediaKindConsumptionSummaryResponse> resolvedMediaKindSummaries = includeMediaKindSummaries
|
||||
? mediaKindSummaries ?? [_mediaKindConsumptionSummaryResponseFixture.Create()]
|
||||
: [];
|
||||
|
||||
return new ConsumptionSummaryResponse(
|
||||
userId ?? _faker.Random.Guid(),
|
||||
totalConsumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS),
|
||||
countedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
stoppedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completionRate ?? _faker.Random.Double(0, 1),
|
||||
resolvedMediaKindSummaries);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ConsumptionSummaryResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ConsumptionSummaryResponse"/> instances.</returns>
|
||||
public List<ConsumptionSummaryResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaKindConsumptionSummaryResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaKindConsumptionSummaryResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
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="MediaKindConsumptionSummaryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The kind of media the statistics belong to. Defaults to a random supported kind.</param>
|
||||
/// <param name="totalConsumedDurationInSeconds">Optional. The total consumed duration of the media kind, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <param name="countedSessionCount">Optional. The number of sessions that count towards statistics.</param>
|
||||
/// <param name="completedSessionCount">Optional. The number of sessions that completed.</param>
|
||||
/// <param name="stoppedSessionCount">Optional. The number of sessions that stopped before they completed.</param>
|
||||
/// <param name="completionRate">Optional. The completion rate. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <returns>The created <see cref="MediaKindConsumptionSummaryResponse"/>.</returns>
|
||||
public MediaKindConsumptionSummaryResponse Create(
|
||||
MediaKind? mediaKind = null,
|
||||
double? totalConsumedDurationInSeconds = null,
|
||||
int? countedSessionCount = null,
|
||||
int? completedSessionCount = null,
|
||||
int? stoppedSessionCount = null,
|
||||
double? completionRate = null)
|
||||
{
|
||||
return new MediaKindConsumptionSummaryResponse(
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
totalConsumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS),
|
||||
countedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
stoppedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completionRate ?? _faker.Random.Double(0, 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="MediaKindConsumptionSummaryResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaKindConsumptionSummaryResponse"/> instances.</returns>
|
||||
public List<MediaKindConsumptionSummaryResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.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.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaPositionResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaPositionResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_OFFSET_SECONDS = 7_200;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionKind[] _positionKinds =
|
||||
[
|
||||
MediaPositionKind.TimeOffset,
|
||||
MediaPositionKind.Location
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaPositionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="kind">Optional. The kind of representation used by the position. 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="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="MediaPositionResponse"/>.</returns>
|
||||
public MediaPositionResponse Create(
|
||||
MediaPositionKind? kind = null,
|
||||
double? timeOffsetSeconds = null,
|
||||
string? location = null,
|
||||
bool includeTimeOffsetSeconds = true,
|
||||
bool includeLocation = true)
|
||||
{
|
||||
MediaPositionKind resolvedKind = kind ?? _faker.Random.ArrayElement(_positionKinds);
|
||||
bool isTimeOffset = resolvedKind == MediaPositionKind.TimeOffset;
|
||||
double? resolvedTimeOffsetSeconds = includeTimeOffsetSeconds
|
||||
? timeOffsetSeconds ?? (isTimeOffset ? _faker.Random.Double(0, MAXIMUM_OFFSET_SECONDS) : (double?)null)
|
||||
: null;
|
||||
string? resolvedLocation = includeLocation
|
||||
? location ?? (isTimeOffset ? null : _faker.Lorem.Word())
|
||||
: null;
|
||||
|
||||
return new MediaPositionResponse(resolvedKind, resolvedTimeOffsetSeconds, resolvedLocation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="MediaPositionResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaPositionResponse"/> instances.</returns>
|
||||
public List<MediaPositionResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ResumePointResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ResumePointResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionResponseFixture _mediaPositionResponseFixture = new();
|
||||
private readonly MediaKind[] _resumableMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ResumePointResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the resume point.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the media item.</param>
|
||||
/// <param name="mediaItemId">Optional. The Id of the media item to resume.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that is resumed. Defaults to a random resumable kind.</param>
|
||||
/// <param name="lastPosition">Optional. The position at which the media item can be resumed. Defaults to a position matching the position kind of the media kind.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The progress fraction at which the media item can be resumed. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="lastConsumedOnUtc">Optional. The date and time when the media item was last consumed. Defaults to a moment in the past.</param>
|
||||
/// <returns>The created <see cref="ResumePointResponse"/>.</returns>
|
||||
public ResumePointResponse Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
Guid? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
MediaPositionResponse? lastPosition = null,
|
||||
double? lastProgressFraction = null,
|
||||
DateTime? lastConsumedOnUtc = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_resumableMediaKinds);
|
||||
|
||||
return new ResumePointResponse(
|
||||
id ?? _faker.Random.Guid(),
|
||||
libraryId ?? _faker.Random.Guid(),
|
||||
mediaItemId ?? _faker.Random.Guid(),
|
||||
resolvedMediaKind,
|
||||
lastPosition ?? _mediaPositionResponseFixture.Create(kind: ResolveDefaultPositionKind(resolvedMediaKind)),
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
lastConsumedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 720)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ResumePointResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ResumePointResponse"/> instances.</returns>
|
||||
public List<ResumePointResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the default kind of position used by a media kind.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">The kind of media.</param>
|
||||
/// <returns>The position kind that a resume point of the media kind uses.</returns>
|
||||
private static MediaPositionKind ResolveDefaultPositionKind(MediaKind mediaKind)
|
||||
{
|
||||
return mediaKind == MediaKind.Book ? MediaPositionKind.Location : MediaPositionKind.TimeOffset;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TagConsumptionResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagConsumptionResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TagConsumptionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The lowercase name of the tag.</param>
|
||||
/// <param name="consumedItemCount">Optional. The number of distinct consumed media items that carry the tag.</param>
|
||||
/// <param name="consumedDurationInSeconds">Optional. The consumed duration of the media items that carry the tag, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <returns>The created <see cref="TagConsumptionResponse"/>.</returns>
|
||||
public TagConsumptionResponse Create(
|
||||
string? name = null,
|
||||
int? consumedItemCount = null,
|
||||
double? consumedDurationInSeconds = null)
|
||||
{
|
||||
return new TagConsumptionResponse(
|
||||
name ?? _faker.Lorem.Word().ToLowerInvariant(),
|
||||
consumedItemCount ?? _faker.Random.Int(0, 1000),
|
||||
consumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TagConsumptionResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="TagConsumptionResponse"/> instances.</returns>
|
||||
public List<TagConsumptionResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user