Implements tests for commit 45f9aa3bd5

This commit is contained in:
BinaryAlley committed 2026-10-28 22:34:32 +02:00
1 parent d61a114d80
commit aeefa9487e
44 files changed
+6929 -18

No files matched your search

@@ -0,0 +1,75 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="NormalizedTrackDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class NormalizedTrackDtoFixture
{
private readonly Faker _faker = new();
private readonly NormalizedTrackSegmentDtoFixture _normalizedTrackSegmentDtoFixture = new();
/// <summary>
/// Creates a random valid <see cref="NormalizedTrackDto"/>.
/// </summary>
/// <param name="trackId">Optional. The Id of the track whose audio the cached entry holds.</param>
/// <param name="cacheId">Optional. The opaque identifier of the cached entry that holds the normalized audio.</param>
/// <param name="mode">Optional. The way the audio is delivered.</param>
/// <param name="container">Optional. The container of the delivered audio.</param>
/// <param name="codec">Optional. The codec of the delivered audio.</param>
/// <param name="segmentDurationSeconds">Optional. The duration of each segment of the delivered audio, in seconds.</param>
/// <param name="durationInSeconds">Optional. The duration of the produced and cached audio, in seconds.</param>
/// <param name="segments">Optional. The segments that make up the delivered audio, in playback order.</param>
/// <param name="includeSegments">Whether the segments should be included, or forced to an empty collection.</param>
/// <returns>The created <see cref="NormalizedTrackDto"/>.</returns>
public NormalizedTrackDto Create(
Guid? trackId = null,
string? cacheId = null,
PlaybackDeliveryMode? mode = null,
string? container = null,
string? codec = null,
int? segmentDurationSeconds = null,
int? durationInSeconds = null,
IReadOnlyList<NormalizedTrackSegmentDto>? segments = null,
bool includeSegments = true)
{
int resolvedSegmentDurationSeconds = segmentDurationSeconds ?? _faker.Random.Int(1, 30);
List<NormalizedTrackSegmentDto> generatedSegments = [];
int generatedSegmentCount = _faker.Random.Int(1, 6);
for (int index = 0; index < generatedSegmentCount; index++)
generatedSegments.Add(_normalizedTrackSegmentDtoFixture.Create(
index: index,
startSeconds: index * resolvedSegmentDurationSeconds,
durationSeconds: resolvedSegmentDurationSeconds));
return new NormalizedTrackDto(
trackId ?? _faker.Random.Guid(),
cacheId ?? _faker.Random.Guid().ToString("N") + _faker.Random.Guid().ToString("N"),
mode ?? _faker.PickRandom(PlaybackDeliveryMode.Remux, PlaybackDeliveryMode.Transcode),
container ?? _faker.PickRandom("MP3", "AAC", "FLAC", "WAV", "OGG"),
codec ?? _faker.PickRandom("MP3", "AAC", "FLAC", "PCM", "OPUS"),
resolvedSegmentDurationSeconds,
durationInSeconds ?? _faker.Random.Int(1, 3600),
includeSegments ? (segments ?? generatedSegments) : []);
}
/// <summary>
/// Creates a list of <see cref="NormalizedTrackDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="NormalizedTrackDto"/> instances.</returns>
public List<NormalizedTrackDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,102 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="NormalizedTrackRequestDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class NormalizedTrackRequestDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="NormalizedTrackRequestDto"/>.
/// </summary>
/// <param name="trackId">Optional. The Id of the track whose audio is normalized.</param>
/// <param name="userId">Optional. The Id of the user whose request starts the production.</param>
/// <param name="sourcePath">Optional. The file system path of the stored audio file of the track.</param>
/// <param name="allowedRoots">Optional. The content locations the source path is allowed to be inside.</param>
/// <param name="sourceContainer">Optional. The container of the stored audio file, as captured by the probe.</param>
/// <param name="mode">Optional. The way the audio is delivered.</param>
/// <param name="container">Optional. The container of the delivered audio.</param>
/// <param name="codec">Optional. The codec of the delivered audio.</param>
/// <param name="segmentDurationSeconds">Optional. The duration of each segment of the delivered audio, in seconds.</param>
/// <param name="durationInSeconds">Optional. The duration of the audio of the track, in seconds.</param>
/// <param name="bitrate">Optional. The stored audio bitrate of the track, in kbps.</param>
/// <param name="sampleRate">Optional. The sample rate of the stored audio of the track, in Hz.</param>
/// <param name="channels">Optional. The number of audio channels of the track.</param>
/// <param name="bitDepth">Optional. The bit depth of the stored audio of the track.</param>
/// <param name="quality">Optional. The quality cap applied to the delivered audio when it has to be re-encoded.</param>
/// <param name="sourceLength">Optional. The length the source file had when the delivery was declared, in bytes.</param>
/// <param name="sourceLastModifiedUtc">Optional. The last modification time the source file had when the delivery was declared.</param>
/// <param name="includeSourceContainer">Whether the source container should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeBitrate">Whether the bitrate should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeBitDepth">Whether the bit depth should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="NormalizedTrackRequestDto"/>.</returns>
public NormalizedTrackRequestDto Create(
Guid? trackId = null,
Guid? userId = null,
string? sourcePath = null,
IReadOnlyList<string>? allowedRoots = null,
string? sourceContainer = null,
PlaybackDeliveryMode? mode = null,
string? container = null,
string? codec = null,
int? segmentDurationSeconds = null,
int? durationInSeconds = null,
int? bitrate = null,
int? sampleRate = null,
int? channels = null,
int? bitDepth = null,
PlaybackStreamingQuality? quality = null,
long? sourceLength = null,
DateTime? sourceLastModifiedUtc = null,
bool includeSourceContainer = true,
bool includeBitrate = true,
bool includeBitDepth = true)
{
IReadOnlyList<string> resolvedAllowedRoots = allowedRoots ?? [Path.Combine(Path.GetTempPath(), "lumina-tests", _faker.Random.AlphaNumeric(12))];
string resolvedSourcePath = sourcePath ?? (resolvedAllowedRoots.Count > 0
? Path.Combine(resolvedAllowedRoots[0], "track-" + _faker.Random.AlphaNumeric(8) + ".flac")
: Path.Combine(Path.GetTempPath(), "track-" + _faker.Random.AlphaNumeric(8) + ".flac"));
return new NormalizedTrackRequestDto(
trackId ?? _faker.Random.Guid(),
userId ?? _faker.Random.Guid(),
resolvedSourcePath,
resolvedAllowedRoots,
includeSourceContainer ? (sourceContainer ?? _faker.PickRandom("FLAC", "MP3", "OGG", "MP4", "WAV")) : null,
mode ?? _faker.PickRandom(PlaybackDeliveryMode.Remux, PlaybackDeliveryMode.Transcode),
container ?? _faker.PickRandom("MP3", "AAC", "FLAC", "WAV", "OGG"),
codec ?? _faker.PickRandom("MP3", "AAC", "FLAC", "PCM", "OPUS"),
segmentDurationSeconds ?? _faker.Random.Int(1, 30),
durationInSeconds ?? _faker.Random.Int(1, 3600),
includeBitrate ? (bitrate ?? _faker.Random.Int(96, 1411)) : null,
sampleRate ?? _faker.PickRandom(44100, 48000, 96000),
channels ?? _faker.PickRandom(1, 2, 6),
includeBitDepth ? (bitDepth ?? _faker.Random.Int(16, 24)) : null,
quality ?? _faker.PickRandom<PlaybackStreamingQuality>(),
sourceLength ?? _faker.Random.Long(1, 100_000_000),
sourceLastModifiedUtc ?? _faker.Date.Past().ToUniversalTime());
}
/// <summary>
/// Creates a list of <see cref="NormalizedTrackRequestDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="NormalizedTrackRequestDto"/> instances.</returns>
public List<NormalizedTrackRequestDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="NormalizedTrackSegmentDataDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class NormalizedTrackSegmentDataDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="NormalizedTrackSegmentDataDto"/>.
/// </summary>
/// <param name="content">Optional. The read stream over the segment. When it is not supplied, a fresh empty <see cref="MemoryStream"/> is created.</param>
/// <param name="length">Optional. The length of the segment, in bytes.</param>
/// <param name="startSeconds">Optional. The exact start of the segment on the track timeline, in seconds.</param>
/// <param name="container">Optional. The container of the delivered audio.</param>
/// <param name="segmentCount">Optional. The number of segments the production holds.</param>
/// <param name="durationInSeconds">Optional. The duration of the produced normalized audio, in seconds.</param>
/// <returns>The created <see cref="NormalizedTrackSegmentDataDto"/>.</returns>
public NormalizedTrackSegmentDataDto Create(
Stream? content = null,
long? length = null,
decimal? startSeconds = null,
string? container = null,
int? segmentCount = null,
int? durationInSeconds = null)
{
return new NormalizedTrackSegmentDataDto(
content ?? new MemoryStream(),
length ?? _faker.Random.Long(1, 10_000_000),
startSeconds ?? _faker.Random.Decimal(0, 3600),
container ?? _faker.PickRandom("MP3", "AAC", "FLAC", "WAV", "OGG"),
segmentCount ?? _faker.Random.Int(1, 1000),
durationInSeconds ?? _faker.Random.Int(1, 3600));
}
/// <summary>
/// Creates a list of <see cref="NormalizedTrackSegmentDataDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="NormalizedTrackSegmentDataDto"/> instances.</returns>
public List<NormalizedTrackSegmentDataDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="NormalizedTrackSegmentDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class NormalizedTrackSegmentDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="NormalizedTrackSegmentDto"/>.
/// </summary>
/// <param name="index">Optional. The zero based position of the segment in the delivered audio.</param>
/// <param name="startSeconds">Optional. The time, in seconds from the start of the track, at which the segment starts.</param>
/// <param name="durationSeconds">Optional. The duration of the segment, in seconds.</param>
/// <param name="length">Optional. The length of the segment, in bytes.</param>
/// <returns>The created <see cref="NormalizedTrackSegmentDto"/>.</returns>
public NormalizedTrackSegmentDto Create(
int? index = null,
decimal? startSeconds = null,
decimal? durationSeconds = null,
long? length = null)
{
return new NormalizedTrackSegmentDto(
index ?? _faker.Random.Int(0, 1000),
startSeconds ?? _faker.Random.Decimal(0, 3600),
durationSeconds ?? _faker.Random.Decimal(1, 30),
length ?? _faker.Random.Long(1, 10_000_000));
}
/// <summary>
/// Creates a list of <see cref="NormalizedTrackSegmentDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="NormalizedTrackSegmentDto"/> instances.</returns>
public List<NormalizedTrackSegmentDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="PlaybackDeliveryDecisionDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaybackDeliveryDecisionDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PlaybackDeliveryDecisionDto"/>.
/// </summary>
/// <param name="mode">Optional. The way the audio is delivered.</param>
/// <param name="container">Optional. The container of the delivered audio.</param>
/// <param name="codec">Optional. The codec of the delivered audio.</param>
/// <param name="shape">Optional. The shape the delivered audio is addressed and seeked by.</param>
/// <param name="segmentDurationSeconds">Optional. The duration of each segment of the delivered audio, in seconds.</param>
/// <returns>The created <see cref="PlaybackDeliveryDecisionDto"/>.</returns>
public PlaybackDeliveryDecisionDto Create(
PlaybackDeliveryMode? mode = null,
string? container = null,
string? codec = null,
PlaybackDeliveryShape? shape = null,
int? segmentDurationSeconds = null)
{
PlaybackDeliveryShape resolvedShape = shape ?? _faker.PickRandom<PlaybackDeliveryShape>();
return new PlaybackDeliveryDecisionDto(
mode ?? _faker.PickRandom(PlaybackDeliveryMode.Remux, PlaybackDeliveryMode.Transcode),
container ?? _faker.PickRandom("MP3", "AAC", "FLAC", "WAV", "OGG"),
codec ?? _faker.PickRandom("MP3", "AAC", "FLAC", "PCM", "OPUS"),
resolvedShape,
segmentDurationSeconds ?? (resolvedShape == PlaybackDeliveryShape.TimeAddressedSegments ? _faker.Random.Int(1, 30) : 0));
}
/// <summary>
/// Creates a list of <see cref="PlaybackDeliveryDecisionDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaybackDeliveryDecisionDto"/> instances.</returns>
public List<PlaybackDeliveryDecisionDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
/// <summary>
/// Fixture class for the <see cref="PlaybackDeliveryHandleDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaybackDeliveryHandleDtoFixture
{
private readonly Faker _faker = new();
private readonly NormalizedTrackRequestDtoFixture _normalizedTrackRequestDtoFixture = new();
/// <summary>
/// Creates a random valid <see cref="PlaybackDeliveryHandleDto"/>.
/// </summary>
/// <param name="request">Optional. The complete normalization request the delivery declares.</param>
/// <param name="shape">Optional. The shape the delivered audio is addressed by.</param>
/// <param name="libraryId">Optional. The Id of the library the track belongs to.</param>
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
/// <param name="artistId">Optional. The Id of the artist that owns the album.</param>
/// <returns>The created <see cref="PlaybackDeliveryHandleDto"/>.</returns>
public PlaybackDeliveryHandleDto Create(
NormalizedTrackRequestDto? request = null,
PlaybackDeliveryShape? shape = null,
Guid? libraryId = null,
Guid? albumId = null,
Guid? artistId = null)
{
return new PlaybackDeliveryHandleDto(
request ?? _normalizedTrackRequestDtoFixture.Create(),
shape ?? _faker.PickRandom<PlaybackDeliveryShape>(),
libraryId ?? _faker.Random.Guid(),
albumId ?? _faker.Random.Guid(),
artistId ?? _faker.Random.Guid());
}
/// <summary>
/// Creates a list of <see cref="PlaybackDeliveryHandleDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaybackDeliveryHandleDto"/> instances.</returns>
public List<PlaybackDeliveryHandleDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,84 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
/// <summary>
/// Fixture class for the <see cref="TrackPlaybackManifestDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class TrackPlaybackManifestDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="TrackPlaybackManifestDto"/>.
/// </summary>
/// <param name="path">Optional. The file system path of the stored audio file of the track.</param>
/// <param name="container">Optional. The container of the audio file of the track.</param>
/// <param name="audioCodec">Optional. The audio codec used by the audio file of the track.</param>
/// <param name="durationInSeconds">Optional. The duration of the audio of the track, in seconds.</param>
/// <param name="sampleRate">Optional. The sample rate of the audio of the track, in Hz.</param>
/// <param name="channels">Optional. The number of audio channels of the track.</param>
/// <param name="bitDepth">Optional. The bit depth of the audio of the track.</param>
/// <param name="bitrate">Optional. The bitrate of the audio of the track, in kbps.</param>
/// <param name="replayGainTrackGain">Optional. The ReplayGain track gain of the track, in decibels.</param>
/// <param name="replayGainTrackPeak">Optional. The ReplayGain track peak of the track.</param>
/// <param name="replayGainAlbumGain">Optional. The ReplayGain album gain of the track, in decibels.</param>
/// <param name="replayGainAlbumPeak">Optional. The ReplayGain album peak of the track.</param>
/// <param name="includeContainer">Whether the container should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAudioCodec">Whether the audio codec should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeBitDepth">Whether the bit depth should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeBitrate">Whether the bitrate should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeReplayGain">Whether the ReplayGain values should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="TrackPlaybackManifestDto"/>.</returns>
public TrackPlaybackManifestDto Create(
string? path = null,
string? container = null,
string? audioCodec = null,
int? durationInSeconds = null,
int? sampleRate = null,
int? channels = null,
int? bitDepth = null,
int? bitrate = null,
decimal? replayGainTrackGain = null,
decimal? replayGainTrackPeak = null,
decimal? replayGainAlbumGain = null,
decimal? replayGainAlbumPeak = null,
bool includeContainer = true,
bool includeAudioCodec = true,
bool includeBitDepth = true,
bool includeBitrate = true,
bool includeReplayGain = true)
{
return new TrackPlaybackManifestDto(
path ?? Path.Combine(_faker.System.DirectoryPath(), _faker.System.FileName("flac")),
includeContainer ? (container ?? _faker.PickRandom("FLAC", "MP3", "OGG", "MP4", "AAC", "WAV")) : null,
includeAudioCodec ? (audioCodec ?? _faker.PickRandom("FLAC", "MP3", "AAC", "ALAC", "PCM")) : null,
durationInSeconds ?? _faker.Random.Int(1, 3600),
sampleRate ?? _faker.PickRandom(44100, 48000, 96000),
channels ?? _faker.PickRandom(1, 2, 6),
includeBitDepth ? (bitDepth ?? _faker.Random.Int(8, 32)) : null,
includeBitrate ? (bitrate ?? _faker.Random.Int(96, 1411)) : null,
includeReplayGain ? (replayGainTrackGain ?? _faker.Random.Decimal(-20m, 0m)) : null,
includeReplayGain ? (replayGainTrackPeak ?? _faker.Random.Decimal(0m, 1.5m)) : null,
includeReplayGain ? (replayGainAlbumGain ?? _faker.Random.Decimal(-20m, 0m)) : null,
includeReplayGain ? (replayGainAlbumPeak ?? _faker.Random.Decimal(0m, 1.5m)) : null);
}
/// <summary>
/// Creates a list of <see cref="TrackPlaybackManifestDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="TrackPlaybackManifestDto"/> instances.</returns>
public List<TrackPlaybackManifestDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}