Adds the music artist alias, area, and work value objects and their enumerations

This commit is contained in:
BinaryAlley committed 2026-10-06 09:14:00 +03:00
1 parent bf8b49653d
commit e20e244a04
12 files changed
+1389

No files matched your search

@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
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="MusicArea"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicAreaFixture
{
private readonly Faker _faker = new();
private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="MusicArea"/>.
/// </summary>
/// <param name="musicBrainzAreaId">Optional. The MusicBrainz identifier of the area.</param>
/// <param name="name">Optional. The name of the area.</param>
/// <param name="sortName">Optional. The sort name of the area.</param>
/// <param name="disambiguation">Optional. The disambiguation comment of the area.</param>
/// <param name="type">Optional. The MusicBrainz type of the area.</param>
/// <param name="iso3166Code">Optional. The ISO 3166 code of the area.</param>
/// <returns>The created <see cref="MusicArea"/>.</returns>
public MusicArea Create(
MusicBrainzId? musicBrainzAreaId = null,
string? name = null,
Optional<string>? sortName = null,
Optional<string>? disambiguation = null,
Optional<string>? type = null,
Optional<string>? iso3166Code = null)
{
Result<MusicArea> areaResult = MusicArea.Create(
musicBrainzAreaId ?? _musicBrainzIdFixture.Create(),
name ?? _faker.Address.Country(),
sortName ?? Optional<string>.Some(_faker.Address.Country()),
disambiguation ?? Optional<string>.Some(_faker.Lorem.Sentence()),
type ?? Optional<string>.Some(_faker.Random.ArrayElement(["Country", "City", "Area"])),
iso3166Code ?? Optional<string>.Some(_faker.Address.CountryCode()));
if (areaResult.IsFailure)
throw new System.InvalidOperationException("Failed to create MusicArea: " + string.Join(", ", areaResult.Errors));
return areaResult.Value;
}
/// <summary>
/// Creates multiple <see cref="MusicArea"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MusicArea"/> instances.</returns>
public List<MusicArea> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,72 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using System;
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="MusicArtistAlias"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicArtistAliasFixture
{
private const int MINIMUM_ALIAS_YEAR = 1900;
private const int MAXIMUM_ALIAS_YEAR = 2026;
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MusicArtistAlias"/>.
/// </summary>
/// <param name="name">Optional. The name of the alias.</param>
/// <param name="sortName">Optional. The sort name of the alias.</param>
/// <param name="type">Optional. The type of the alias.</param>
/// <param name="locale">Optional. The locale the alias is used in.</param>
/// <param name="isPrimary">Optional. Whether this is the primary alias of the artist.</param>
/// <param name="beginDate">Optional. The date the alias began being used.</param>
/// <param name="endDate">Optional. The date the alias stopped being used.</param>
/// <param name="isEnded">Optional. Whether the alias is no longer used.</param>
/// <returns>The created <see cref="MusicArtistAlias"/>.</returns>
public MusicArtistAlias Create(
string? name = null,
Optional<string>? sortName = null,
Optional<string>? type = null,
Optional<string>? locale = null,
bool? isPrimary = null,
Optional<DateOnly>? beginDate = null,
Optional<DateOnly>? endDate = null,
bool? isEnded = null)
{
int beginYear = Random.Shared.Next(MINIMUM_ALIAS_YEAR, MAXIMUM_ALIAS_YEAR);
int endYear = Random.Shared.Next(beginYear, Math.Max(beginYear + 1, MAXIMUM_ALIAS_YEAR));
Result<MusicArtistAlias> aliasResult = MusicArtistAlias.Create(
name ?? _faker.Name.FullName(),
sortName ?? Optional<string>.Some(_faker.Name.FullName()),
type ?? Optional<string>.Some(_faker.Random.ArrayElement(["Artist name", "Search hint"])),
locale ?? Optional<string>.Some(_faker.Random.String2(2)),
isPrimary ?? _faker.Random.Bool(),
beginDate ?? Optional<DateOnly>.Some(new DateOnly(beginYear, 1, 1)),
endDate ?? Optional<DateOnly>.Some(new DateOnly(endYear, 1, 1)),
isEnded ?? _faker.Random.Bool());
if (aliasResult.IsFailure)
throw new InvalidOperationException("Failed to create MusicArtistAlias: " + string.Join(", ", aliasResult.Errors));
return aliasResult.Value;
}
/// <summary>
/// Creates multiple <see cref="MusicArtistAlias"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MusicArtistAlias"/> instances.</returns>
public List<MusicArtistAlias> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
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="MusicWork"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicWorkFixture
{
private readonly Faker _faker = new();
private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new();
private readonly LanguageInfoFixture _languageInfoFixture = new();
/// <summary>
/// Creates a random valid <see cref="MusicWork"/>.
/// </summary>
/// <param name="musicBrainzWorkId">Optional. The MusicBrainz identifier of the work.</param>
/// <param name="title">Optional. The title of the work.</param>
/// <param name="type">Optional. The MusicBrainz type of the work.</param>
/// <param name="languages">Optional. The languages of the work.</param>
/// <param name="iswcs">Optional. The ISWC codes of the work.</param>
/// <returns>The created <see cref="MusicWork"/>.</returns>
public MusicWork Create(
MusicBrainzId? musicBrainzWorkId = null,
string? title = null,
Optional<string>? type = null,
List<LanguageInfo>? languages = null,
List<string>? iswcs = null)
{
Result<MusicWork> workResult = MusicWork.Create(
musicBrainzWorkId ?? _musicBrainzIdFixture.Create(),
title ?? _faker.Music.Genre(),
type ?? Optional<string>.Some(_faker.Random.ArrayElement(["Song", "Instrumental"])),
languages ?? _languageInfoFixture.CreateMany(_faker.Random.Int(1, 2)),
iswcs ?? [.. Enumerable.Range(0, _faker.Random.Int(1, 2)).Select(_ => $"T{_faker.Random.AlphaNumeric(10)}")]);
if (workResult.IsFailure)
throw new System.InvalidOperationException("Failed to create MusicWork: " + string.Join(", ", workResult.Errors));
return workResult.Value;
}
/// <summary>
/// Creates multiple <see cref="MusicWork"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MusicWork"/> instances.</returns>
public List<MusicWork> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}