mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Adds the test suites for the library path templates and centralizes their resolution in the domain service
This commit is contained in:
1 parent
ca4f308b0a
commit
7ed6f05632
52 files changed
+4724
-40
No files matched your search
+68
@@ -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}";
|
||||
}
|
||||
}
|
||||
+44
@@ -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())];
|
||||
}
|
||||
}
|
||||
+50
@@ -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())];
|
||||
}
|
||||
}
|
||||
+65
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user