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
+85
@@ -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())];
|
||||
}
|
||||
}
|
||||
+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