mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Adds the music library track test suite
This commit is contained in:
1 parent
dc2692e208
commit
12d310631b
89 files changed
+18849
-9
No files matched your search
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TrackLiteRow"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TrackLiteRowFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TrackLiteRow"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the track.</param>
|
||||
/// <param name="title">Optional. The title 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="includeDiscNumber">Whether the disc number should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="TrackLiteRow"/>.</returns>
|
||||
public TrackLiteRow Create(
|
||||
Guid? id = null,
|
||||
string? title = null,
|
||||
int? trackNumber = null,
|
||||
int? discNumber = null,
|
||||
bool includeDiscNumber = true)
|
||||
{
|
||||
return new TrackLiteRow
|
||||
{
|
||||
Id = id ?? _faker.Random.Guid(),
|
||||
Title = title ?? _faker.Lorem.Sentence(),
|
||||
TrackNumber = trackNumber ?? _faker.Random.Int(1, 30),
|
||||
DiscNumber = includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TrackLiteRow"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="TrackLiteRow"/> instances.</returns>
|
||||
public List<TrackLiteRow> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AlbumContributorEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AlbumContributorEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AlbumContributorEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the participation.</param>
|
||||
/// <param name="albumId">Optional. The Id of the album the contributor participated in.</param>
|
||||
/// <param name="mediaContributorId">Optional. The Id of the media contributor.</param>
|
||||
/// <param name="role">Optional. The role the contributor played in the album.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the participation.</param>
|
||||
/// <returns>The created <see cref="AlbumContributorEntity"/>.</returns>
|
||||
public AlbumContributorEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? albumId = null,
|
||||
Guid? mediaContributorId = null,
|
||||
MediaContributorRole? role = null,
|
||||
Guid? createdBy = null)
|
||||
{
|
||||
return new AlbumContributorEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
AlbumId = albumId ?? Guid.NewGuid(),
|
||||
MediaContributorId = mediaContributorId ?? Guid.NewGuid(),
|
||||
Role = role ?? _faker.PickRandom<MediaContributorRole>(),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = createdBy ?? Guid.NewGuid(),
|
||||
UpdatedOnUtc = _faker.Random.Bool() ? _faker.Date.Recent() : null,
|
||||
UpdatedBy = _faker.Random.Bool() ? Guid.NewGuid() : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AlbumContributorEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <param name="albumId">Optional. The Id of the album the contributors participated in.</param>
|
||||
/// <returns>List of configured <see cref="AlbumContributorEntity"/> instances.</returns>
|
||||
public List<AlbumContributorEntity> CreateMany(int count = 3, Guid? albumId = null)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create(albumId: albumId))];
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Fixtures.Common.Setup;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AlbumEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AlbumEntityFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly AlbumContributorEntityFixture _albumContributorEntityFixture = new();
|
||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AlbumEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the album.</param>
|
||||
/// <param name="artistId">Optional. The Id of the artist that owns the album.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that owns the album.</param>
|
||||
/// <param name="title">Optional. The title of the album.</param>
|
||||
/// <param name="tracks">Optional. The tracks of the album.</param>
|
||||
/// <param name="includeTracks">Whether the album should own a generated track, or no track at all.</param>
|
||||
/// <param name="includeMetadata">Whether the owned metadata collections (Tags, Genres, Contributors, Ratings) should be included, or forced to empty collections.</param>
|
||||
/// <param name="originalReleaseDate">Optional. The original release date of the album.</param>
|
||||
/// <param name="originalReleaseYear">Optional. The original release year of the album.</param>
|
||||
/// <param name="reReleaseDate">Optional. The re-release date of the album.</param>
|
||||
/// <param name="reReleaseYear">Optional. The re-release year of the album.</param>
|
||||
/// <param name="barcode">Optional. The barcode of the album.</param>
|
||||
/// <param name="includeOriginalReleaseDate">Whether the original release date should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeOriginalReleaseYear">Whether the original release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReReleaseDate">Whether the re-release date should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReReleaseYear">Whether the re-release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeBarcode">Whether the barcode should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AlbumEntity"/>.</returns>
|
||||
public AlbumEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? artistId = null,
|
||||
Guid? libraryId = null,
|
||||
string? title = null,
|
||||
List<TrackEntity>? tracks = null,
|
||||
bool includeTracks = true,
|
||||
bool includeMetadata = true,
|
||||
DateOnly? originalReleaseDate = null,
|
||||
int? originalReleaseYear = null,
|
||||
DateOnly? reReleaseDate = null,
|
||||
int? reReleaseYear = null,
|
||||
string? barcode = null,
|
||||
bool includeOriginalReleaseDate = true,
|
||||
bool includeOriginalReleaseYear = true,
|
||||
bool includeReReleaseDate = true,
|
||||
bool includeReReleaseYear = true,
|
||||
bool includeBarcode = true)
|
||||
{
|
||||
Guid resolvedId = id ?? Guid.NewGuid();
|
||||
Guid resolvedArtistId = artistId ?? Guid.NewGuid();
|
||||
Guid resolvedLibraryId = libraryId ?? Guid.NewGuid();
|
||||
const int MAXIMUM_RELEASE_YEAR = 2026;
|
||||
int resolvedOriginalReleaseYear = originalReleaseYear ?? _random.Next(1900, MAXIMUM_RELEASE_YEAR);
|
||||
int resolvedReReleaseYearUpperBound = Math.Max(resolvedOriginalReleaseYear + 1, MAXIMUM_RELEASE_YEAR);
|
||||
int resolvedReReleaseYear = reReleaseYear ?? _random.Next(resolvedOriginalReleaseYear, resolvedReReleaseYearUpperBound);
|
||||
DateOnly resolvedOriginalReleaseDate = originalReleaseDate ?? _faker.DateOnlyBetween(new DateOnly(resolvedOriginalReleaseYear, 1, 1), new DateOnly(resolvedOriginalReleaseYear, 12, 31));
|
||||
DateOnly resolvedReReleaseDate = reReleaseDate ?? _faker.DateOnlyBetween(resolvedReReleaseYear == resolvedOriginalReleaseYear ? resolvedOriginalReleaseDate : new DateOnly(resolvedReReleaseYear, 1, 1), new DateOnly(resolvedReReleaseYear, 12, 31));
|
||||
List<TrackEntity> resolvedTracks = tracks ?? (includeTracks ? [_trackEntityFixture.Create(albumId: resolvedId, libraryId: resolvedLibraryId, includeMetadata: includeMetadata, includeOriginalReleaseDate: includeOriginalReleaseDate, includeOriginalReleaseYear: includeOriginalReleaseYear, includeReReleaseDate: includeReReleaseDate, includeReReleaseYear: includeReReleaseYear)] : []);
|
||||
|
||||
return new Faker<AlbumEntity>()
|
||||
.CustomInstantiator(f => new AlbumEntity
|
||||
{
|
||||
Id = resolvedId,
|
||||
ArtistId = resolvedArtistId,
|
||||
LibraryId = resolvedLibraryId,
|
||||
Title = default!,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.OriginalReleaseDate, includeOriginalReleaseDate ? resolvedOriginalReleaseDate : (DateOnly?)null)
|
||||
.RuleFor(x => x.OriginalReleaseYear, includeOriginalReleaseYear ? resolvedOriginalReleaseYear : (int?)null)
|
||||
.RuleFor(x => x.ReReleaseDate, includeReReleaseDate ? resolvedReReleaseDate : (DateOnly?)null)
|
||||
.RuleFor(x => x.ReReleaseYear, includeReReleaseYear ? resolvedReReleaseYear : (int?)null)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.PickRandom<ReleaseCountry>())
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.ReleaseType, f => f.PickRandom<MusicReleaseType>())
|
||||
.RuleFor(x => x.ReleaseStatus, f => f.PickRandom<MusicReleaseStatus>())
|
||||
.RuleFor(x => x.TotalDiscs, _random.Next(1, 3))
|
||||
.RuleFor(x => x.TotalTracks, resolvedTracks.Count)
|
||||
.RuleFor(x => x.MediaFormat, f => f.PickRandom<MusicMediaFormat>())
|
||||
.RuleFor(x => x.Barcode, f => includeBarcode ? (barcode ?? f.Random.String2(f.Random.Number(12, 13), "0123456789")) : null)
|
||||
.RuleFor(x => x.CatalogNumber, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.MusicBrainzReleaseId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.MusicBrainzReleaseGroupId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.MusicBrainzReleaseArtistId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Tags, f => includeMetadata ? [.. _tagEntityFixture.CreateMany(f.Random.Number(1, 3))] : [])
|
||||
.RuleFor(x => x.Genres, f => includeMetadata ? [.. _genreEntityFixture.CreateMany(f.Random.Number(1, 3))] : [])
|
||||
.RuleFor(x => x.Contributors, f => includeMetadata ? _albumContributorEntityFixture.CreateMany(f.Random.Number(1, 3), albumId: resolvedId) : [])
|
||||
.RuleFor(x => x.Ratings, f => includeMetadata ? _audioRatingEntityFixture.CreateMany(f.Random.Number(1, 3)) : [])
|
||||
.RuleFor(x => x.Tracks, resolvedTracks)
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AlbumEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="AlbumEntity"/> instances.</returns>
|
||||
public List<AlbumEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ArtistContributorEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistContributorEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ArtistContributorEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the participation.</param>
|
||||
/// <param name="artistId">Optional. The Id of the artist the contributor participated in.</param>
|
||||
/// <param name="mediaContributorId">Optional. The Id of the media contributor.</param>
|
||||
/// <param name="role">Optional. The role the contributor played in the artist.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the participation.</param>
|
||||
/// <returns>The created <see cref="ArtistContributorEntity"/>.</returns>
|
||||
public ArtistContributorEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? artistId = null,
|
||||
Guid? mediaContributorId = null,
|
||||
MediaContributorRole? role = null,
|
||||
Guid? createdBy = null)
|
||||
{
|
||||
return new ArtistContributorEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
ArtistId = artistId ?? Guid.NewGuid(),
|
||||
MediaContributorId = mediaContributorId ?? Guid.NewGuid(),
|
||||
Role = role ?? _faker.PickRandom<MediaContributorRole>(),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = createdBy ?? Guid.NewGuid(),
|
||||
UpdatedOnUtc = _faker.Random.Bool() ? _faker.Date.Recent() : null,
|
||||
UpdatedBy = _faker.Random.Bool() ? Guid.NewGuid() : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ArtistContributorEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <param name="artistId">Optional. The Id of the artist the contributors participated in.</param>
|
||||
/// <returns>List of configured <see cref="ArtistContributorEntity"/> instances.</returns>
|
||||
public List<ArtistContributorEntity> CreateMany(int count = 3, Guid? artistId = null)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create(artistId: artistId))];
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ArtistEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistEntityFixture
|
||||
{
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly ArtistContributorEntityFixture _artistContributorEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ArtistEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the artist.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that owns the artist.</param>
|
||||
/// <param name="name">Optional. The name of the artist.</param>
|
||||
/// <param name="albums">Optional. The albums of the artist.</param>
|
||||
/// <param name="includeAlbums">Whether the artist should own a generated album, or no album at all.</param>
|
||||
/// <param name="includeContributors">Whether the artist should own a generated media contributor, or none at all.</param>
|
||||
/// <param name="includeMetadata">Whether the owned metadata collections of the generated album should be included, or forced to empty collections.</param>
|
||||
/// <returns>The created <see cref="ArtistEntity"/>.</returns>
|
||||
public ArtistEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
string? name = null,
|
||||
List<AlbumEntity>? albums = null,
|
||||
bool includeAlbums = true,
|
||||
bool includeContributors = true,
|
||||
bool includeMetadata = true)
|
||||
{
|
||||
Guid resolvedId = id ?? Guid.NewGuid();
|
||||
Guid resolvedLibraryId = libraryId ?? Guid.NewGuid();
|
||||
List<AlbumEntity> resolvedAlbums = albums ?? (includeAlbums ? [_albumEntityFixture.Create(artistId: resolvedId, libraryId: resolvedLibraryId, includeMetadata: includeMetadata)] : []);
|
||||
|
||||
return new Faker<ArtistEntity>()
|
||||
.CustomInstantiator(f => new ArtistEntity
|
||||
{
|
||||
Id = resolvedId,
|
||||
LibraryId = resolvedLibraryId,
|
||||
Name = default!,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.RuleFor(x => x.Name, f => name ?? f.Name.FullName())
|
||||
.RuleFor(x => x.Website, f => f.Internet.Url())
|
||||
.RuleFor(x => x.MusicBrainzArtistId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Albums, resolvedAlbums)
|
||||
.RuleFor(x => x.Contributors, f => includeContributors ? _artistContributorEntityFixture.CreateMany(f.Random.Number(1, 3), artistId: resolvedId) : [])
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ArtistEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ArtistEntity"/> instances.</returns>
|
||||
public List<ArtistEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AudioRatingEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AudioRatingEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AudioRatingEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The rating value of the audio media element.</param>
|
||||
/// <param name="maxValue">Optional. The maximum possible rating value of the audio media element.</param>
|
||||
/// <param name="source">Optional. The source of the audio rating.</param>
|
||||
/// <param name="voteCount">Optional. The number of votes that contributed to the audio rating.</param>
|
||||
/// <param name="includeValue">Whether the value should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeMaxValue">Whether the maximum value should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSource">Whether the source should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeVoteCount">Whether the vote count should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AudioRatingEntity"/>.</returns>
|
||||
public AudioRatingEntity Create(
|
||||
decimal? value = null,
|
||||
decimal? maxValue = null,
|
||||
AudioRatingSource? source = null,
|
||||
int? voteCount = null,
|
||||
bool includeValue = true,
|
||||
bool includeMaxValue = true,
|
||||
bool includeSource = true,
|
||||
bool includeVoteCount = true)
|
||||
{
|
||||
return new AudioRatingEntity(
|
||||
includeValue ? (value ?? _faker.Random.Decimal(1, 5)) : null,
|
||||
includeMaxValue ? (maxValue ?? 5) : null,
|
||||
includeSource ? (source ?? _faker.PickRandom<AudioRatingSource>()) : null,
|
||||
includeVoteCount ? (voteCount ?? _faker.Random.Number(1, 1000)) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AudioRatingEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<AudioRatingEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TrackContributorEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TrackContributorEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TrackContributorEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the participation.</param>
|
||||
/// <param name="trackId">Optional. The Id of the track the contributor participated in.</param>
|
||||
/// <param name="mediaContributorId">Optional. The Id of the media contributor.</param>
|
||||
/// <param name="role">Optional. The role the contributor played in the track.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the participation.</param>
|
||||
/// <returns>The created <see cref="TrackContributorEntity"/>.</returns>
|
||||
public TrackContributorEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? trackId = null,
|
||||
Guid? mediaContributorId = null,
|
||||
MediaContributorRole? role = null,
|
||||
Guid? createdBy = null)
|
||||
{
|
||||
return new TrackContributorEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
TrackId = trackId ?? Guid.NewGuid(),
|
||||
MediaContributorId = mediaContributorId ?? Guid.NewGuid(),
|
||||
Role = role ?? _faker.PickRandom<MediaContributorRole>(),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = createdBy ?? Guid.NewGuid(),
|
||||
UpdatedOnUtc = _faker.Random.Bool() ? _faker.Date.Recent() : null,
|
||||
UpdatedBy = _faker.Random.Bool() ? Guid.NewGuid() : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TrackContributorEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <param name="trackId">Optional. The Id of the track the contributors participated in.</param>
|
||||
/// <returns>List of configured <see cref="TrackContributorEntity"/> instances.</returns>
|
||||
public List<TrackContributorEntity> CreateMany(int count = 3, Guid? trackId = null)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create(trackId: trackId))];
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Fixtures.Common.Setup;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TrackEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TrackEntityFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker = new();
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly TrackMoodEntityFixture _trackMoodEntityFixture = new();
|
||||
private readonly TrackIsrcEntityFixture _trackIsrcEntityFixture = new();
|
||||
private readonly TrackContributorEntityFixture _trackContributorEntityFixture = new();
|
||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TrackEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the track.</param>
|
||||
/// <param name="albumId">Optional. The Id of the album that owns the track.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that owns the track.</param>
|
||||
/// <param name="path">Optional. The file system path of the track.</param>
|
||||
/// <param name="title">Optional. The title of the track.</param>
|
||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||
/// <param name="includeMetadata">Whether the owned metadata collections (Tags, Genres, Moods, ISRCs, Contributors, Ratings) should be included, or forced to empty collections.</param>
|
||||
/// <param name="originalReleaseDate">Optional. The original release date of the track.</param>
|
||||
/// <param name="originalReleaseYear">Optional. The original release year of the track.</param>
|
||||
/// <param name="reReleaseDate">Optional. The re-release date of the track.</param>
|
||||
/// <param name="reReleaseYear">Optional. The re-release year of the track.</param>
|
||||
/// <param name="includeOriginalReleaseDate">Whether the original release date should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeOriginalReleaseYear">Whether the original release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReReleaseDate">Whether the re-release date should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReReleaseYear">Whether the re-release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="TrackEntity"/>.</returns>
|
||||
public TrackEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? albumId = null,
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
string? title = null,
|
||||
int? trackNumber = null,
|
||||
bool includeMetadata = true,
|
||||
DateOnly? originalReleaseDate = null,
|
||||
int? originalReleaseYear = null,
|
||||
DateOnly? reReleaseDate = null,
|
||||
int? reReleaseYear = null,
|
||||
bool includeOriginalReleaseDate = true,
|
||||
bool includeOriginalReleaseYear = true,
|
||||
bool includeReReleaseDate = true,
|
||||
bool includeReReleaseYear = true)
|
||||
{
|
||||
Guid resolvedId = id ?? Guid.NewGuid();
|
||||
Guid resolvedAlbumId = albumId ?? Guid.NewGuid();
|
||||
Guid resolvedLibraryId = libraryId ?? Guid.NewGuid();
|
||||
const int MAXIMUM_RELEASE_YEAR = 2026;
|
||||
int resolvedOriginalReleaseYear = originalReleaseYear ?? _random.Next(1900, MAXIMUM_RELEASE_YEAR);
|
||||
int resolvedReReleaseYearUpperBound = Math.Max(resolvedOriginalReleaseYear + 1, MAXIMUM_RELEASE_YEAR);
|
||||
int resolvedReReleaseYear = reReleaseYear ?? _random.Next(resolvedOriginalReleaseYear, resolvedReReleaseYearUpperBound);
|
||||
DateOnly resolvedOriginalReleaseDate = originalReleaseDate ?? _faker.DateOnlyBetween(new DateOnly(resolvedOriginalReleaseYear, 1, 1), new DateOnly(resolvedOriginalReleaseYear, 12, 31));
|
||||
DateOnly resolvedReReleaseDate = reReleaseDate ?? _faker.DateOnlyBetween(resolvedReReleaseYear == resolvedOriginalReleaseYear ? resolvedOriginalReleaseDate : new DateOnly(resolvedReReleaseYear, 1, 1), new DateOnly(resolvedReReleaseYear, 12, 31));
|
||||
|
||||
return new Faker<TrackEntity>()
|
||||
.CustomInstantiator(f => new TrackEntity
|
||||
{
|
||||
Id = resolvedId,
|
||||
AlbumId = resolvedAlbumId,
|
||||
LibraryId = resolvedLibraryId,
|
||||
Path = default!,
|
||||
Title = default!,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
|
||||
.RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.OriginalReleaseDate, includeOriginalReleaseDate ? resolvedOriginalReleaseDate : null)
|
||||
.RuleFor(x => x.OriginalReleaseYear, includeOriginalReleaseYear ? resolvedOriginalReleaseYear : null)
|
||||
.RuleFor(x => x.ReReleaseDate, includeReReleaseDate ? resolvedReReleaseDate : null)
|
||||
.RuleFor(x => x.ReReleaseYear, includeReReleaseYear ? resolvedReReleaseYear : null)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.PickRandom<ReleaseCountry>())
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.DurationInSeconds, _random.Next(60, 7200))
|
||||
.RuleFor(x => x.SampleRate, f => f.PickRandom(44100, 48000, 96000))
|
||||
.RuleFor(x => x.Channels, f => f.PickRandom(1, 2, 6))
|
||||
.RuleFor(x => x.BitDepth, _random.Next(8, 32))
|
||||
.RuleFor(x => x.AudioCodec, f => f.PickRandom("FLAC", "MP3", "AAC", "ALAC"))
|
||||
.RuleFor(x => x.Bitrate, _random.Next(96, 1411))
|
||||
.RuleFor(x => x.TrackNumber, f => trackNumber ?? f.Random.Int(1, 20))
|
||||
.RuleFor(x => x.DiscNumber, _random.Next(1, 3))
|
||||
.RuleFor(x => x.Script, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.Key, f => f.PickRandom<MusicKey>())
|
||||
.RuleFor(x => x.Bpm, _random.Next(40, 240))
|
||||
.RuleFor(x => x.Work, f => f.Music.Genre())
|
||||
.RuleFor(x => x.MusicBrainzRecordingId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.MusicBrainzTrackId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.MusicBrainzWorkId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Tags, f => includeMetadata ? [.. _tagEntityFixture.CreateMany(f.Random.Number(1, 3))] : [])
|
||||
.RuleFor(x => x.Genres, f => includeMetadata ? [.. _genreEntityFixture.CreateMany(f.Random.Number(1, 3))] : [])
|
||||
.RuleFor(x => x.Moods, f => includeMetadata ? _trackMoodEntityFixture.CreateMany(f.Random.Number(1, 3)) : [])
|
||||
.RuleFor(x => x.Isrcs, f => includeMetadata ? _trackIsrcEntityFixture.CreateMany(f.Random.Number(1, 3)) : [])
|
||||
.RuleFor(x => x.Contributors, f => includeMetadata ? _trackContributorEntityFixture.CreateMany(f.Random.Number(1, 3), trackId: resolvedId) : [])
|
||||
.RuleFor(x => x.Ratings, f => includeMetadata ? _audioRatingEntityFixture.CreateMany(f.Random.Number(1, 3)) : [])
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TrackEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="TrackEntity"/> instances.</returns>
|
||||
public List<TrackEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TrackIsrcEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TrackIsrcEntityFixture
|
||||
{
|
||||
private const string LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private const string ALPHANUMERICS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private const string DIGITS = "0123456789";
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TrackIsrcEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The value of the ISRC.</param>
|
||||
/// <returns>The created <see cref="TrackIsrcEntity"/>.</returns>
|
||||
public TrackIsrcEntity Create(string? value = null)
|
||||
{
|
||||
// ISRC codes follow the domain format: two letters, three alphanumeric characters and seven digits.
|
||||
return new TrackIsrcEntity(value ?? (
|
||||
_faker.Random.String2(2, LETTERS)
|
||||
+ _faker.Random.String2(3, ALPHANUMERICS)
|
||||
+ _faker.Random.String2(7, DIGITS)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TrackIsrcEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<TrackIsrcEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TrackMoodEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TrackMoodEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TrackMoodEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the mood.</param>
|
||||
/// <returns>The created <see cref="TrackMoodEntity"/>.</returns>
|
||||
public TrackMoodEntity Create(
|
||||
string? name = null)
|
||||
{
|
||||
return new TrackMoodEntity(name ?? _faker.Lorem.Word());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TrackMoodEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<TrackMoodEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user