diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistGender.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistGender.cs new file mode 100644 index 00000000..528dd181 --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistGender.cs @@ -0,0 +1,32 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; + +/// +/// Enumeration for the gender of a music artist, applicable only to artists that are persons or characters. +/// +[DebuggerDisplay("{ToString()}")] +public enum MusicArtistGender +{ + /// + /// The artist identifies as male. + /// + Male, + + /// + /// The artist identifies as female. + /// + Female, + + /// + /// The artist identifies with a gender other than male or female. + /// + Other, + + /// + /// The gender of the artist is not applicable, or is deliberately not stated. + /// + NotApplicable +} diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistType.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistType.cs new file mode 100644 index 00000000..230cdf62 --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicArtistType.cs @@ -0,0 +1,42 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; + +/// +/// Enumeration for the type of a music artist, describing whether the artist is an individual, an ensemble, or something else. +/// +[DebuggerDisplay("{ToString()}")] +public enum MusicArtistType +{ + /// + /// The artist is an individual person. + /// + Person, + + /// + /// The artist is a group of people that may or may not have a distinctive name. + /// + Group, + + /// + /// The artist is an orchestra, a large instrumental ensemble. + /// + Orchestra, + + /// + /// The artist is a choir or chorus, a large vocal ensemble. + /// + Choir, + + /// + /// The artist is an individual fictional character. + /// + Character, + + /// + /// The type of the artist does not fit into any of the known categories. + /// + Other +} diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicReleasePackaging.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicReleasePackaging.cs new file mode 100644 index 00000000..aa2f5d2c --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/AudioLibrary/MusicReleasePackaging.cs @@ -0,0 +1,132 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; + +/// +/// Enumeration for the outermost physical packaging of a music release. +/// +[DebuggerDisplay("{ToString()}")] +public enum MusicReleasePackaging +{ + /// + /// The release is a book with a sleeve containing a medium, usually a compact disc. + /// + Book, + + /// + /// The release is a box with a lid or an opening that contains the medium and other packaging, like posters and a booklet. + /// + Box, + + /// + /// The release is a sleeve made of paper, paperboard, or cardboard. + /// + CardboardPaperSleeve, + + /// + /// The release is a regular plastic case for a cassette. + /// + CassetteCase, + + /// + /// The release is a minimalistic plastic case where the back and the front are kept together by a small hinge. + /// + ClamshellCase, + + /// + /// The release is a bounded booklet, usually in hardcover, with a sleeve bound to its spine that houses a compact disc. + /// + Digibook, + + /// + /// The release is a folded cardboard compact disc packaging that has a small pocket on one side for the disc. + /// + Digifile, + + /// + /// The release is a folded case, typically made of coated paperboard, with one or more plastic trays glued into it. + /// + Digipak, + + /// + /// The release is a pouch-like package with an internal mechanism that pushes the contents out when the lid flap is opened. + /// + DiscboxSlider, + + /// + /// The release is a double-sided, double-width jewel case normally holding two to four compact discs. + /// + Fatbox, + + /// + /// The release is a cardboard sleeve that folds in halves, thirds, or more, and can hold multiple records, compact discs, booklets, or posters. + /// + GatefoldCover, + + /// + /// The release is the traditional compact disc case, made of hard, brittle plastic. + /// + JewelCase, + + /// + /// The release is the traditional DVD case, made of soft plastic with a thin transparent cover protecting the artwork. + /// + KeepCase, + + /// + /// The release is a large cardboard box, often used to sell compact discs in North America so that they would fit vinyl racks. + /// + Longbox, + + /// + /// The release is an often decorated metal tin containing one or more compact discs. + /// + MetalTin, + + /// + /// The release is a sleeve made entirely of plastic that holds the medium and the other parts of the album. + /// + PlasticSleeve, + + /// + /// The release is a box with openings at its two ends that contains a tray holding the medium. + /// + Slidepack, + + /// + /// The release is a thinner jewel case, commonly used for compact disc singles. + /// + SlimJewelCase, + + /// + /// The release is a four or five-sided box that surrounds a second inner package such as a jewel case. + /// + Slipcase, + + /// + /// The release is a digipak-like case held together with a snapping plastic closure. + /// + SnapCase, + + /// + /// The release is a cardboard jacket, commonly used for 8cm compact disc singles in Japan. + /// + SnapPack, + + /// + /// The release is a case similar to the regular jewel case, but with rounded corners and a latch closing mechanism. + /// + SuperJewelBox, + + /// + /// The packaging of the release does not fit into any of the known categories. + /// + Other, + + /// + /// The release has no packaging at all, which is common for digital media. + /// + None +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArea.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArea.cs new file mode 100644 index 00000000..d4c2ead0 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArea.cs @@ -0,0 +1,111 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Value Object for a MusicBrainz area, the geographic area a music artist is associated with. +/// +[DebuggerDisplay("{Name}")] +public sealed class MusicArea : ValueObject +{ + /// + /// Gets the MusicBrainz identifier of the area. + /// + public MusicBrainzId MusicBrainzAreaId { get; } + + /// + /// Gets the name of the area. + /// + public string Name { get; } + + /// + /// Gets the optional sort name of the area. + /// + public Optional SortName { get; } + + /// + /// Gets the optional disambiguation comment of the area. + /// + public Optional Disambiguation { get; } + + /// + /// Gets the optional MusicBrainz type of the area (e.g., Country, City). + /// + public Optional Type { get; } + + /// + /// Gets the optional ISO 3166 code of the area. + /// + public Optional Iso3166Code { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The MusicBrainz identifier of the area. + /// The name of the area. + /// The optional sort name of the area. + /// The optional disambiguation comment of the area. + /// The optional MusicBrainz type of the area. + /// The optional ISO 3166 code of the area. + private MusicArea( + MusicBrainzId musicBrainzAreaId, + string name, + Optional sortName, + Optional disambiguation, + Optional type, + Optional iso3166Code) + { + MusicBrainzAreaId = musicBrainzAreaId; + Name = name; + SortName = sortName; + Disambiguation = disambiguation; + Type = type; + Iso3166Code = iso3166Code; + } + + /// + /// Creates a new instance of the class. + /// + /// The MusicBrainz identifier of the area. + /// The name of the area. + /// The optional sort name of the area. + /// The optional disambiguation comment of the area. + /// The optional MusicBrainz type of the area. + /// The optional ISO 3166 code of the area. + /// + /// An containing either a successfully created , or an error message. + /// + public static Result Create( + MusicBrainzId musicBrainzAreaId, + string name, + Optional sortName, + Optional disambiguation, + Optional type, + Optional iso3166Code) + { + if (string.IsNullOrWhiteSpace(name)) + return Errors.Music.AreaNameCannotBeEmpty; + + return new MusicArea(musicBrainzAreaId, name.Trim(), sortName, disambiguation, type, iso3166Code); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return MusicBrainzAreaId; + yield return Name; + yield return SortName; + yield return Disambiguation; + yield return Type; + yield return Iso3166Code; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAlias.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAlias.cs new file mode 100644 index 00000000..caff08a1 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAlias.cs @@ -0,0 +1,134 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Value Object for an alternative name of a music artist. +/// +[DebuggerDisplay("{Name}")] +public sealed class MusicArtistAlias : ValueObject +{ + /// + /// Gets the name of the alias. + /// + public string Name { get; } + + /// + /// Gets the optional sort name of the alias. + /// + public Optional SortName { get; } + + /// + /// Gets the optional type of the alias (e.g., Artist name, Search hint). + /// + public Optional Type { get; } + + /// + /// Gets the optional locale the alias is used in. + /// + public Optional Locale { get; } + + /// + /// Gets a value indicating whether this is the primary alias of the artist. + /// + public bool IsPrimary { get; } + + /// + /// Gets the optional date the alias began being used. + /// + public Optional BeginDate { get; } + + /// + /// Gets the optional date the alias stopped being used. + /// + public Optional EndDate { get; } + + /// + /// Gets a value indicating whether the alias is no longer used. + /// + public bool IsEnded { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the alias. + /// The optional sort name of the alias. + /// The optional type of the alias. + /// The optional locale the alias is used in. + /// Whether this is the primary alias of the artist. + /// The optional date the alias began being used. + /// The optional date the alias stopped being used. + /// Whether the alias is no longer used. + private MusicArtistAlias( + string name, + Optional sortName, + Optional type, + Optional locale, + bool isPrimary, + Optional beginDate, + Optional endDate, + bool isEnded) + { + Name = name; + SortName = sortName; + Type = type; + Locale = locale; + IsPrimary = isPrimary; + BeginDate = beginDate; + EndDate = endDate; + IsEnded = isEnded; + } + + /// + /// Creates a new instance of the class. + /// + /// The name of the alias. + /// The optional sort name of the alias. + /// The optional type of the alias. + /// The optional locale the alias is used in. + /// Whether this is the primary alias of the artist. + /// The optional date the alias began being used. + /// The optional date the alias stopped being used. + /// Whether the alias is no longer used. + /// + /// An containing either a successfully created , or an error message. + /// + public static Result Create( + string name, + Optional sortName, + Optional type, + Optional locale, + bool isPrimary, + Optional beginDate, + Optional endDate, + bool isEnded) + { + if (string.IsNullOrWhiteSpace(name)) + return Errors.Music.ArtistAliasNameCannotBeEmpty; + + return new MusicArtistAlias(name.Trim(), sortName, type, locale, isPrimary, beginDate, endDate, isEnded); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return Name; + yield return SortName; + yield return Type; + yield return Locale; + yield return IsPrimary; + yield return BeginDate; + yield return EndDate; + yield return IsEnded; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWork.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWork.cs new file mode 100644 index 00000000..fc6edc94 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWork.cs @@ -0,0 +1,106 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Common.ValueObjects.Metadata; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Value Object for a MusicBrainz work, the musical composition a track is a recording of. +/// +[DebuggerDisplay("{Title}")] +public sealed class MusicWork : ValueObject +{ + private readonly List _languages; + private readonly List _iswcs; + + /// + /// Gets the MusicBrainz identifier of the work. + /// + public MusicBrainzId MusicBrainzWorkId { get; } + + /// + /// Gets the title of the work. + /// + public string Title { get; } + + /// + /// Gets the optional MusicBrainz type of the work (e.g., Song). + /// + public Optional Type { get; } + + /// + /// Gets the list of languages of the work. + /// + public IReadOnlyCollection Languages => _languages.AsReadOnly(); + + /// + /// Gets the list of ISWC (International Standard Musical Work Code) of the work. + /// + public IReadOnlyCollection Iswcs => _iswcs.AsReadOnly(); + + /// + /// Initializes a new instance of the class. + /// + /// The MusicBrainz identifier of the work. + /// The title of the work. + /// The optional MusicBrainz type of the work. + /// The list of languages of the work. + /// The list of ISWC of the work. + private MusicWork( + MusicBrainzId musicBrainzWorkId, + string title, + Optional type, + List languages, + List iswcs) + { + MusicBrainzWorkId = musicBrainzWorkId; + Title = title; + Type = type; + _languages = languages; + _iswcs = iswcs; + } + + /// + /// Creates a new instance of the class. + /// + /// The MusicBrainz identifier of the work. + /// The title of the work. + /// The optional MusicBrainz type of the work. + /// The list of languages of the work. + /// The list of ISWC of the work. + /// + /// An containing either a successfully created , or an error message. + /// + public static Result Create( + MusicBrainzId musicBrainzWorkId, + string title, + Optional type, + List languages, + List iswcs) + { + if (string.IsNullOrWhiteSpace(title)) + return Errors.Music.WorkTitleCannotBeEmpty; + + return new MusicWork(musicBrainzWorkId, title.Trim(), type, languages, iswcs); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return MusicBrainzWorkId; + yield return Title; + yield return Type; + foreach (LanguageInfo language in _languages) + yield return language; + foreach (string iswc in _iswcs) + yield return iswc; + } +} diff --git a/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaFixture.cs b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaFixture.cs new file mode 100644 index 00000000..94fea40f --- /dev/null +++ b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaFixture.cs @@ -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; + +/// +/// Fixture class for the domain value object. +/// +[ExcludeFromCodeCoverage] +public class MusicAreaFixture +{ + private readonly Faker _faker = new(); + private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The MusicBrainz identifier of the area. + /// Optional. The name of the area. + /// Optional. The sort name of the area. + /// Optional. The disambiguation comment of the area. + /// Optional. The MusicBrainz type of the area. + /// Optional. The ISO 3166 code of the area. + /// The created . + public MusicArea Create( + MusicBrainzId? musicBrainzAreaId = null, + string? name = null, + Optional? sortName = null, + Optional? disambiguation = null, + Optional? type = null, + Optional? iso3166Code = null) + { + Result areaResult = MusicArea.Create( + musicBrainzAreaId ?? _musicBrainzIdFixture.Create(), + name ?? _faker.Address.Country(), + sortName ?? Optional.Some(_faker.Address.Country()), + disambiguation ?? Optional.Some(_faker.Lorem.Sentence()), + type ?? Optional.Some(_faker.Random.ArrayElement(["Country", "City", "Area"])), + iso3166Code ?? Optional.Some(_faker.Address.CountryCode())); + + if (areaResult.IsFailure) + throw new System.InvalidOperationException("Failed to create MusicArea: " + string.Join(", ", areaResult.Errors)); + return areaResult.Value; + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasFixture.cs b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasFixture.cs new file mode 100644 index 00000000..f1a868eb --- /dev/null +++ b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasFixture.cs @@ -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; + +/// +/// Fixture class for the domain value object. +/// +[ExcludeFromCodeCoverage] +public class MusicArtistAliasFixture +{ + private const int MINIMUM_ALIAS_YEAR = 1900; + private const int MAXIMUM_ALIAS_YEAR = 2026; + + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The name of the alias. + /// Optional. The sort name of the alias. + /// Optional. The type of the alias. + /// Optional. The locale the alias is used in. + /// Optional. Whether this is the primary alias of the artist. + /// Optional. The date the alias began being used. + /// Optional. The date the alias stopped being used. + /// Optional. Whether the alias is no longer used. + /// The created . + public MusicArtistAlias Create( + string? name = null, + Optional? sortName = null, + Optional? type = null, + Optional? locale = null, + bool? isPrimary = null, + Optional? beginDate = null, + Optional? 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 aliasResult = MusicArtistAlias.Create( + name ?? _faker.Name.FullName(), + sortName ?? Optional.Some(_faker.Name.FullName()), + type ?? Optional.Some(_faker.Random.ArrayElement(["Artist name", "Search hint"])), + locale ?? Optional.Some(_faker.Random.String2(2)), + isPrimary ?? _faker.Random.Bool(), + beginDate ?? Optional.Some(new DateOnly(beginYear, 1, 1)), + endDate ?? Optional.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; + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkFixture.cs b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkFixture.cs new file mode 100644 index 00000000..d41ed5d7 --- /dev/null +++ b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkFixture.cs @@ -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; + +/// +/// Fixture class for the domain value object. +/// +[ExcludeFromCodeCoverage] +public class MusicWorkFixture +{ + private readonly Faker _faker = new(); + private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new(); + private readonly LanguageInfoFixture _languageInfoFixture = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The MusicBrainz identifier of the work. + /// Optional. The title of the work. + /// Optional. The MusicBrainz type of the work. + /// Optional. The languages of the work. + /// Optional. The ISWC codes of the work. + /// The created . + public MusicWork Create( + MusicBrainzId? musicBrainzWorkId = null, + string? title = null, + Optional? type = null, + List? languages = null, + List? iswcs = null) + { + Result workResult = MusicWork.Create( + musicBrainzWorkId ?? _musicBrainzIdFixture.Create(), + title ?? _faker.Music.Genre(), + type ?? Optional.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; + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaTests.cs new file mode 100644 index 00000000..1dadf494 --- /dev/null +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicAreaTests.cs @@ -0,0 +1,199 @@ +#region ========================================================================= USING ===================================================================================== +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; +using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; +using System; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Contains unit tests for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicAreaTests +{ + private readonly MusicAreaFixture _musicAreaFixture = new(); + private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new(); + + [Fact] + public void Create_WhenCalledWithValidValues_ShouldCreateMusicAreaWithAllPropertiesSet() + { + // Arrange + MusicBrainzId areaId = _musicBrainzIdFixture.Create(value: Guid.Parse("f0e9c1a2-0000-0000-0000-000000000000")); + + // Act + Result result = MusicArea.Create( + areaId, + "United Kingdom", + Optional.Some("UK"), + Optional.Some("The United Kingdom of Great Britain and Northern Ireland"), + Optional.Some("Country"), + Optional.Some("GB")); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(areaId, result.Value.MusicBrainzAreaId); + Assert.Equal("United Kingdom", result.Value.Name); + Assert.Equal(Optional.Some("UK"), result.Value.SortName); + Assert.Equal(Optional.Some("The United Kingdom of Great Britain and Northern Ireland"), result.Value.Disambiguation); + Assert.Equal(Optional.Some("Country"), result.Value.Type); + Assert.Equal(Optional.Some("GB"), result.Value.Iso3166Code); + } + + [Fact] + public void Create_WhenNameHasSurroundingWhitespace_ShouldTrimIt() + { + // Act + Result result = MusicArea.Create( + _musicBrainzIdFixture.Create(), + " United Kingdom ", + Optional.None(), + Optional.None(), + Optional.None(), + Optional.None()); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("United Kingdom", result.Value.Name); + } + + [Theory] + [InlineData(null)] // null area name + [InlineData("")] // empty area name + [InlineData(" ")] // whitespace area name + public void Create_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name) + { + // Act + Result result = MusicArea.Create( + _musicBrainzIdFixture.Create(), + name!, + Optional.None(), + Optional.None(), + Optional.None(), + Optional.None()); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(DomainErrors.Music.AreaNameCannotBeEmpty, result.FirstError); + } + + [Fact] + public void Create_WhenOptionalValuesAreAbsent_ShouldCreateMusicAreaWithoutThem() + { + // Act + Result result = MusicArea.Create( + _musicBrainzIdFixture.Create(), + "United Kingdom", + Optional.None(), + Optional.None(), + Optional.None(), + Optional.None()); + + // Assert + Assert.False(result.IsFailure); + Assert.False(result.Value.SortName.HasValue); + Assert.False(result.Value.Disambiguation.HasValue); + Assert.False(result.Value.Type.HasValue); + Assert.False(result.Value.Iso3166Code.HasValue); + } + + [Fact] + public void Equals_WithSameValues_ShouldReturnTrue() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(); + + // Act + MusicArea secondArea = _musicAreaFixture.Create( + musicBrainzAreaId: firstArea.MusicBrainzAreaId, + name: firstArea.Name, + sortName: firstArea.SortName, + disambiguation: firstArea.Disambiguation, + type: firstArea.Type, + iso3166Code: firstArea.Iso3166Code); + + // Assert + Assert.Equal(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentMusicBrainzAreaId_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(musicBrainzAreaId: _musicBrainzIdFixture.Create(value: Guid.Parse("11111111-1111-1111-1111-111111111111"))); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(musicBrainzAreaId: _musicBrainzIdFixture.Create(value: Guid.Parse("22222222-2222-2222-2222-222222222222"))); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentName_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(name: "United Kingdom"); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(name: "France"); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentSortName_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(sortName: Optional.Some("UK")); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(sortName: Optional.Some("GB")); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentDisambiguation_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(disambiguation: Optional.Some("The country")); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(disambiguation: Optional.Some("The region")); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentType_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(type: Optional.Some("Country")); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(type: Optional.Some("City")); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } + + [Fact] + public void Equals_WithDifferentIso3166Code_ShouldReturnFalse() + { + // Arrange + MusicArea firstArea = _musicAreaFixture.Create(iso3166Code: Optional.Some("GB")); + + // Act + MusicArea secondArea = _musicAreaFixture.Create(iso3166Code: Optional.Some("FR")); + + // Assert + Assert.NotEqual(firstArea, secondArea); + } +} diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasTests.cs new file mode 100644 index 00000000..9e84ec84 --- /dev/null +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicArtistAliasTests.cs @@ -0,0 +1,238 @@ +#region ========================================================================= USING ===================================================================================== +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; +using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; +using System; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Contains unit tests for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicArtistAliasTests +{ + private readonly MusicArtistAliasFixture _musicArtistAliasFixture = new(); + + [Fact] + public void Create_WhenCalledWithValidValues_ShouldCreateAliasWithAllPropertiesSet() + { + // Arrange + DateOnly beginDate = new(1970, 1, 1); + DateOnly endDate = new(1991, 1, 1); + + // Act + Result result = MusicArtistAlias.Create( + "Freddie Mercury", + Optional.Some("Mercury, Freddie"), + Optional.Some("Artist name"), + Optional.Some("en"), + isPrimary: true, + Optional.Some(beginDate), + Optional.Some(endDate), + isEnded: true); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("Freddie Mercury", result.Value.Name); + Assert.Equal(Optional.Some("Mercury, Freddie"), result.Value.SortName); + Assert.Equal(Optional.Some("Artist name"), result.Value.Type); + Assert.Equal(Optional.Some("en"), result.Value.Locale); + Assert.True(result.Value.IsPrimary); + Assert.Equal(Optional.Some(beginDate), result.Value.BeginDate); + Assert.Equal(Optional.Some(endDate), result.Value.EndDate); + Assert.True(result.Value.IsEnded); + } + + [Fact] + public void Create_WhenNameHasSurroundingWhitespace_ShouldTrimIt() + { + // Act + Result result = MusicArtistAlias.Create( + " Freddie Mercury ", + Optional.None(), + Optional.None(), + Optional.None(), + isPrimary: false, + Optional.None(), + Optional.None(), + isEnded: false); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("Freddie Mercury", result.Value.Name); + } + + [Theory] + [InlineData(null)] // null alias name + [InlineData("")] // empty alias name + [InlineData(" ")] // whitespace alias name + public void Create_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name) + { + // Act + Result result = MusicArtistAlias.Create( + name!, + Optional.None(), + Optional.None(), + Optional.None(), + isPrimary: false, + Optional.None(), + Optional.None(), + isEnded: false); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(DomainErrors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError); + } + + [Fact] + public void Create_WhenOptionalValuesAreAbsent_ShouldCreateAliasWithoutThem() + { + // Act + Result result = MusicArtistAlias.Create( + "Freddie Mercury", + Optional.None(), + Optional.None(), + Optional.None(), + isPrimary: false, + Optional.None(), + Optional.None(), + isEnded: false); + + // Assert + Assert.False(result.IsFailure); + Assert.False(result.Value.SortName.HasValue); + Assert.False(result.Value.Type.HasValue); + Assert.False(result.Value.Locale.HasValue); + Assert.False(result.Value.BeginDate.HasValue); + Assert.False(result.Value.EndDate.HasValue); + } + + [Fact] + public void Equals_WithSameValues_ShouldReturnTrue() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create( + name: firstAlias.Name, + sortName: firstAlias.SortName, + type: firstAlias.Type, + locale: firstAlias.Locale, + isPrimary: firstAlias.IsPrimary, + beginDate: firstAlias.BeginDate, + endDate: firstAlias.EndDate, + isEnded: firstAlias.IsEnded); + + // Assert + Assert.Equal(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentName_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(name: "Freddie Mercury"); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(name: "Farrokh Bulsara"); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentSortName_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(sortName: Optional.Some("Mercury, Freddie")); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(sortName: Optional.Some("Bulsara, Farrokh")); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentType_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(type: Optional.Some("Artist name")); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(type: Optional.Some("Search hint")); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentLocale_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(locale: Optional.Some("en")); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(locale: Optional.Some("fr")); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentIsPrimary_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(isPrimary: true); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(isPrimary: false); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentBeginDate_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(beginDate: Optional.Some(new DateOnly(1970, 1, 1))); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(beginDate: Optional.Some(new DateOnly(1980, 1, 1))); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentEndDate_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(endDate: Optional.Some(new DateOnly(1991, 1, 1))); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(endDate: Optional.Some(new DateOnly(2000, 1, 1))); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } + + [Fact] + public void Equals_WithDifferentIsEnded_ShouldReturnFalse() + { + // Arrange + MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(isEnded: true); + + // Act + MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(isEnded: false); + + // Assert + Assert.NotEqual(firstAlias, secondAlias); + } +} diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkTests.cs new file mode 100644 index 00000000..020214b7 --- /dev/null +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicWorkTests.cs @@ -0,0 +1,201 @@ +#region ========================================================================= USING ===================================================================================== +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +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 Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Contains unit tests for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicWorkTests +{ + private readonly MusicWorkFixture _musicWorkFixture = new(); + private readonly MusicBrainzIdFixture _musicBrainzIdFixture = new(); + private readonly LanguageInfoFixture _languageInfoFixture = new(); + + [Fact] + public void Create_WhenCalledWithValidValues_ShouldCreateWorkWithAllPropertiesSet() + { + // Arrange + MusicBrainzId workId = _musicBrainzIdFixture.Create(value: Guid.Parse("f0e9c1a2-0000-0000-0000-000000000000")); + LanguageInfo language = _languageInfoFixture.Create(languageCode: "en", languageName: "English"); + + // Act + Result result = MusicWork.Create( + workId, + "Bohemian Rhapsody", + Optional.Some("Song"), + [language], + ["T1234567890"]); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(workId, result.Value.MusicBrainzWorkId); + Assert.Equal("Bohemian Rhapsody", result.Value.Title); + Assert.Equal(Optional.Some("Song"), result.Value.Type); + Assert.Equal([language], result.Value.Languages); + Assert.Equal(["T1234567890"], result.Value.Iswcs); + } + + [Fact] + public void Create_WhenTitleHasSurroundingWhitespace_ShouldTrimIt() + { + // Act + Result result = MusicWork.Create( + _musicBrainzIdFixture.Create(), + " Bohemian Rhapsody ", + Optional.None(), + [], + []); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("Bohemian Rhapsody", result.Value.Title); + } + + [Theory] + [InlineData(null)] // null work title + [InlineData("")] // empty work title + [InlineData(" ")] // whitespace work title + public void Create_WhenTitleIsNullOrWhitespace_ShouldReturnError(string? title) + { + // Act + Result result = MusicWork.Create( + _musicBrainzIdFixture.Create(), + title!, + Optional.None(), + [], + []); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(DomainErrors.Music.WorkTitleCannotBeEmpty, result.FirstError); + } + + [Fact] + public void Create_WhenOptionalAndCollectionValuesAreAbsent_ShouldCreateWorkWithoutThem() + { + // Act + Result result = MusicWork.Create( + _musicBrainzIdFixture.Create(), + "Bohemian Rhapsody", + Optional.None(), + [], + []); + + // Assert + Assert.False(result.IsFailure); + Assert.False(result.Value.Type.HasValue); + Assert.Empty(result.Value.Languages); + Assert.Empty(result.Value.Iswcs); + } + + [Fact] + public void Equals_WithSameValues_ShouldReturnTrue() + { + // Arrange + MusicWork firstWork = _musicWorkFixture.Create(); + + // Act + MusicWork secondWork = _musicWorkFixture.Create( + musicBrainzWorkId: firstWork.MusicBrainzWorkId, + title: firstWork.Title, + type: firstWork.Type, + languages: [.. firstWork.Languages], + iswcs: [.. firstWork.Iswcs]); + + // Assert + Assert.Equal(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentMusicBrainzWorkId_ShouldReturnFalse() + { + // Arrange + MusicWork firstWork = _musicWorkFixture.Create(musicBrainzWorkId: _musicBrainzIdFixture.Create(value: Guid.Parse("11111111-1111-1111-1111-111111111111"))); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(musicBrainzWorkId: _musicBrainzIdFixture.Create(value: Guid.Parse("22222222-2222-2222-2222-222222222222"))); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentTitle_ShouldReturnFalse() + { + // Arrange + MusicWork firstWork = _musicWorkFixture.Create(title: "Bohemian Rhapsody"); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(title: "Love of My Life"); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentType_ShouldReturnFalse() + { + // Arrange + MusicWork firstWork = _musicWorkFixture.Create(type: Optional.Some("Song")); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(type: Optional.Some("Instrumental")); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentLanguages_ShouldReturnFalse() + { + // Arrange + LanguageInfo english = _languageInfoFixture.Create(languageCode: "en", languageName: "English"); + LanguageInfo french = _languageInfoFixture.Create(languageCode: "fr", languageName: "French"); + MusicWork firstWork = _musicWorkFixture.Create(languages: [english]); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(languages: [french]); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentIswcs_ShouldReturnFalse() + { + // Arrange + MusicWork firstWork = _musicWorkFixture.Create(iswcs: ["T1234567890"]); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(iswcs: ["T0987654321"]); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } + + [Fact] + public void Equals_WithDifferentLanguageOrder_ShouldReturnFalse() + { + // Arrange + LanguageInfo english = _languageInfoFixture.Create(languageCode: "en", languageName: "English"); + LanguageInfo french = _languageInfoFixture.Create(languageCode: "fr", languageName: "French"); + MusicWork firstWork = _musicWorkFixture.Create(languages: [english, french]); + + // Act + MusicWork secondWork = _musicWorkFixture.Create(languages: [french, english]); + + // Assert + Assert.NotEqual(firstWork, secondWork); + } +}