mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11: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
+90
@@ -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())];
|
||||
}
|
||||
}
|
||||
+126
@@ -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;
|
||||
}
|
||||
}
|
||||
+68
@@ -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())];
|
||||
}
|
||||
}
|
||||
+69
@@ -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())];
|
||||
}
|
||||
}
|
||||
+64
@@ -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())];
|
||||
}
|
||||
}
|
||||
+84
@@ -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;
|
||||
}
|
||||
}
|
||||
+48
@@ -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())];
|
||||
}
|
||||
}
|
||||
+177
@@ -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;
|
||||
}
|
||||
}
|
||||
+136
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user