Adds the music library persistence model, its repositories, and the scanning migration

This commit is contained in:
BinaryAlley committed 2026-10-08 20:48:00 +03:00
1 parent 4f0526faa4
commit 00376c8313
63 files changed
+8679 -203

No files matched your search

@@ -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="AlbumCatalogNumberEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AlbumCatalogNumberEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="AlbumCatalogNumberEntity"/>.
/// </summary>
/// <param name="catalogNumber">Optional. The catalog number assigned by the label.</param>
/// <returns>The created <see cref="AlbumCatalogNumberEntity"/>.</returns>
public AlbumCatalogNumberEntity Create(
string? catalogNumber = null)
{
return new AlbumCatalogNumberEntity(catalogNumber ?? _faker.Random.String2(_faker.Random.Number(1, 50)));
}
/// <summary>
/// Creates a list of <see cref="AlbumCatalogNumberEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<AlbumCatalogNumberEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,6 +6,7 @@ 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 Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -24,6 +25,8 @@ public class AlbumEntityFixture
private readonly TrackEntityFixture _trackEntityFixture = new();
private readonly TagEntityFixture _tagEntityFixture = new();
private readonly GenreEntityFixture _genreEntityFixture = new();
private readonly AlbumReleaseTypeEntityFixture _albumReleaseTypeEntityFixture = new();
private readonly AlbumCatalogNumberEntityFixture _albumCatalogNumberEntityFixture = new();
private readonly AlbumContributorEntityFixture _albumContributorEntityFixture = new();
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
@@ -71,10 +74,11 @@ public class AlbumEntityFixture
/// <param name="includeReleaseStatus">Whether the release status should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTotalDiscs">Whether the total number of discs should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMediaFormat">Whether the media format should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeCatalogNumber">Whether the catalog number should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeCatalogNumbers">Whether the catalog number should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMusicBrainzReleaseId">Whether the MusicBrainz release identifier should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMusicBrainzReleaseGroupId">Whether the MusicBrainz release group identifier should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeMusicBrainzReleaseArtistId">Whether the MusicBrainz release artist identifier should be included, or forced to <see langword="null"/>.</param>
/// <param name="metadataStatus">Optional. The metadata enrichment status of the album.</param>
/// <returns>The created <see cref="AlbumEntity"/>.</returns>
public AlbumEntity Create(
Guid? id = null,
@@ -99,7 +103,7 @@ public class AlbumEntityFixture
MusicReleaseStatus? releaseStatus = null,
int? totalDiscs = null,
MusicMediaFormat? mediaFormat = null,
string? catalogNumber = null,
List<string>? catalogNumbers = null,
Guid? musicBrainzReleaseId = null,
Guid? musicBrainzReleaseGroupId = null,
Guid? musicBrainzReleaseArtistId = null,
@@ -118,10 +122,11 @@ public class AlbumEntityFixture
bool includeReleaseStatus = true,
bool includeTotalDiscs = true,
bool includeMediaFormat = true,
bool includeCatalogNumber = true,
bool includeCatalogNumbers = true,
bool includeMusicBrainzReleaseId = true,
bool includeMusicBrainzReleaseGroupId = true,
bool includeMusicBrainzReleaseArtistId = true)
bool includeMusicBrainzReleaseArtistId = true,
MetadataStatus? metadataStatus = null)
{
Guid resolvedId = id ?? Guid.NewGuid();
Guid resolvedArtistId = artistId ?? Guid.NewGuid();
@@ -140,6 +145,7 @@ public class AlbumEntityFixture
Id = resolvedId,
ArtistId = resolvedArtistId,
LibraryId = resolvedLibraryId,
MetadataStatus = metadataStatus ?? MetadataStatus.Pending,
Title = default!,
CreatedOnUtc = default,
CreatedBy = default,
@@ -147,6 +153,7 @@ public class AlbumEntityFixture
})
.RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.OriginalTitle, f => includeOriginalTitle ? (originalTitle ?? f.Random.String2(f.Random.Number(1, 255))) : null)
.RuleFor(x => x.ReleaseTitle, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.Description, f => includeDescription ? (description ?? f.Random.String2(f.Random.Number(1, 2000))) : null)
.RuleFor(x => x.OriginalReleaseDate, includeOriginalReleaseDate ? resolvedOriginalReleaseDate : (DateOnly?)null)
.RuleFor(x => x.OriginalReleaseYear, includeOriginalReleaseYear ? resolvedOriginalReleaseYear : (int?)null)
@@ -160,13 +167,13 @@ public class AlbumEntityFixture
.RuleFor(x => x.OriginalLanguageCode, f => includeOriginalLanguage ? (originalLanguageCode ?? f.Random.String2(2)) : null)
.RuleFor(x => x.OriginalLanguageName, f => includeOriginalLanguage ? (originalLanguageName ?? f.Random.String2(f.Random.Number(1, 50))) : null)
.RuleFor(x => x.OriginalLanguageNativeName, f => includeOriginalLanguage ? (originalLanguageNativeName ?? f.Random.String2(f.Random.Number(1, 50))) : null)
.RuleFor(x => x.ReleaseType, f => includeReleaseType ? (releaseType ?? f.PickRandom<MusicReleaseType>()) : (MusicReleaseType?)null)
.RuleFor(x => x.ReleaseTypes, f => includeReleaseType ? [_albumReleaseTypeEntityFixture.Create(releaseType: releaseType)] : [])
.RuleFor(x => x.ReleaseStatus, f => includeReleaseStatus ? (releaseStatus ?? f.PickRandom<MusicReleaseStatus>()) : (MusicReleaseStatus?)null)
.RuleFor(x => x.TotalDiscs, includeTotalDiscs ? (totalDiscs ?? Random.Shared.Next(1, 3)) : (int?)null)
.RuleFor(x => x.TotalTracks, resolvedTracks.Count)
.RuleFor(x => x.MediaFormat, f => includeMediaFormat ? (mediaFormat ?? f.PickRandom<MusicMediaFormat>()) : (MusicMediaFormat?)null)
.RuleFor(x => x.Barcode, f => includeBarcode ? (barcode ?? f.Random.String2(f.Random.Number(12, 13), "0123456789")) : null)
.RuleFor(x => x.CatalogNumber, f => includeCatalogNumber ? (catalogNumber ?? f.Random.String2(f.Random.Number(1, 50))) : null)
.RuleFor(x => x.CatalogNumbers, f => includeCatalogNumbers ? [.. (catalogNumbers ?? [f.Random.String2(f.Random.Number(1, 50))]).Select(catalogNumber => _albumCatalogNumberEntityFixture.Create(catalogNumber: catalogNumber))] : [])
.RuleFor(x => x.MusicBrainzReleaseId, f => includeMusicBrainzReleaseId ? (musicBrainzReleaseId ?? f.Random.Guid()) : (Guid?)null)
.RuleFor(x => x.MusicBrainzReleaseGroupId, f => includeMusicBrainzReleaseGroupId ? (musicBrainzReleaseGroupId ?? f.Random.Guid()) : (Guid?)null)
.RuleFor(x => x.MusicBrainzReleaseArtistId, f => includeMusicBrainzReleaseArtistId ? (musicBrainzReleaseArtistId ?? f.Random.Guid()) : (Guid?)null)
@@ -0,0 +1,40 @@
#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="AlbumReleaseTypeEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AlbumReleaseTypeEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="AlbumReleaseTypeEntity"/>.
/// </summary>
/// <param name="releaseType">Optional. The type of the release.</param>
/// <returns>The created <see cref="AlbumReleaseTypeEntity"/>.</returns>
public AlbumReleaseTypeEntity Create(
MusicReleaseType? releaseType = null)
{
return new AlbumReleaseTypeEntity(releaseType ?? _faker.PickRandom<MusicReleaseType>());
}
/// <summary>
/// Creates a list of <see cref="AlbumReleaseTypeEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<AlbumReleaseTypeEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,78 @@
#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="ArtistAliasEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ArtistAliasEntityFixture
{
private const int MINIMUM_ALIAS_YEAR = 1900;
private const int MAXIMUM_ALIAS_YEAR = 2026;
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ArtistAliasEntity"/>.
/// </summary>
/// <param name="name">Optional. The name of the alias.</param>
/// <param name="sortName">Optional. The sort name of the alias.</param>
/// <param name="type">Optional. The type of the alias.</param>
/// <param name="locale">Optional. The locale the alias is used in.</param>
/// <param name="isPrimary">Optional. Whether this is the primary alias of the artist.</param>
/// <param name="beginDate">Optional. The date the alias began being used.</param>
/// <param name="endDate">Optional. The date the alias stopped being used.</param>
/// <param name="isEnded">Optional. Whether the alias is no longer used.</param>
/// <param name="includeSortName">Whether the sort name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeType">Whether the type should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeLocale">Whether the locale should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeBeginDate">Whether the begin date should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeEndDate">Whether the end date should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="ArtistAliasEntity"/>.</returns>
public ArtistAliasEntity Create(
string? name = null,
string? sortName = null,
string? type = null,
string? locale = null,
bool? isPrimary = null,
DateOnly? beginDate = null,
DateOnly? endDate = null,
bool? isEnded = null,
bool includeSortName = true,
bool includeType = true,
bool includeLocale = true,
bool includeBeginDate = true,
bool includeEndDate = true)
{
int beginYear = Random.Shared.Next(MINIMUM_ALIAS_YEAR, MAXIMUM_ALIAS_YEAR);
int endYear = Random.Shared.Next(beginYear, Math.Max(beginYear + 1, MAXIMUM_ALIAS_YEAR));
return new ArtistAliasEntity(
name ?? _faker.Name.FullName(),
includeSortName ? (sortName ?? _faker.Name.FullName()) : null,
includeType ? (type ?? _faker.Random.ArrayElement(["Artist name", "Search hint"])) : null,
includeLocale ? (locale ?? _faker.Random.String2(2)) : null,
isPrimary ?? _faker.Random.Bool(),
includeBeginDate ? (beginDate ?? new DateOnly(beginYear, 1, 1)) : null,
includeEndDate ? (endDate ?? new DateOnly(endYear, 1, 1)) : null,
isEnded ?? _faker.Random.Bool());
}
/// <summary>
/// Creates a list of <see cref="ArtistAliasEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ArtistAliasEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -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="ArtistIpiEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ArtistIpiEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ArtistIpiEntity"/>.
/// </summary>
/// <param name="value">Optional. The value of the IPI code.</param>
/// <returns>The created <see cref="ArtistIpiEntity"/>.</returns>
public ArtistIpiEntity Create(
string? value = null)
{
return new ArtistIpiEntity(value ?? _faker.Random.String2(_faker.Random.Number(1, 20), "0123456789"));
}
/// <summary>
/// Creates a list of <see cref="ArtistIpiEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ArtistIpiEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -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="ArtistIsniEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ArtistIsniEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ArtistIsniEntity"/>.
/// </summary>
/// <param name="value">Optional. The value of the ISNI code.</param>
/// <returns>The created <see cref="ArtistIsniEntity"/>.</returns>
public ArtistIsniEntity Create(
string? value = null)
{
return new ArtistIsniEntity(value ?? _faker.Random.String2(_faker.Random.Number(1, 20), "0123456789X"));
}
/// <summary>
/// Creates a list of <see cref="ArtistIsniEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ArtistIsniEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,64 @@
#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="MusicAreaEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicAreaEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MusicAreaEntity"/>.
/// </summary>
/// <param name="musicBrainzAreaId">Optional. The MusicBrainz identifier of the area.</param>
/// <param name="name">Optional. The name of the area.</param>
/// <param name="sortName">Optional. The sort name of the area.</param>
/// <param name="disambiguation">Optional. The disambiguation comment of the area.</param>
/// <param name="type">Optional. The MusicBrainz type of the area.</param>
/// <param name="iso3166Code">Optional. The ISO 3166 code of the area.</param>
/// <param name="includeSortName">Whether the sort name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeDisambiguation">Whether the disambiguation should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeType">Whether the type should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeIso3166Code">Whether the ISO 3166 code should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MusicAreaEntity"/>.</returns>
public MusicAreaEntity Create(
Guid? musicBrainzAreaId = null,
string? name = null,
string? sortName = null,
string? disambiguation = null,
string? type = null,
string? iso3166Code = null,
bool includeSortName = true,
bool includeDisambiguation = true,
bool includeType = true,
bool includeIso3166Code = true)
{
return new MusicAreaEntity(
musicBrainzAreaId ?? _faker.Random.Guid(),
name ?? _faker.Address.Country(),
includeSortName ? (sortName ?? _faker.Address.Country()) : null,
includeDisambiguation ? (disambiguation ?? _faker.Lorem.Sentence()) : null,
includeType ? (type ?? _faker.Random.ArrayElement(["Country", "City", "Area"])) : null,
includeIso3166Code ? (iso3166Code ?? _faker.Address.CountryCode()) : null);
}
/// <summary>
/// Creates a list of <see cref="MusicAreaEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MusicAreaEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,102 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.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.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
/// <summary>
/// Fixture class for the <see cref="MusicLibraryScanItemMetadataEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicLibraryScanItemMetadataEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MusicLibraryScanItemMetadataEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the staged metadata.</param>
/// <param name="libraryScanId">Optional. The Id of the media library scan the staged metadata belongs to.</param>
/// <param name="libraryId">Optional. The Id of the media library the staged metadata belongs to.</param>
/// <param name="path">Optional. The file system path of the music file.</param>
/// <param name="artistName">Optional. The name of the artist.</param>
/// <param name="releaseName">Optional. The name of the release.</param>
/// <param name="trackTitle">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="musicBrainzArtistId">Optional. The MusicBrainz identifier of the artist.</param>
/// <param name="musicBrainzReleaseArtistId">Optional. The MusicBrainz identifier of the release artist.</param>
/// <param name="musicBrainzReleaseGroupId">Optional. The MusicBrainz identifier of the release group.</param>
/// <param name="musicBrainzReleaseId">Optional. The MusicBrainz identifier of the release.</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="workTitle">Optional. The title of the work.</param>
/// <param name="includeMusicBrainzTags">Whether the MusicBrainz identifiers and the work title should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="MusicLibraryScanItemMetadataEntity"/>.</returns>
public MusicLibraryScanItemMetadataEntity Create(
Guid? id = null,
Guid? libraryScanId = null,
Guid? libraryId = null,
string? path = null,
string? artistName = null,
string? releaseName = null,
string? trackTitle = null,
int? trackNumber = null,
int? discNumber = null,
Guid? musicBrainzArtistId = null,
Guid? musicBrainzReleaseArtistId = null,
Guid? musicBrainzReleaseGroupId = null,
Guid? musicBrainzReleaseId = null,
Guid? musicBrainzRecordingId = null,
Guid? musicBrainzTrackId = null,
Guid? musicBrainzWorkId = null,
string? workTitle = null,
bool includeMusicBrainzTags = true)
{
return new MusicLibraryScanItemMetadataEntity
{
Id = id ?? Guid.NewGuid(),
LibraryScanId = libraryScanId ?? Guid.NewGuid(),
LibraryId = libraryId ?? Guid.NewGuid(),
Path = path ?? _faker.System.FilePath(),
ArtistName = artistName ?? _faker.Name.FullName(),
ReleaseType = _faker.PickRandom<MusicReleaseType>(),
ReleaseYear = Random.Shared.Next(1900, 2026),
ReleaseName = releaseName ?? _faker.Music.Genre(),
TrackTitle = trackTitle ?? _faker.Music.Genre(),
TrackNumber = trackNumber ?? _faker.Random.Int(1, 20),
DiscNumber = discNumber ?? _faker.Random.Int(1, 3),
DurationInSeconds = Random.Shared.Next(60, 7200),
SampleRate = _faker.PickRandom(44100, 48000, 96000),
Channels = _faker.PickRandom(1, 2, 6),
BitDepth = Random.Shared.Next(8, 32),
AudioCodec = _faker.PickRandom("FLAC", "MP3", "AAC", "ALAC"),
Bitrate = Random.Shared.Next(96, 1411),
MusicBrainzArtistId = includeMusicBrainzTags ? musicBrainzArtistId ?? Guid.NewGuid() : null,
MusicBrainzReleaseArtistId = includeMusicBrainzTags ? musicBrainzReleaseArtistId ?? Guid.NewGuid() : null,
MusicBrainzReleaseGroupId = includeMusicBrainzTags ? musicBrainzReleaseGroupId ?? Guid.NewGuid() : null,
MusicBrainzReleaseId = includeMusicBrainzTags ? musicBrainzReleaseId ?? Guid.NewGuid() : null,
MusicBrainzRecordingId = includeMusicBrainzTags ? musicBrainzRecordingId ?? Guid.NewGuid() : null,
MusicBrainzTrackId = includeMusicBrainzTags ? musicBrainzTrackId ?? Guid.NewGuid() : null,
MusicBrainzWorkId = includeMusicBrainzTags ? musicBrainzWorkId ?? Guid.NewGuid() : null,
WorkTitle = includeMusicBrainzTags ? workTitle ?? _faker.Music.Genre() : null
};
}
/// <summary>
/// Creates a list of <see cref="MusicLibraryScanItemMetadataEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MusicLibraryScanItemMetadataEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,6 +6,7 @@ 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 Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -46,6 +47,7 @@ public class TrackEntityFixture
/// <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="metadataStatus">Optional. The metadata enrichment status of the track.</param>
/// <returns>The created <see cref="TrackEntity"/>.</returns>
public TrackEntity Create(
Guid? id = null,
@@ -62,7 +64,8 @@ public class TrackEntityFixture
bool includeOriginalReleaseDate = true,
bool includeOriginalReleaseYear = true,
bool includeReReleaseDate = true,
bool includeReReleaseYear = true)
bool includeReReleaseYear = true,
MetadataStatus? metadataStatus = null)
{
Guid resolvedId = id ?? Guid.NewGuid();
Guid resolvedAlbumId = albumId ?? Guid.NewGuid();
@@ -80,6 +83,7 @@ public class TrackEntityFixture
Id = resolvedId,
AlbumId = resolvedAlbumId,
LibraryId = resolvedLibraryId,
MetadataStatus = metadataStatus ?? MetadataStatus.Pending,
Path = default!,
Title = default!,
CreatedOnUtc = default,
@@ -113,7 +117,9 @@ public class TrackEntityFixture
.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.Shared.Next(40, 240))
.RuleFor(x => x.Work, f => f.Music.Genre())
.RuleFor(x => x.IsVideo, f => f.Random.Bool())
.RuleFor(x => x.WorkTitle, f => f.Music.Genre())
.RuleFor(x => x.WorkType, 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())
@@ -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="TrackWorkIswcEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class TrackWorkIswcEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="TrackWorkIswcEntity"/>.
/// </summary>
/// <param name="value">Optional. The value of the ISWC.</param>
/// <returns>The created <see cref="TrackWorkIswcEntity"/>.</returns>
public TrackWorkIswcEntity Create(
string? value = null)
{
return new TrackWorkIswcEntity(value ?? $"T{_faker.Random.AlphaNumeric(10)}");
}
/// <summary>
/// Creates a list of <see cref="TrackWorkIswcEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<TrackWorkIswcEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#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="TrackWorkLanguageEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class TrackWorkLanguageEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="TrackWorkLanguageEntity"/>.
/// </summary>
/// <param name="languageCode">Optional. The ISO 639-1 two-letter language code.</param>
/// <param name="languageName">Optional. The full name of the language in English.</param>
/// <param name="nativeName">Optional. The native name of the language.</param>
/// <param name="includeNativeName">Whether the native name should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="TrackWorkLanguageEntity"/>.</returns>
public TrackWorkLanguageEntity Create(
string? languageCode = null,
string? languageName = null,
string? nativeName = null,
bool includeNativeName = true)
{
return new TrackWorkLanguageEntity(
languageCode ?? _faker.PickRandom("en", "fr", "de", "es", "it", "ja", "ko", "zh", "pt", "ru"),
languageName ?? _faker.Lorem.Word(),
includeNativeName ? (nativeName ?? _faker.Lorem.Word()) : null);
}
/// <summary>
/// Creates a list of <see cref="TrackWorkLanguageEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<TrackWorkLanguageEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,8 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Fixtures.Common.Setup;using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
using Lumina.Application.Fixtures.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using System;
using System.Collections.Generic;
@@ -19,6 +20,10 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Wr
public class BookEntityFixture
{
private readonly Faker _faker = new();
private readonly TagEntityFixture _tagEntityFixture = new();
private readonly GenreEntityFixture _genreEntityFixture = new();
private readonly IsbnEntityFixture _isbnEntityFixture = new();
private readonly BookRatingEntityFixture _bookRatingEntityFixture = new();
/// <summary>
/// Creates a random valid <see cref="BookEntity"/>.
@@ -60,8 +65,8 @@ public class BookEntityFixture
.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.Tags, f => includeMetadata ? [.. CreateTags(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Genres, f => includeMetadata ? [.. CreateGenres(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Tags, f => includeMetadata ? [.. _tagEntityFixture.CreateMany(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Genres, f => includeMetadata ? [.. _genreEntityFixture.CreateMany(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
.RuleFor(x => x.PageCount, Random.Shared.Next(100, 300))
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
@@ -76,8 +81,8 @@ public class BookEntityFixture
.RuleFor(x => x.GoogleBooksId, CreateGoogleBooksId)
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(x => x.ISBNs, f => includeMetadata ? CreateIsbns(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.Ratings, f => includeMetadata ? CreateBookRatings(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.ISBNs, f => includeMetadata ? _isbnEntityFixture.CreateMany(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.Ratings, f => includeMetadata ? _bookRatingEntityFixture.CreateMany(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
.Generate();
@@ -93,30 +98,6 @@ public class BookEntityFixture
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates a list of tag entities with random data.
/// </summary>
/// <param name="count">The number of tags to create.</param>
/// <returns>A list of randomly generated tag entities.</returns>
private static List<TagEntity> CreateTags(int count)
{
return new Faker<TagEntity>()
.CustomInstantiator(f => new TagEntity(f.Random.String2(f.Random.Number(1, 50))))
.Generate(count);
}
/// <summary>
/// Creates a list of genre entities with random data.
/// </summary>
/// <param name="count">The number of genres to create.</param>
/// <returns>A list of randomly generated genre entities.</returns>
private static List<GenreEntity> CreateGenres(int count)
{
return new Faker<GenreEntity>()
.CustomInstantiator(f => new GenreEntity(f.Random.String2(f.Random.Number(1, 50))))
.Generate(count);
}
/// <summary>
/// Creates a valid Library of Congress Control Number (LCCN).
/// </summary>
@@ -172,73 +153,4 @@ public class BookEntityFixture
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
}
/// <summary>
/// Creates a list of ISBN entities with random data.
/// </summary>
/// <param name="count">The number of ISBNs to create.</param>
/// <returns>A list of randomly generated ISBN entities.</returns>
private static List<IsbnEntity> CreateIsbns(int count)
{
return new Faker<IsbnEntity>()
.CustomInstantiator(f =>
{
string isbnValue = CreateIsbn(f);
return new IsbnEntity(isbnValue, isbnValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
})
.Generate(count);
}
/// <summary>
/// Creates a valid ISBN (International Standard Book Number).
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <returns>A properly formatted ISBN-10 or ISBN-13 string with valid checksum.</returns>
private static string CreateIsbn(Faker f)
{
bool isIsbn13 = f.Random.Bool();
if (isIsbn13)
{
string prefix = f.Random.Bool() ? "978" : "979";
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
int sum = 0;
for (int i = 0; i < 12; i++)
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
int checkDigit = (10 - (sum % 10)) % 10;
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
}
else
{
int[] digits = new int[9];
for (int i = 0; i < 9; i++)
digits[i] = f.Random.Number(0, 9);
int sum = 0;
for (int i = 0; i < 9; i++)
sum += (10 - i) * digits[i];
int checkDigit = (11 - (sum % 11)) % 11;
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
}
}
/// <summary>
/// Creates a list of book rating entities with random data.
/// </summary>
/// <param name="count">The number of ratings to create.</param>
/// <returns>A list of randomly generated book rating entities.</returns>
private static List<BookRatingEntity> CreateBookRatings(int count)
{
return new Faker<BookRatingEntity>()
.CustomInstantiator(f => new BookRatingEntity(
f.Random.Decimal(1, 5),
5,
f.PickRandom<BookRatingSource>(),
f.Random.Number(1, 1000)
))
.Generate(count);
}
}
@@ -18,20 +18,22 @@ public class IsbnEntityFixture
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="IsbnEntity"/>.
/// Creates a random valid <see cref="IsbnEntity"/>, with a value that satisfies the ISBN checksum and a format that matches it.
/// </summary>
/// <param name="value">Optional. The ISBN value.</param>
/// <param name="format">Optional. The format of the ISBN.</param>
/// <param name="includeValue">Whether the value should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeFormat">Whether the format should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="IsbnEntity"/>.</returns>
public IsbnEntity Create(
string? value = null,
IsbnFormat? format = null,
bool includeValue = true)
string? value = null,
IsbnFormat? format = null,
bool includeValue = true,
bool includeFormat = true)
{
return new IsbnEntity(
includeValue ? value ?? _faker.Random.String2(13, "0123456789") : null,
format);
string? resolvedValue = includeValue ? value ?? CreateValidIsbn13() : null;
IsbnFormat? resolvedFormat = includeFormat ? format ?? InferFormat(resolvedValue) : null;
return new IsbnEntity(resolvedValue, resolvedFormat);
}
/// <summary>
@@ -43,4 +45,33 @@ public class IsbnEntityFixture
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Infers the format of an ISBN from the number of digits of its value.
/// </summary>
/// <param name="value">The ISBN value whose format is inferred.</param>
/// <returns>The inferred ISBN format.</returns>
private static IsbnFormat InferFormat(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return IsbnFormat.Isbn13;
int digitCount = value.Count(char.IsLetterOrDigit);
return digitCount is 10 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13;
}
/// <summary>
/// Generates a random ISBN-13 value with a valid check digit.
/// </summary>
/// <returns>A valid ISBN-13 value of 13 digits.</returns>
private string CreateValidIsbn13()
{
string prefix = _faker.Random.Bool() ? "978" : "979";
string firstTwelveDigits = prefix + _faker.Random.String2(9, "0123456789");
int sum = 0;
for (int index = 0; index < 12; index++)
sum += index % 2 == 0 ? firstTwelveDigits[index] - '0' : 3 * (firstTwelveDigits[index] - '0');
int checkDigit = (10 - (sum % 10)) % 10;
return firstTwelveDigits + checkDigit;
}
}