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())];
}
}
@@ -0,0 +1,35 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="GetLibraryPathTemplatePartsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryPathTemplatePartsRequestFixture
{
/// <summary>
/// Creates a random valid <see cref="GetLibraryPathTemplatePartsRequest"/>.
/// </summary>
/// <param name="libraryType">Optional. The media library type whose available path parts are retrieved.</param>
/// <returns>The created <see cref="GetLibraryPathTemplatePartsRequest"/>.</returns>
public GetLibraryPathTemplatePartsRequest Create(string? libraryType = null)
{
return new GetLibraryPathTemplatePartsRequest(libraryType ?? "Music");
}
/// <summary>
/// Creates a list of <see cref="GetLibraryPathTemplatePartsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryPathTemplatePartsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplatePartRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartRequestFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplatePartRequest"/>.
/// </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="LibraryPathTemplatePartRequest"/>.</returns>
public LibraryPathTemplatePartRequest Create(
string? kind = null,
string? representation = null,
bool isOptional = false)
{
return new LibraryPathTemplatePartRequest(
kind ?? "Artist",
representation ?? "{0}",
isOptional);
}
/// <summary>
/// Creates a list of <see cref="LibraryPathTemplatePartRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathTemplatePartRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathPartDefinitionResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathPartDefinitionResponseFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryPathPartDefinitionResponse"/>.
/// </summary>
/// <param name="kind">Optional. The kind of the path part.</param>
/// <param name="valueType">Optional. The value type captured by the path part.</param>
/// <param name="defaultRepresentation">Optional. The default representation of the path part.</param>
/// <param name="isOptionalByDefault">Whether the path part is optional by default.</param>
/// <returns>The created <see cref="LibraryPathPartDefinitionResponse"/>.</returns>
public LibraryPathPartDefinitionResponse Create(
string? kind = null,
string? valueType = null,
string? defaultRepresentation = null,
bool isOptionalByDefault = false)
{
return new LibraryPathPartDefinitionResponse(
kind ?? "Artist",
valueType ?? "Text",
defaultRepresentation ?? "{0}",
isOptionalByDefault);
}
/// <summary>
/// Creates a list of <see cref="LibraryPathPartDefinitionResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathPartDefinitionResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,47 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplateCatalogResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplateCatalogResponseFixture
{
private readonly LibraryPathPartDefinitionResponseFixture _libraryPathPartDefinitionResponseFixture = new();
private readonly LibraryPathTemplatePartResponseFixture _libraryPathTemplatePartResponseFixture = new();
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplateCatalogResponse"/>.
/// </summary>
/// <param name="parts">Optional. The path parts that can be used in the path template of the library type.</param>
/// <param name="defaultTemplateParts">Optional. The ordered parts of the default path template of the library type.</param>
/// <param name="includeParts">Whether the catalog should carry selectable path parts. When <see langword="false"/>, no parts are created.</param>
/// <param name="includeDefaultTemplateParts">Whether the catalog should carry default template parts. When <see langword="false"/>, no default template parts are created.</param>
/// <returns>The created <see cref="LibraryPathTemplateCatalogResponse"/>.</returns>
public LibraryPathTemplateCatalogResponse Create(
List<LibraryPathPartDefinitionResponse>? parts = null,
List<LibraryPathTemplatePartResponse>? defaultTemplateParts = null,
bool includeParts = true,
bool includeDefaultTemplateParts = true)
{
return new LibraryPathTemplateCatalogResponse(
includeParts ? (parts ?? _libraryPathPartDefinitionResponseFixture.CreateMany(2)) : [],
includeDefaultTemplateParts ? (defaultTemplateParts ?? _libraryPathTemplatePartResponseFixture.CreateMany(2)) : []);
}
/// <summary>
/// Creates a list of <see cref="LibraryPathTemplateCatalogResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathTemplateCatalogResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplatePartResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartResponseFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplatePartResponse"/>.
/// </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="LibraryPathTemplatePartResponse"/>.</returns>
public LibraryPathTemplatePartResponse Create(
string? kind = null,
string? representation = null,
bool isOptional = false)
{
return new LibraryPathTemplatePartResponse(
kind ?? "Artist",
representation ?? "{0}",
isOptional);
}
/// <summary>
/// Creates a list of <see cref="LibraryPathTemplatePartResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryPathTemplatePartResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,85 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MusicLibraryPathMetadata"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicLibraryPathMetadataFixture
{
private readonly Faker _faker = new();
private readonly ParsedLibraryPathFixture _parsedLibraryPathFixture = new();
/// <summary>
/// Creates a random valid <see cref="MusicLibraryPathMetadata"/>.
/// </summary>
/// <param name="artistName">Optional. The name of the artist derived from the path.</param>
/// <param name="releaseType">Optional. The type of the release derived from the path.</param>
/// <param name="releaseYear">Optional. The release year derived from the path.</param>
/// <param name="releaseName">Optional. The name of the release derived from the path.</param>
/// <param name="trackNumber">Optional. The number of the track derived from the path.</param>
/// <param name="discNumber">Optional. The number of the disc the track belongs to, derived from the path.</param>
/// <param name="trackTitle">Optional. The title of the track derived from the path.</param>
/// <param name="includeArtistName">Whether the artist name should be captured. When <see langword="false"/>, the artist name is not captured.</param>
/// <param name="includeReleaseType">Whether the release type should be captured. When <see langword="false"/>, the release type is not captured.</param>
/// <param name="includeReleaseYear">Whether the release year should be captured. When <see langword="false"/>, the release year is not captured.</param>
/// <param name="includeReleaseName">Whether the release name should be captured. When <see langword="false"/>, the release name is not captured.</param>
/// <param name="includeTrackNumber">Whether the track number should be captured. When <see langword="false"/>, the track number is not captured.</param>
/// <param name="includeDiscNumber">Whether the disc number should be captured. When <see langword="false"/>, the disc number is not captured.</param>
/// <param name="includeTrackTitle">Whether the track title should be captured. When <see langword="false"/>, the track title is not captured.</param>
/// <returns>The created <see cref="MusicLibraryPathMetadata"/>.</returns>
public MusicLibraryPathMetadata Create(
string? artistName = null,
MusicReleaseType? releaseType = null,
int? releaseYear = null,
string? releaseName = null,
int? trackNumber = null,
int? discNumber = null,
string? trackTitle = null,
bool includeArtistName = true,
bool includeReleaseType = true,
bool includeReleaseYear = true,
bool includeReleaseName = true,
bool includeTrackNumber = true,
bool includeDiscNumber = true,
bool includeTrackTitle = true)
{
Dictionary<LibraryPathPartKind, string> values = [];
if (includeArtistName)
values[LibraryPathPartKind.Artist] = artistName ?? _faker.Name.FullName();
if (includeReleaseType)
values[LibraryPathPartKind.ReleaseType] = (releaseType ?? _faker.PickRandom<MusicReleaseType>()).ToString();
if (includeReleaseYear)
values[LibraryPathPartKind.ReleaseYear] = (releaseYear ?? _faker.Random.Int(1900, 2025)).ToString();
if (includeReleaseName)
values[LibraryPathPartKind.ReleaseName] = releaseName ?? _faker.Commerce.ProductName();
if (includeTrackNumber)
values[LibraryPathPartKind.TrackNumber] = (trackNumber ?? _faker.Random.Int(1, 30)).ToString();
if (includeDiscNumber)
values[LibraryPathPartKind.DiscNumber] = (discNumber ?? _faker.Random.Int(1, 4)).ToString();
if (includeTrackTitle)
values[LibraryPathPartKind.TrackName] = trackTitle ?? _faker.Commerce.ProductName();
return MusicLibraryPathMetadata.FromParsedLibraryPath(_parsedLibraryPathFixture.Create(values));
}
/// <summary>
/// Creates multiple <see cref="MusicLibraryPathMetadata"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MusicLibraryPathMetadata"/> instances.</returns>
public List<MusicLibraryPathMetadata> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="LibraryPathPart"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathPartFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LibraryPathPart"/>.
/// </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. When omitted, a representation valid for the resolved kind is generated.</param>
/// <param name="isOptional">Whether the path part can be absent from the path.</param>
/// <returns>The created <see cref="LibraryPathPart"/>.</returns>
public LibraryPathPart Create(
LibraryPathPartKind? kind = null,
string? representation = null,
bool isOptional = false)
{
LibraryPathPartKind resolvedKind = kind ?? _faker.PickRandom<LibraryPathPartKind>();
string resolvedRepresentation = representation ?? CreateValidRepresentation(resolvedKind);
Result<LibraryPathPart> partResult = LibraryPathPart.Create(resolvedKind, resolvedRepresentation, isOptional);
if (partResult.IsFailure)
throw new InvalidOperationException("Failed to create LibraryPathPart: " + string.Join(", ", partResult.Errors));
return partResult.Value;
}
/// <summary>
/// Creates multiple <see cref="LibraryPathPart"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathPart"/> instances.</returns>
public List<LibraryPathPart> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates a representation that is valid for the provided <paramref name="kind"/>.
/// </summary>
/// <param name="kind">The kind of the path part a representation is created for.</param>
/// <returns>The created representation.</returns>
private string CreateValidRepresentation(LibraryPathPartKind kind)
{
// A separator renders the platform path separator, so it never carries a representation.
if (kind == LibraryPathPartKind.Separator)
return string.Empty;
// A literal is arbitrary on-disk text between value parts, so it carries no value placeholder.
if (kind == LibraryPathPartKind.Literal)
return _faker.Lorem.Word();
// A typed part must carry exactly one value placeholder, so that the position of the captured value is unambiguous.
return "{0}";
}
}
@@ -0,0 +1,44 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplate"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplateFixture
{
private readonly Faker _faker = new();
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
/// <summary>
/// Creates a random valid <see cref="LibraryPathTemplate"/>.
/// </summary>
/// <param name="parts">Optional. The ordered parts that make up the path template.</param>
/// <param name="includeParts">Whether the template should carry parts. When <see langword="false"/>, an empty template is created.</param>
/// <returns>The created <see cref="LibraryPathTemplate"/>.</returns>
public LibraryPathTemplate Create(
IEnumerable<LibraryPathPart>? parts = null,
bool includeParts = true)
{
if (!includeParts)
return LibraryPathTemplate.Empty();
return LibraryPathTemplate.Create(parts ?? _libraryPathPartFixture.CreateMany(_faker.Random.Int(1, 4)));
}
/// <summary>
/// Creates multiple <see cref="LibraryPathTemplate"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathTemplate"/> instances.</returns>
public List<LibraryPathTemplate> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="LibraryPathPartDefinition"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathPartDefinitionFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LibraryPathPartDefinition"/>.
/// </summary>
/// <param name="kind">Optional. The kind of the described part.</param>
/// <param name="valueType">Optional. The value type captured by the described part.</param>
/// <param name="defaultRepresentation">Optional. The default representation of the described part.</param>
/// <param name="isOptionalByDefault">Whether the described part is optional by default.</param>
/// <returns>The created <see cref="LibraryPathPartDefinition"/>.</returns>
public LibraryPathPartDefinition Create(
LibraryPathPartKind? kind = null,
LibraryPathValueType? valueType = null,
string? defaultRepresentation = null,
bool isOptionalByDefault = false)
{
return new LibraryPathPartDefinition(
kind ?? _faker.PickRandom<LibraryPathPartKind>(),
valueType ?? _faker.PickRandom<LibraryPathValueType>(),
defaultRepresentation ?? "{0}",
isOptionalByDefault);
}
/// <summary>
/// Creates multiple <see cref="LibraryPathPartDefinition"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathPartDefinition"/> instances.</returns>
public List<LibraryPathPartDefinition> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,65 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="ParsedLibraryPath"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class ParsedLibraryPathFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ParsedLibraryPath"/>.
/// </summary>
/// <param name="values">Optional. The captured values, keyed by their part kind.</param>
/// <param name="includeValues">Whether the parsed path should carry captured values. When <see langword="false"/>, an empty set of values is created.</param>
/// <returns>The created <see cref="ParsedLibraryPath"/>.</returns>
public ParsedLibraryPath Create(
IReadOnlyDictionary<LibraryPathPartKind, string>? values = null,
bool includeValues = true)
{
if (!includeValues)
return ParsedLibraryPath.Create(new Dictionary<LibraryPathPartKind, string>());
return ParsedLibraryPath.Create(values ?? CreateRandomValues());
}
/// <summary>
/// Creates multiple <see cref="ParsedLibraryPath"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ParsedLibraryPath"/> instances.</returns>
public List<ParsedLibraryPath> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates a bounded set of random captured values.
/// </summary>
/// <returns>The captured values, keyed by their part kind.</returns>
private Dictionary<LibraryPathPartKind, string> CreateRandomValues()
{
LibraryPathPartKind[] candidateKinds =
[
LibraryPathPartKind.Artist,
LibraryPathPartKind.ReleaseName,
LibraryPathPartKind.TrackName,
LibraryPathPartKind.Title,
LibraryPathPartKind.Author
];
Dictionary<LibraryPathPartKind, string> values = [];
foreach (LibraryPathPartKind kind in candidateKinds.Take(_faker.Random.Int(1, candidateKinds.Length)))
values[kind] = _faker.Lorem.Word();
return values;
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Libraries;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
/// <summary>
/// Fixture class for the <see cref="LibraryPathPartDefinitionDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathPartDefinitionDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="LibraryPathPartDefinitionDto"/> instance with randomized test data.
/// </summary>
/// <param name="kind">Optional kind of the path part.</param>
/// <param name="valueType">Optional value type captured by the path part.</param>
/// <param name="defaultRepresentation">Optional default representation of the path part.</param>
/// <param name="isOptionalByDefault">Optional value indicating whether the path part is optional by default.</param>
/// <returns>A configured <see cref="LibraryPathPartDefinitionDto"/> instance.</returns>
public LibraryPathPartDefinitionDto Create(
string? kind = null,
string? valueType = null,
string? defaultRepresentation = null,
bool? isOptionalByDefault = null)
{
return new LibraryPathPartDefinitionDto
{
Kind = kind ?? _faker.Random.Word(),
ValueType = valueType ?? _faker.Random.Word(),
DefaultRepresentation = defaultRepresentation ?? "{0}",
IsOptionalByDefault = isOptionalByDefault ?? _faker.Random.Bool()
};
}
/// <summary>
/// Creates multiple <see cref="LibraryPathPartDefinitionDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathPartDefinitionDto"/> instances.</returns>
public List<LibraryPathPartDefinitionDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.DTO.Libraries;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplateCatalogDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplateCatalogDtoFixture
{
private readonly LibraryPathPartDefinitionDtoFixture _libraryPathPartDefinitionDtoFixture = new();
private readonly LibraryPathTemplatePartDtoFixture _libraryPathTemplatePartDtoFixture = new();
/// <summary>
/// Creates a new <see cref="LibraryPathTemplateCatalogDto"/> instance with randomized test data.
/// </summary>
/// <param name="parts">Optional path parts that can be used in the path template of the library type.</param>
/// <param name="defaultTemplateParts">Optional ordered parts of the default path template of the library type.</param>
/// <param name="includeParts">Whether the catalog should carry selectable path parts. When <see langword="false"/>, the parts are forced to an empty collection.</param>
/// <param name="includeDefaultTemplateParts">Whether the catalog should carry default template parts. When <see langword="false"/>, the default template parts are forced to an empty collection.</param>
/// <returns>A configured <see cref="LibraryPathTemplateCatalogDto"/> instance.</returns>
public LibraryPathTemplateCatalogDto Create(
List<LibraryPathPartDefinitionDto>? parts = null,
List<LibraryPathTemplatePartDto>? defaultTemplateParts = null,
bool includeParts = true,
bool includeDefaultTemplateParts = true)
{
return new LibraryPathTemplateCatalogDto
{
Parts = includeParts ? (parts ?? _libraryPathPartDefinitionDtoFixture.CreateMany(2)) : [],
DefaultTemplateParts = includeDefaultTemplateParts ? (defaultTemplateParts ?? _libraryPathTemplatePartDtoFixture.CreateMany(2)) : []
};
}
/// <summary>
/// Creates multiple <see cref="LibraryPathTemplateCatalogDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathTemplateCatalogDto"/> instances.</returns>
public List<LibraryPathTemplateCatalogDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Libraries;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
/// <summary>
/// Fixture class for the <see cref="LibraryPathTemplatePartDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="LibraryPathTemplatePartDto"/> instance with randomized test data.
/// </summary>
/// <param name="kind">Optional kind of the path part.</param>
/// <param name="representation">Optional literal text or value mask of the path part.</param>
/// <param name="isOptional">Optional value indicating whether the path part can be absent from the path.</param>
/// <returns>A configured <see cref="LibraryPathTemplatePartDto"/> instance.</returns>
public LibraryPathTemplatePartDto Create(
string? kind = null,
string? representation = null,
bool? isOptional = null)
{
return new LibraryPathTemplatePartDto
{
Kind = kind ?? _faker.Random.Word(),
Representation = representation ?? "{0}",
IsOptional = isOptional ?? _faker.Random.Bool()
};
}
/// <summary>
/// Creates multiple <see cref="LibraryPathTemplatePartDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryPathTemplatePartDto"/> instances.</returns>
public List<LibraryPathTemplatePartDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Library.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Library.Management;
/// <summary>
/// Fixture class for the <see cref="GetLibraryPathTemplatePartsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryPathTemplatePartsRequestFixture
{
/// <summary>
/// Creates a random valid <see cref="GetLibraryPathTemplatePartsRequest"/>.
/// </summary>
/// <param name="libraryType">Optional. The media library type whose available path parts are retrieved.</param>
/// <returns>The created <see cref="GetLibraryPathTemplatePartsRequest"/>.</returns>
public GetLibraryPathTemplatePartsRequest Create(
string? libraryType = null)
{
return new GetLibraryPathTemplatePartsRequest(libraryType ?? "Music");
}
/// <summary>
/// Creates a list of <see cref="GetLibraryPathTemplatePartsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryPathTemplatePartsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}