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,90 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="ConsumedItemDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ConsumedItemDtoFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_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="ConsumedItemDto"/>.
/// </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="consumedDurationMilliseconds">Optional. The active duration consumed in the media item, in milliseconds. Defaults to a bounded random duration.</param>
/// <returns>The created <see cref="ConsumedItemDto"/>.</returns>
public ConsumedItemDto 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,
long? consumedDurationMilliseconds = null)
{
return new ConsumedItemDto(
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),
consumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS));
}
/// <summary>
/// Creates a list of <see cref="ConsumedItemDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ConsumedItemDto"/> instances.</returns>
public List<ConsumedItemDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,126 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.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.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="ConsumptionRecordDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ConsumptionRecordDtoFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_000;
private readonly Faker _faker = new();
private readonly MediaPositionDtoFixture _mediaPositionDtoFixture = 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="ConsumptionRecordDto"/>.
/// </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="consumedDurationMilliseconds">Optional. The active duration consumed by the session, in milliseconds. 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="ConsumptionRecordDto"/>.</returns>
public ConsumptionRecordDto 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,
long? consumedDurationMilliseconds = null,
MediaPositionDto? 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);
MediaPositionDto? resolvedLastPosition = includeLastPosition && (lastPosition is not null || defaultPositionKind.HasValue)
? lastPosition ?? _mediaPositionDtoFixture.Create(kind: defaultPositionKind)
: null;
return new ConsumptionRecordDto(
id ?? _faker.Random.Guid(),
libraryId ?? _faker.Random.Guid(),
mediaItemId ?? _faker.Random.Guid(),
resolvedMediaKind,
resolvedStatus,
resolvedStartedOnUtc,
resolvedLastActivityOnUtc,
resolvedEndedOnUtc,
consumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS),
resolvedLastPosition,
lastProgressFraction ?? _faker.Random.Double(0, 1),
consecutivePagesRead ?? (resolvedMediaKind == MediaKind.Book ? _faker.Random.Int(0, 100) : 0));
}
/// <summary>
/// Creates a list of <see cref="ConsumptionRecordDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ConsumptionRecordDto"/> instances.</returns>
public List<ConsumptionRecordDto> 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;
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaConsumption;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="ConsumptionStatisticsDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ConsumptionStatisticsDtoFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_000;
private readonly Faker _faker = new();
private readonly MediaKindConsumptionStatisticsDtoFixture _mediaKindConsumptionStatisticsDtoFixture = new();
/// <summary>
/// Creates a random valid <see cref="ConsumptionStatisticsDto"/>.
/// </summary>
/// <param name="userId">Optional. The Id of the user the statistics belong to.</param>
/// <param name="totalConsumedDurationMilliseconds">Optional. The total consumed duration, in milliseconds. 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="ConsumptionStatisticsDto"/>.</returns>
public ConsumptionStatisticsDto Create(
Guid? userId = null,
long? totalConsumedDurationMilliseconds = null,
int? countedSessionCount = null,
int? completedSessionCount = null,
int? stoppedSessionCount = null,
double? completionRate = null,
IReadOnlyList<MediaKindConsumptionStatisticsDto>? mediaKindSummaries = null,
bool includeMediaKindSummaries = true)
{
IReadOnlyList<MediaKindConsumptionStatisticsDto> resolvedMediaKindSummaries = includeMediaKindSummaries
? mediaKindSummaries ?? [_mediaKindConsumptionStatisticsDtoFixture.Create()]
: [];
return new ConsumptionStatisticsDto(
userId ?? _faker.Random.Guid(),
totalConsumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS),
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="ConsumptionStatisticsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ConsumptionStatisticsDto"/> instances.</returns>
public List<ConsumptionStatisticsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,69 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="MediaKindConsumptionStatisticsDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaKindConsumptionStatisticsDtoFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_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="MediaKindConsumptionStatisticsDto"/>.
/// </summary>
/// <param name="mediaKind">Optional. The kind of media the statistics belong to. Defaults to a random supported kind.</param>
/// <param name="totalConsumedDurationMilliseconds">Optional. The total consumed duration of the media kind, in milliseconds. 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="MediaKindConsumptionStatisticsDto"/>.</returns>
public MediaKindConsumptionStatisticsDto Create(
MediaKind? mediaKind = null,
long? totalConsumedDurationMilliseconds = null,
int? countedSessionCount = null,
int? completedSessionCount = null,
int? stoppedSessionCount = null,
double? completionRate = null)
{
return new MediaKindConsumptionStatisticsDto(
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
totalConsumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS),
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="MediaKindConsumptionStatisticsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaKindConsumptionStatisticsDto"/> instances.</returns>
public List<MediaKindConsumptionStatisticsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,64 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="MediaPositionDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaPositionDtoFixture
{
private const int MAXIMUM_OFFSET_MILLISECONDS = 7_200_000;
private readonly Faker _faker = new();
private readonly MediaPositionKind[] _positionKinds =
[
MediaPositionKind.TimeOffset,
MediaPositionKind.Location
];
/// <summary>
/// Creates a random valid <see cref="MediaPositionDto"/>.
/// </summary>
/// <param name="kind">Optional. The kind of representation used by the position. Defaults to a random valid kind.</param>
/// <param name="timeOffsetMilliseconds">Optional. The position within the media item, in milliseconds. 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="includeTimeOffsetMilliseconds">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="MediaPositionDto"/>.</returns>
public MediaPositionDto Create(
MediaPositionKind? kind = null,
long? timeOffsetMilliseconds = null,
string? location = null,
bool includeTimeOffsetMilliseconds = true,
bool includeLocation = true)
{
MediaPositionKind resolvedKind = kind ?? _faker.Random.ArrayElement(_positionKinds);
bool isTimeOffset = resolvedKind == MediaPositionKind.TimeOffset;
long? resolvedTimeOffsetMilliseconds = includeTimeOffsetMilliseconds
? timeOffsetMilliseconds ?? (isTimeOffset ? _faker.Random.Long(0, MAXIMUM_OFFSET_MILLISECONDS) : (long?)null)
: null;
string? resolvedLocation = includeLocation
? location ?? (isTimeOffset ? (string?)null : _faker.Lorem.Word())
: null;
return new MediaPositionDto(resolvedKind, resolvedTimeOffsetMilliseconds, resolvedLocation);
}
/// <summary>
/// Creates a list of <see cref="MediaPositionDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaPositionDto"/> instances.</returns>
public List<MediaPositionDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,84 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.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.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="ResumePointDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ResumePointDtoFixture
{
private readonly Faker _faker = new();
private readonly MediaPositionDtoFixture _mediaPositionDtoFixture = 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="ResumePointDto"/>.
/// </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="ResumePointDto"/>.</returns>
public ResumePointDto Create(
Guid? id = null,
Guid? libraryId = null,
Guid? mediaItemId = null,
MediaKind? mediaKind = null,
MediaPositionDto? lastPosition = null,
double? lastProgressFraction = null,
DateTime? lastConsumedOnUtc = null)
{
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_resumableMediaKinds);
return new ResumePointDto(
id ?? _faker.Random.Guid(),
libraryId ?? _faker.Random.Guid(),
mediaItemId ?? _faker.Random.Guid(),
resolvedMediaKind,
lastPosition ?? _mediaPositionDtoFixture.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="ResumePointDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ResumePointDto"/> instances.</returns>
public List<ResumePointDto> 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;
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="TagConsumptionDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagConsumptionDtoFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_000;
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="TagConsumptionDto"/>.
/// </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="consumedDurationMilliseconds">Optional. The consumed duration of the media items that carry the tag, in milliseconds. Defaults to a bounded random duration.</param>
/// <returns>The created <see cref="TagConsumptionDto"/>.</returns>
public TagConsumptionDto Create(
string? name = null,
int? consumedItemCount = null,
long? consumedDurationMilliseconds = null)
{
return new TagConsumptionDto(
name ?? _faker.Lorem.Word().ToLowerInvariant(),
consumedItemCount ?? _faker.Random.Int(0, 1000),
consumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS));
}
/// <summary>
/// Creates a list of <see cref="TagConsumptionDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="TagConsumptionDto"/> instances.</returns>
public List<TagConsumptionDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,177 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.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.Application.Fixtures.Common.DataAccess.Entities.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="MediaConsumptionRecordEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaConsumptionRecordEntityFixture
{
private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_000;
private const int MAXIMUM_OFFSET_MILLISECONDS = 7_200_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
];
private readonly ConsumptionStatus[] _statuses =
[
ConsumptionStatus.InProgress,
ConsumptionStatus.Completed,
ConsumptionStatus.Stopped
];
/// <summary>
/// Creates a random valid <see cref="MediaConsumptionRecordEntity"/>.
/// </summary>
/// <remarks>
/// Every default produced here is accepted by the conversion of the entity to its domain aggregate: the status and end time agree, the last
/// activity never precedes the start, the end never precedes the last activity, consecutive pages are only counted for a book, and a generated
/// position always uses the position kind of its media kind. Supplying contradicting values is allowed, so that the invalid branches of the
/// conversion can be exercised.
/// </remarks>
/// <param name="id">Optional. The Id of the consumption record.</param>
/// <param name="userId">Optional. The Id of the user that started the session.</param>
/// <param name="libraryId">Optional. The Id of the media library that contains the media item.</param>
/// <param name="mediaKind">Optional. The kind of media that was consumed. Defaults to a random supported kind.</param>
/// <param name="mediaItemId">Optional. The Id of the consumed media item.</param>
/// <param name="status">Optional. The state of the 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, or before the last activity when it is supplied.</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="consumedDurationMilliseconds">Optional. The active duration consumed by the session, in milliseconds. Defaults to a bounded random duration.</param>
/// <param name="lastPositionKind">Optional. The kind of the last known position. Defaults to no position for a photo, a location for a book, and a time offset for every other kind.</param>
/// <param name="includeLastPositionKind">Whether the position kind should be included, or forced to <see langword="null"/>.</param>
/// <param name="lastPositionTimeOffsetMilliseconds">Optional. The last known position, in milliseconds. Defaults to a bounded random offset for a time offset position, and to <see langword="null"/> otherwise.</param>
/// <param name="includeLastPositionTimeOffsetMilliseconds">Whether the time offset should be included, or forced to <see langword="null"/>.</param>
/// <param name="lastPositionLocation">Optional. The last known opaque locator. Defaults to a random word for a location position, and to <see langword="null"/> otherwise.</param>
/// <param name="includeLastPositionLocation">Whether the location 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>
/// <param name="version">Optional. The optimistic concurrency version of the row. Defaults to a bounded random positive version.</param>
/// <param name="createdOnUtc">Optional. The date and time when the row was created. Defaults to the start of the session.</param>
/// <param name="createdBy">Optional. The Id of the user that created the row.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the row was last updated. Defaults to no value.</param>
/// <param name="includeUpdatedOnUtc">Whether the update time should be included, or forced to <see langword="null"/>.</param>
/// <param name="updatedBy">Optional. The Id of the user that last updated the row. Defaults to <see langword="null"/>.</param>
/// <param name="includeUpdatedBy">Whether the updating user Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MediaConsumptionRecordEntity"/>.</returns>
public MediaConsumptionRecordEntity Create(
Guid? id = null,
Guid? userId = null,
Guid? libraryId = null,
MediaKind? mediaKind = null,
Guid? mediaItemId = null,
ConsumptionStatus? status = null,
DateTime? startedOnUtc = null,
DateTime? lastActivityOnUtc = null,
DateTime? endedOnUtc = null,
bool includeEndedOnUtc = true,
long? consumedDurationMilliseconds = null,
MediaPositionKind? lastPositionKind = null,
bool includeLastPositionKind = true,
long? lastPositionTimeOffsetMilliseconds = null,
bool includeLastPositionTimeOffsetMilliseconds = true,
string? lastPositionLocation = null,
bool includeLastPositionLocation = true,
double? lastProgressFraction = null,
int? consecutivePagesRead = null,
long? version = null,
DateTime? createdOnUtc = null,
Guid? createdBy = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = true,
Guid? updatedBy = null,
bool includeUpdatedBy = true)
{
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
ConsumptionStatus resolvedStatus = status ?? _faker.Random.ArrayElement(_statuses);
DateTime resolvedStartedOnUtc = startedOnUtc ?? (lastActivityOnUtc.HasValue
? lastActivityOnUtc.Value.AddMinutes(-_faker.Random.Int(0, 120))
: 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? resolvedLastPositionKind = includeLastPositionKind
? lastPositionKind ?? ResolveDefaultPositionKind(resolvedMediaKind)
: null;
long? resolvedLastPositionTimeOffsetMilliseconds = includeLastPositionTimeOffsetMilliseconds
? lastPositionTimeOffsetMilliseconds ?? (resolvedLastPositionKind == MediaPositionKind.TimeOffset
? _faker.Random.Long(0, MAXIMUM_OFFSET_MILLISECONDS)
: (long?)null)
: null;
string? resolvedLastPositionLocation = includeLastPositionLocation
? lastPositionLocation ?? (resolvedLastPositionKind == MediaPositionKind.Location
? _faker.Lorem.Word()
: (string?)null)
: null;
return new MediaConsumptionRecordEntity
{
Id = id ?? _faker.Random.Guid(),
UserId = userId ?? _faker.Random.Guid(),
LibraryId = libraryId ?? _faker.Random.Guid(),
MediaKind = resolvedMediaKind,
MediaItemId = mediaItemId ?? _faker.Random.Guid(),
Status = resolvedStatus,
StartedOnUtc = resolvedStartedOnUtc,
LastActivityOnUtc = resolvedLastActivityOnUtc,
EndedOnUtc = resolvedEndedOnUtc,
ConsumedDurationMilliseconds = consumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS),
LastPositionKind = resolvedLastPositionKind,
LastPositionTimeOffsetMilliseconds = resolvedLastPositionTimeOffsetMilliseconds,
LastPositionLocation = resolvedLastPositionLocation,
LastProgressFraction = lastProgressFraction ?? _faker.Random.Double(0, 1),
ConsecutivePagesRead = consecutivePagesRead ?? (resolvedMediaKind == MediaKind.Book ? _faker.Random.Int(0, 100) : 0),
Version = version ?? _faker.Random.Long(1, 1000),
CreatedOnUtc = createdOnUtc ?? resolvedStartedOnUtc,
CreatedBy = createdBy ?? _faker.Random.Guid(),
UpdatedOnUtc = includeUpdatedOnUtc ? updatedOnUtc : null,
UpdatedBy = includeUpdatedBy ? updatedBy : null
};
}
/// <summary>
/// Creates a list of <see cref="MediaConsumptionRecordEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaConsumptionRecordEntity"/> instances.</returns>
public List<MediaConsumptionRecordEntity> 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;
}
}
@@ -0,0 +1,136 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.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.Application.Fixtures.Common.DataAccess.Entities.MediaConsumption;
/// <summary>
/// Fixture class for the <see cref="MediaResumePointEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaResumePointEntityFixture
{
private const int MAXIMUM_OFFSET_MILLISECONDS = 7_200_000;
private readonly Faker _faker = 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="MediaResumePointEntity"/>.
/// </summary>
/// <remarks>
/// Every default produced here is accepted by the conversion of the entity to its domain aggregate: the media kind can be resumed, the progress
/// fraction stays within its boundaries, and a generated position always uses the position kind of its media kind. Supplying contradicting values is
/// allowed, so that the invalid branches of the conversion can be exercised.
/// </remarks>
/// <param name="id">Optional. The Id of the resume point.</param>
/// <param name="userId">Optional. The Id of the user that owns the resume point.</param>
/// <param name="libraryId">Optional. The Id of the media library that contains the media item.</param>
/// <param name="mediaKind">Optional. The kind of media that is resumed. Defaults to a random resumable kind.</param>
/// <param name="mediaItemId">Optional. The Id of the media item to resume.</param>
/// <param name="lastPositionKind">Optional. The kind of the position at which the media item can be resumed. Defaults to a location for a book, and to a time offset for every other kind.</param>
/// <param name="lastPositionTimeOffsetMilliseconds">Optional. The position, in milliseconds. Defaults to a bounded random offset for a time offset position, and to <see langword="null"/> otherwise.</param>
/// <param name="includeLastPositionTimeOffsetMilliseconds">Whether the time offset should be included, or forced to <see langword="null"/>.</param>
/// <param name="lastPositionLocation">Optional. The opaque locator. Defaults to a random word for a location position, and to <see langword="null"/> otherwise.</param>
/// <param name="includeLastPositionLocation">Whether the location should be included, or forced to <see langword="null"/>.</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>
/// <param name="version">Optional. The optimistic concurrency version of the row. Defaults to a bounded random positive version.</param>
/// <param name="createdOnUtc">Optional. The date and time when the row was created. Defaults to the last consumption time.</param>
/// <param name="createdBy">Optional. The Id of the user that created the row.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the row was last updated. Defaults to no value.</param>
/// <param name="includeUpdatedOnUtc">Whether the update time should be included, or forced to <see langword="null"/>.</param>
/// <param name="updatedBy">Optional. The Id of the user that last updated the row. Defaults to <see langword="null"/>.</param>
/// <param name="includeUpdatedBy">Whether the updating user Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MediaResumePointEntity"/>.</returns>
public MediaResumePointEntity Create(
Guid? id = null,
Guid? userId = null,
Guid? libraryId = null,
MediaKind? mediaKind = null,
Guid? mediaItemId = null,
MediaPositionKind? lastPositionKind = null,
long? lastPositionTimeOffsetMilliseconds = null,
bool includeLastPositionTimeOffsetMilliseconds = true,
string? lastPositionLocation = null,
bool includeLastPositionLocation = true,
double? lastProgressFraction = null,
DateTime? lastConsumedOnUtc = null,
long? version = null,
DateTime? createdOnUtc = null,
Guid? createdBy = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = true,
Guid? updatedBy = null,
bool includeUpdatedBy = true)
{
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_resumableMediaKinds);
MediaPositionKind resolvedLastPositionKind = lastPositionKind ?? ResolveDefaultPositionKind(resolvedMediaKind);
long? resolvedLastPositionTimeOffsetMilliseconds = includeLastPositionTimeOffsetMilliseconds
? lastPositionTimeOffsetMilliseconds ?? (resolvedLastPositionKind == MediaPositionKind.TimeOffset
? _faker.Random.Long(0, MAXIMUM_OFFSET_MILLISECONDS)
: (long?)null)
: null;
string? resolvedLastPositionLocation = includeLastPositionLocation
? lastPositionLocation ?? (resolvedLastPositionKind == MediaPositionKind.Location
? _faker.Lorem.Word()
: (string?)null)
: null;
DateTime resolvedLastConsumedOnUtc = lastConsumedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 720));
return new MediaResumePointEntity
{
Id = id ?? _faker.Random.Guid(),
UserId = userId ?? _faker.Random.Guid(),
LibraryId = libraryId ?? _faker.Random.Guid(),
MediaKind = resolvedMediaKind,
MediaItemId = mediaItemId ?? _faker.Random.Guid(),
LastPositionKind = resolvedLastPositionKind,
LastPositionTimeOffsetMilliseconds = resolvedLastPositionTimeOffsetMilliseconds,
LastPositionLocation = resolvedLastPositionLocation,
LastProgressFraction = lastProgressFraction ?? _faker.Random.Double(0, 1),
LastConsumedOnUtc = resolvedLastConsumedOnUtc,
Version = version ?? _faker.Random.Long(1, 1000),
CreatedOnUtc = createdOnUtc ?? resolvedLastConsumedOnUtc,
CreatedBy = createdBy ?? _faker.Random.Guid(),
UpdatedOnUtc = includeUpdatedOnUtc ? updatedOnUtc : null,
UpdatedBy = includeUpdatedBy ? updatedBy : null
};
}
/// <summary>
/// Creates a list of <see cref="MediaResumePointEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaResumePointEntity"/> instances.</returns>
public List<MediaResumePointEntity> 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;
}
}
@@ -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())];
}
}
@@ -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())];
}
}
@@ -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;
}
}
@@ -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())];
}
}
@@ -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())];
}
}
@@ -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())];
}
}
@@ -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;
}
}
@@ -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())];
}
}