Adds the test suites for the library path templates and centralizes their resolution in the domain service

This commit is contained in:
BinaryAlley committed 2026-10-05 20:15:00 +03:00
1 parent ca4f308b0a
commit 7ed6f05632
52 files changed
+4724 -40

No files matched your search

@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplatePartDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartDtoFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplatePartDto"/>.
/// </summary>
/// <param name="kind">Optional. The kind of the path part.</param>
/// <param name="representation">Optional. The literal text or the value mask of the path part.</param>
/// <param name="isOptional">Whether the path part can be absent from the path.</param>
/// <returns>The created <see cref="LibraryPathTemplatePartDto"/>.</returns>
public LibraryPathTemplatePartDto Create(
string? kind = null,
string? representation = null,
bool isOptional = false)
{
return new LibraryPathTemplatePartDto(
kind ?? "Artist",
representation ?? "{0}",
isOptional);
}
/// <summary>
/// Creates a list of <see cref="LibraryPathTemplatePartDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathTemplatePartDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -17,6 +17,7 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Ma
public class LibraryEntityFixture
{
private readonly LibraryContentLocationEntityFixture _libraryContentLocationEntityFixture = new();
private readonly LibraryPathTemplatePartEntityFixture _libraryPathTemplatePartEntityFixture = new();
/// <summary>
/// Creates a random valid <see cref="LibraryEntity"/>.
@@ -34,6 +35,8 @@ public class LibraryEntityFixture
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
/// <param name="metadataProvidersConfigurationFingerprint">Optional. The fingerprint of the metadata provider configuration of the media library.</param>
/// <param name="artworkProvidersConfigurationFingerprint">Optional. The fingerprint of the artwork provider configuration of the media library.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <param name="pathTemplateFingerprint">Optional. The fingerprint of the path template of the media library.</param>
/// <returns>The created media library entity.</returns>
public LibraryEntity Create(
Guid? id = null,
@@ -48,7 +51,9 @@ public class LibraryEntityFixture
bool shouldSaveMetadataInMediaDirectories = true,
bool shouldSkipUnchangedDirectoriesDuringScan = false,
string? metadataProvidersConfigurationFingerprint = null,
string? artworkProvidersConfigurationFingerprint = null)
string? artworkProvidersConfigurationFingerprint = null,
IEnumerable<LibraryPathTemplatePartEntity>? pathTemplateParts = null,
string? pathTemplateFingerprint = null)
{
return new Faker<LibraryEntity>()
.CustomInstantiator(f => new LibraryEntity
@@ -59,6 +64,7 @@ public class LibraryEntityFixture
CoverImage = default,
LibraryType = default,
ContentLocations = [],
PathTemplateParts = [],
LibraryScans = [],
IsEnabled = isEnabled,
IsLocked = isLocked,
@@ -67,6 +73,7 @@ public class LibraryEntityFixture
ShouldSkipUnchangedDirectoriesDuringScan = shouldSkipUnchangedDirectoriesDuringScan,
MetadataProvidersConfigurationFingerprint = metadataProvidersConfigurationFingerprint,
ArtworkProvidersConfigurationFingerprint = artworkProvidersConfigurationFingerprint,
PathTemplateFingerprint = pathTemplateFingerprint,
CreatedOnUtc = default,
CreatedBy = default,
UpdatedOnUtc = null,
@@ -80,6 +87,7 @@ public class LibraryEntityFixture
IEnumerable<string> paths = contentLocations ?? [f.System.DirectoryPath(), f.System.DirectoryPath()];
return [.. paths.Select(path => _libraryContentLocationEntityFixture.Create(path: path))];
})
.RuleFor(library => library.PathTemplateParts, f => pathTemplateParts is null ? [] : [.. pathTemplateParts])
.RuleFor(library => library.CreatedOnUtc, f => f.Date.Past())
.RuleFor(library => library.CreatedBy, f => f.Random.Guid())
.Generate();
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplatePartEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplatePartEntity"/>.
/// </summary>
/// <param name="position">Optional. The zero based position of the part in the path template.</param>
/// <param name="kind">Optional. The kind of the path part.</param>
/// <param name="representation">Optional. The literal text or the value mask of the path part.</param>
/// <param name="isOptional">Whether the path part can be absent from the path.</param>
/// <returns>The created <see cref="LibraryPathTemplatePartEntity"/>.</returns>
public LibraryPathTemplatePartEntity Create(
int? position = null,
LibraryPathPartKind? kind = null,
string? representation = null,
bool isOptional = false)
{
return new Faker<LibraryPathTemplatePartEntity>()
.CustomInstantiator(f => new LibraryPathTemplatePartEntity
{
Position = position ?? 0,
Kind = default,
Representation = default!,
IsOptional = isOptional
})
.RuleFor(part => part.Kind, f => kind ?? f.PickRandom<LibraryPathPartKind>())
.RuleFor(part => part.Representation, f => representation ?? "{0}")
.Generate();
}
/// <summary>
/// Creates a list of <see cref="LibraryPathTemplatePartEntity"/> instances with sequential positions.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathTemplatePartEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(index => Create(position: index))];
}
}
@@ -0,0 +1,35 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts;
/// <summary>
/// Fixture class for the <see cref="GetLibraryPathTemplatePartsQuery"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryPathTemplatePartsQueryFixture
{
/// <summary>
/// Creates a random valid <see cref="GetLibraryPathTemplatePartsQuery"/>.
/// </summary>
/// <param name="libraryType">Optional. The media library type whose available path parts are retrieved.</param>
/// <returns>The created <see cref="GetLibraryPathTemplatePartsQuery"/>.</returns>
public GetLibraryPathTemplatePartsQuery Create(string? libraryType = null)
{
return new GetLibraryPathTemplatePartsQuery(libraryType ?? "Music");
}
/// <summary>
/// Creates a list of <see cref="GetLibraryPathTemplatePartsQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryPathTemplatePartsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}