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,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())];
}
}