Adds the music library track test suite

This commit is contained in:
BinaryAlley committed 2026-09-26 17:57:40 +03:00
1 parent dc2692e208
commit 12d310631b
89 files changed
+18849 -9

No files matched your search

@@ -0,0 +1,128 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.Common;
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
/// <summary>
/// Fixture class for the <see cref="AddTrackCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddTrackCommandFixture
{
private readonly Faker _faker = new();
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
private readonly MoodDtoFixture _moodDtoFixture = new();
private readonly IsrcDtoFixture _isrcDtoFixture = new();
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
/// <summary>
/// Creates a random valid command to add a track.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the track belongs to, taken from the route.</param>
/// <param name="artistId">Optional. The Id of the artist the track belongs to, taken from the route.</param>
/// <param name="albumId">Optional. The Id of the album the track belongs to, taken from the route.</param>
/// <param name="path">Optional. The file system path of the track.</param>
/// <param name="metadata">Optional. The audio metadata of the track.</param>
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
/// <param name="script">Optional. The script used by the language of the track.</param>
/// <param name="key">Optional. The musical key of the track.</param>
/// <param name="bpm">Optional. The tempo of the track in beats per minute.</param>
/// <param name="work">Optional. The title of the work the track is a recording of.</param>
/// <param name="musicBrainzRecordingId">Optional. The MusicBrainz identifier of the recording.</param>
/// <param name="musicBrainzTrackId">Optional. The MusicBrainz identifier of the track.</param>
/// <param name="musicBrainzWorkId">Optional. The MusicBrainz identifier of the work.</param>
/// <param name="moods">Optional. The list of moods of the track.</param>
/// <param name="isrcs">Optional. The list of ISRC of the track.</param>
/// <param name="contributors">Optional. The list of media contributors that performed on the track.</param>
/// <param name="ratings">Optional. The list of ratings for this track.</param>
/// <param name="trackId">Optional. The Id of the track, when it already exists.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or forced to <see langword="null"/>.</param>
/// <param name="includeContributors">Whether the contributors should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeRatings">Whether the ratings should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created command to add a track.</returns>
public AddTrackCommand Create(
string? libraryId = null,
string? artistId = null,
string? albumId = null,
string? path = null,
AudioMetadataDto? metadata = null,
int? trackNumber = null,
int? discNumber = null,
string? script = null,
MusicKey? key = null,
int? bpm = null,
string? work = null,
Guid? musicBrainzRecordingId = null,
Guid? musicBrainzTrackId = null,
Guid? musicBrainzWorkId = null,
List<MoodDto>? moods = null,
List<IsrcDto>? isrcs = null,
List<MediaContributorReferenceDto>? contributors = null,
List<AudioRatingDto>? ratings = null,
Guid? trackId = null,
bool includeLibraryId = true,
bool includeArtistId = true,
bool includeAlbumId = true,
bool includePath = true,
bool includeMetadata = true,
bool includeTrackNumber = true,
bool includeOptionalProperties = true,
bool includeContributors = true,
bool includeRatings = true)
{
return new AddTrackCommand(
includeLibraryId ? libraryId ?? Guid.NewGuid().ToString() : null,
includeArtistId ? artistId ?? Guid.NewGuid().ToString() : null,
includeAlbumId ? albumId ?? Guid.NewGuid().ToString() : null,
includePath ? path ?? Path.Combine(Path.GetTempPath(), "lumina-tracks", _faker.System.FileName()) : null,
includeMetadata ? metadata ?? _audioMetadataDtoFixture.Create() : null,
includeTrackNumber ? trackNumber ?? _faker.Random.Int(1, 30) : null,
includeOptionalProperties ? discNumber ?? _faker.Random.Int(1, 3) : null,
includeOptionalProperties ? script ?? _faker.Random.AlphaNumeric(4) : null,
includeOptionalProperties ? key ?? _faker.PickRandom<MusicKey>() : null,
includeOptionalProperties ? bpm ?? _faker.Random.Int(40, 220) : null,
includeOptionalProperties ? work ?? _faker.Lorem.Sentence() : null,
includeOptionalProperties ? musicBrainzRecordingId ?? _faker.Random.Guid() : null,
includeOptionalProperties ? musicBrainzTrackId ?? _faker.Random.Guid() : null,
includeOptionalProperties ? musicBrainzWorkId ?? _faker.Random.Guid() : null,
includeOptionalProperties ? moods ?? _moodDtoFixture.CreateMany(_faker.Random.Int(1, 3)) : null,
includeOptionalProperties ? isrcs ?? _isrcDtoFixture.CreateMany(_faker.Random.Int(1, 3)) : null,
includeContributors ? contributors ?? _mediaContributorReferenceDtoFixture.CreateMany(_faker.Random.Int(1, 3)) : null,
includeRatings ? ratings ?? _audioRatingDtoFixture.CreateMany(_faker.Random.Int(1, 3)) : null,
trackId);
}
/// <summary>
/// Creates a list of <see cref="AddTrackCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<AddTrackCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.DeleteTrack;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.DeleteTrack;
/// <summary>
/// Fixture class for the <see cref="DeleteTrackCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteTrackCommandFixture
{
/// <summary>
/// Creates a random valid <see cref="DeleteTrackCommand"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the track belongs to.</param>
/// <param name="artistId">Optional. The Id of the artist the album of the track belongs to.</param>
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
/// <param name="trackId">Optional. The Id of the track to delete.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="DeleteTrackCommand"/>.</returns>
public DeleteTrackCommand Create(
string? libraryId = null,
string? artistId = null,
string? albumId = null,
string? trackId = null,
bool includeLibraryId = true,
bool includeArtistId = true,
bool includeAlbumId = true,
bool includeTrackId = true)
{
return new DeleteTrackCommand(
includeLibraryId ? (libraryId ?? Guid.NewGuid().ToString()) : null,
includeArtistId ? (artistId ?? Guid.NewGuid().ToString()) : null,
includeAlbumId ? (albumId ?? Guid.NewGuid().ToString()) : null,
includeTrackId ? (trackId ?? Guid.NewGuid().ToString()) : null);
}
/// <summary>
/// Creates a list of <see cref="DeleteTrackCommand"/> instances with randomized test data.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<DeleteTrackCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,129 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.Common;
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
/// <summary>
/// Fixture class for the <see cref="UpdateTrackCommand"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateTrackCommandFixture
{
private readonly Faker _faker = new();
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
private readonly MoodDtoFixture _moodDtoFixture = new();
private readonly IsrcDtoFixture _isrcDtoFixture = new();
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
/// <summary>
/// Creates a random valid command to update a track.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the track belongs to.</param>
/// <param name="artistId">Optional. The Id of the artist the track belongs to.</param>
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
/// <param name="trackId">Optional. The Id of the track to update.</param>
/// <param name="path">Optional. The file system path of the track.</param>
/// <param name="metadata">Optional. The audio metadata of the track.</param>
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
/// <param name="script">Optional. The script used by the language of the track.</param>
/// <param name="key">Optional. The musical key of the track.</param>
/// <param name="bpm">Optional. The tempo of the track in beats per minute.</param>
/// <param name="work">Optional. The title of the work the track is a recording of.</param>
/// <param name="musicBrainzRecordingId">Optional. The MusicBrainz identifier of the recording.</param>
/// <param name="musicBrainzTrackId">Optional. The MusicBrainz identifier of the track.</param>
/// <param name="musicBrainzWorkId">Optional. The MusicBrainz identifier of the work.</param>
/// <param name="moods">Optional. The moods of the track.</param>
/// <param name="isrcs">Optional. The ISRC codes of the track.</param>
/// <param name="contributors">Optional. The media contributors that performed on the track.</param>
/// <param name="ratings">Optional. The ratings of the track.</param>
/// <param name="includeOptionalProperties">Whether the optional properties that are not explicitly provided should be randomized, or forced to <see langword="null"/>.</param>
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeContributors">Whether the contributors list should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeRatings">Whether the ratings list should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created command to update a track.</returns>
public UpdateTrackCommand Create(
string? libraryId = null,
string? artistId = null,
string? albumId = null,
string? trackId = null,
string? path = null,
AudioMetadataDto? metadata = null,
int? trackNumber = null,
int? discNumber = null,
string? script = null,
MusicKey? key = null,
int? bpm = null,
string? work = null,
Guid? musicBrainzRecordingId = null,
Guid? musicBrainzTrackId = null,
Guid? musicBrainzWorkId = null,
List<MoodDto>? moods = null,
List<IsrcDto>? isrcs = null,
List<MediaContributorReferenceDto>? contributors = null,
List<AudioRatingDto>? ratings = null,
bool includeOptionalProperties = true,
bool includeMetadata = true,
bool includeContributors = true,
bool includeRatings = true,
bool includeLibraryId = true,
bool includeArtistId = true,
bool includeAlbumId = true,
bool includeTrackId = true,
bool includePath = true,
bool includeTrackNumber = true)
{
return new UpdateTrackCommand(
includeLibraryId ? (libraryId ?? _faker.Random.Guid().ToString()) : null,
includeArtistId ? (artistId ?? _faker.Random.Guid().ToString()) : null,
includeAlbumId ? (albumId ?? _faker.Random.Guid().ToString()) : null,
includeTrackId ? (trackId ?? _faker.Random.Guid().ToString()) : null,
includePath ? (path ?? _faker.System.FilePath()) : null,
includeMetadata ? (metadata ?? _audioMetadataDtoFixture.Create()) : null,
includeTrackNumber ? (trackNumber ?? _faker.Random.Int(1, 20)) : null,
includeOptionalProperties ? (discNumber ?? _faker.Random.Int(1, 3)) : null,
includeOptionalProperties ? (script ?? _faker.Random.String2(_faker.Random.Number(1, 50))) : null,
includeOptionalProperties ? (key ?? _faker.PickRandom<MusicKey>()) : null,
includeOptionalProperties ? (bpm ?? _faker.Random.Int(40, 240)) : null,
includeOptionalProperties ? (work ?? _faker.Music.Genre()) : null,
includeOptionalProperties ? (musicBrainzRecordingId ?? _faker.Random.Guid()) : null,
includeOptionalProperties ? (musicBrainzTrackId ?? _faker.Random.Guid()) : null,
includeOptionalProperties ? (musicBrainzWorkId ?? _faker.Random.Guid()) : null,
includeOptionalProperties ? (moods ?? [.. _moodDtoFixture.CreateMany(_faker.Random.Int(1, 3))]) : null,
includeOptionalProperties ? (isrcs ?? [.. _isrcDtoFixture.CreateMany(_faker.Random.Int(1, 3))]) : null,
includeContributors ? (contributors ?? [.. _mediaContributorReferenceDtoFixture.CreateMany(_faker.Random.Int(1, 3))]) : null,
includeRatings ? (ratings ?? [.. _audioRatingDtoFixture.CreateMany(_faker.Random.Int(1, 3))]) : null);
}
/// <summary>
/// Creates a list of <see cref="UpdateTrackCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdateTrackCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetTrack;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetTrack;
/// <summary>
/// Fixture class for the <see cref="GetTrackQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetTrackQueryFixture
{
/// <summary>
/// Creates a random valid <see cref="GetTrackQuery"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the track belongs to.</param>
/// <param name="artistId">Optional. The Id of the artist the album of the track belongs to.</param>
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
/// <param name="trackId">Optional. The Id of the track to get.</param>
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="GetTrackQuery"/>.</returns>
public GetTrackQuery Create(
string? libraryId = null,
string? artistId = null,
string? albumId = null,
string? trackId = null,
bool includeLibraryId = true,
bool includeArtistId = true,
bool includeAlbumId = true,
bool includeTrackId = true)
{
return new GetTrackQuery(
includeLibraryId ? (libraryId ?? Guid.NewGuid().ToString()) : null,
includeArtistId ? (artistId ?? Guid.NewGuid().ToString()) : null,
includeAlbumId ? (albumId ?? Guid.NewGuid().ToString()) : null,
includeTrackId ? (trackId ?? Guid.NewGuid().ToString()) : null);
}
/// <summary>
/// Creates a list of <see cref="GetTrackQuery"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="GetTrackQuery"/> instances.</returns>
public List<GetTrackQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}