mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds the music artist alias, area, and work value objects and their enumerations
This commit is contained in:
1 parent
bf8b49653d
commit
e20e244a04
12 files changed
+1389
No files matched your search
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the gender of a music artist, applicable only to artists that are persons or characters.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{ToString()}")]
|
||||
public enum MusicArtistGender
|
||||
{
|
||||
/// <summary>
|
||||
/// The artist identifies as male.
|
||||
/// </summary>
|
||||
Male,
|
||||
|
||||
/// <summary>
|
||||
/// The artist identifies as female.
|
||||
/// </summary>
|
||||
Female,
|
||||
|
||||
/// <summary>
|
||||
/// The artist identifies with a gender other than male or female.
|
||||
/// </summary>
|
||||
Other,
|
||||
|
||||
/// <summary>
|
||||
/// The gender of the artist is not applicable, or is deliberately not stated.
|
||||
/// </summary>
|
||||
NotApplicable
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the type of a music artist, describing whether the artist is an individual, an ensemble, or something else.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{ToString()}")]
|
||||
public enum MusicArtistType
|
||||
{
|
||||
/// <summary>
|
||||
/// The artist is an individual person.
|
||||
/// </summary>
|
||||
Person,
|
||||
|
||||
/// <summary>
|
||||
/// The artist is a group of people that may or may not have a distinctive name.
|
||||
/// </summary>
|
||||
Group,
|
||||
|
||||
/// <summary>
|
||||
/// The artist is an orchestra, a large instrumental ensemble.
|
||||
/// </summary>
|
||||
Orchestra,
|
||||
|
||||
/// <summary>
|
||||
/// The artist is a choir or chorus, a large vocal ensemble.
|
||||
/// </summary>
|
||||
Choir,
|
||||
|
||||
/// <summary>
|
||||
/// The artist is an individual fictional character.
|
||||
/// </summary>
|
||||
Character,
|
||||
|
||||
/// <summary>
|
||||
/// The type of the artist does not fit into any of the known categories.
|
||||
/// </summary>
|
||||
Other
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the outermost physical packaging of a music release.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{ToString()}")]
|
||||
public enum MusicReleasePackaging
|
||||
{
|
||||
/// <summary>
|
||||
/// The release is a book with a sleeve containing a medium, usually a compact disc.
|
||||
/// </summary>
|
||||
Book,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a box with a lid or an opening that contains the medium and other packaging, like posters and a booklet.
|
||||
/// </summary>
|
||||
Box,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a sleeve made of paper, paperboard, or cardboard.
|
||||
/// </summary>
|
||||
CardboardPaperSleeve,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a regular plastic case for a cassette.
|
||||
/// </summary>
|
||||
CassetteCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a minimalistic plastic case where the back and the front are kept together by a small hinge.
|
||||
/// </summary>
|
||||
ClamshellCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a bounded booklet, usually in hardcover, with a sleeve bound to its spine that houses a compact disc.
|
||||
/// </summary>
|
||||
Digibook,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a folded cardboard compact disc packaging that has a small pocket on one side for the disc.
|
||||
/// </summary>
|
||||
Digifile,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a folded case, typically made of coated paperboard, with one or more plastic trays glued into it.
|
||||
/// </summary>
|
||||
Digipak,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a pouch-like package with an internal mechanism that pushes the contents out when the lid flap is opened.
|
||||
/// </summary>
|
||||
DiscboxSlider,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a double-sided, double-width jewel case normally holding two to four compact discs.
|
||||
/// </summary>
|
||||
Fatbox,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a cardboard sleeve that folds in halves, thirds, or more, and can hold multiple records, compact discs, booklets, or posters.
|
||||
/// </summary>
|
||||
GatefoldCover,
|
||||
|
||||
/// <summary>
|
||||
/// The release is the traditional compact disc case, made of hard, brittle plastic.
|
||||
/// </summary>
|
||||
JewelCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is the traditional DVD case, made of soft plastic with a thin transparent cover protecting the artwork.
|
||||
/// </summary>
|
||||
KeepCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a large cardboard box, often used to sell compact discs in North America so that they would fit vinyl racks.
|
||||
/// </summary>
|
||||
Longbox,
|
||||
|
||||
/// <summary>
|
||||
/// The release is an often decorated metal tin containing one or more compact discs.
|
||||
/// </summary>
|
||||
MetalTin,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a sleeve made entirely of plastic that holds the medium and the other parts of the album.
|
||||
/// </summary>
|
||||
PlasticSleeve,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a box with openings at its two ends that contains a tray holding the medium.
|
||||
/// </summary>
|
||||
Slidepack,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a thinner jewel case, commonly used for compact disc singles.
|
||||
/// </summary>
|
||||
SlimJewelCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a four or five-sided box that surrounds a second inner package such as a jewel case.
|
||||
/// </summary>
|
||||
Slipcase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a digipak-like case held together with a snapping plastic closure.
|
||||
/// </summary>
|
||||
SnapCase,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a cardboard jacket, commonly used for 8cm compact disc singles in Japan.
|
||||
/// </summary>
|
||||
SnapPack,
|
||||
|
||||
/// <summary>
|
||||
/// The release is a case similar to the regular jewel case, but with rounded corners and a latch closing mechanism.
|
||||
/// </summary>
|
||||
SuperJewelBox,
|
||||
|
||||
/// <summary>
|
||||
/// The packaging of the release does not fit into any of the known categories.
|
||||
/// </summary>
|
||||
Other,
|
||||
|
||||
/// <summary>
|
||||
/// The release has no packaging at all, which is common for digital media.
|
||||
/// </summary>
|
||||
None
|
||||
}
|
||||
+111
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for a MusicBrainz area, the geographic area a music artist is associated with.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public sealed class MusicArea : ValueObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MusicBrainz identifier of the area.
|
||||
/// </summary>
|
||||
public MusicBrainzId MusicBrainzAreaId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the area.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional sort name of the area.
|
||||
/// </summary>
|
||||
public Optional<string> SortName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional disambiguation comment of the area.
|
||||
/// </summary>
|
||||
public Optional<string> Disambiguation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional MusicBrainz type of the area (e.g., Country, City).
|
||||
/// </summary>
|
||||
public Optional<string> Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional ISO 3166 code of the area.
|
||||
/// </summary>
|
||||
public Optional<string> Iso3166Code { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicArea"/> class.
|
||||
/// </summary>
|
||||
/// <param name="musicBrainzAreaId">The MusicBrainz identifier of the area.</param>
|
||||
/// <param name="name">The name of the area.</param>
|
||||
/// <param name="sortName">The optional sort name of the area.</param>
|
||||
/// <param name="disambiguation">The optional disambiguation comment of the area.</param>
|
||||
/// <param name="type">The optional MusicBrainz type of the area.</param>
|
||||
/// <param name="iso3166Code">The optional ISO 3166 code of the area.</param>
|
||||
private MusicArea(
|
||||
MusicBrainzId musicBrainzAreaId,
|
||||
string name,
|
||||
Optional<string> sortName,
|
||||
Optional<string> disambiguation,
|
||||
Optional<string> type,
|
||||
Optional<string> iso3166Code)
|
||||
{
|
||||
MusicBrainzAreaId = musicBrainzAreaId;
|
||||
Name = name;
|
||||
SortName = sortName;
|
||||
Disambiguation = disambiguation;
|
||||
Type = type;
|
||||
Iso3166Code = iso3166Code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MusicArea"/> class.
|
||||
/// </summary>
|
||||
/// <param name="musicBrainzAreaId">The MusicBrainz identifier of the area.</param>
|
||||
/// <param name="name">The name of the area.</param>
|
||||
/// <param name="sortName">The optional sort name of the area.</param>
|
||||
/// <param name="disambiguation">The optional disambiguation comment of the area.</param>
|
||||
/// <param name="type">The optional MusicBrainz type of the area.</param>
|
||||
/// <param name="iso3166Code">The optional ISO 3166 code of the area.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MusicArea"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArea> Create(
|
||||
MusicBrainzId musicBrainzAreaId,
|
||||
string name,
|
||||
Optional<string> sortName,
|
||||
Optional<string> disambiguation,
|
||||
Optional<string> type,
|
||||
Optional<string> iso3166Code)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Music.AreaNameCannotBeEmpty;
|
||||
|
||||
return new MusicArea(musicBrainzAreaId, name.Trim(), sortName, disambiguation, type, iso3166Code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return MusicBrainzAreaId;
|
||||
yield return Name;
|
||||
yield return SortName;
|
||||
yield return Disambiguation;
|
||||
yield return Type;
|
||||
yield return Iso3166Code;
|
||||
}
|
||||
}
|
||||
+134
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for an alternative name of a music artist.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public sealed class MusicArtistAlias : ValueObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the alias.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional sort name of the alias.
|
||||
/// </summary>
|
||||
public Optional<string> SortName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional type of the alias (e.g., Artist name, Search hint).
|
||||
/// </summary>
|
||||
public Optional<string> Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional locale the alias is used in.
|
||||
/// </summary>
|
||||
public Optional<string> Locale { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this is the primary alias of the artist.
|
||||
/// </summary>
|
||||
public bool IsPrimary { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional date the alias began being used.
|
||||
/// </summary>
|
||||
public Optional<DateOnly> BeginDate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional date the alias stopped being used.
|
||||
/// </summary>
|
||||
public Optional<DateOnly> EndDate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the alias is no longer used.
|
||||
/// </summary>
|
||||
public bool IsEnded { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicArtistAlias"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the alias.</param>
|
||||
/// <param name="sortName">The optional sort name of the alias.</param>
|
||||
/// <param name="type">The optional type of the alias.</param>
|
||||
/// <param name="locale">The optional locale the alias is used in.</param>
|
||||
/// <param name="isPrimary">Whether this is the primary alias of the artist.</param>
|
||||
/// <param name="beginDate">The optional date the alias began being used.</param>
|
||||
/// <param name="endDate">The optional date the alias stopped being used.</param>
|
||||
/// <param name="isEnded">Whether the alias is no longer used.</param>
|
||||
private MusicArtistAlias(
|
||||
string name,
|
||||
Optional<string> sortName,
|
||||
Optional<string> type,
|
||||
Optional<string> locale,
|
||||
bool isPrimary,
|
||||
Optional<DateOnly> beginDate,
|
||||
Optional<DateOnly> endDate,
|
||||
bool isEnded)
|
||||
{
|
||||
Name = name;
|
||||
SortName = sortName;
|
||||
Type = type;
|
||||
Locale = locale;
|
||||
IsPrimary = isPrimary;
|
||||
BeginDate = beginDate;
|
||||
EndDate = endDate;
|
||||
IsEnded = isEnded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MusicArtistAlias"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the alias.</param>
|
||||
/// <param name="sortName">The optional sort name of the alias.</param>
|
||||
/// <param name="type">The optional type of the alias.</param>
|
||||
/// <param name="locale">The optional locale the alias is used in.</param>
|
||||
/// <param name="isPrimary">Whether this is the primary alias of the artist.</param>
|
||||
/// <param name="beginDate">The optional date the alias began being used.</param>
|
||||
/// <param name="endDate">The optional date the alias stopped being used.</param>
|
||||
/// <param name="isEnded">Whether the alias is no longer used.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MusicArtistAlias"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArtistAlias> Create(
|
||||
string name,
|
||||
Optional<string> sortName,
|
||||
Optional<string> type,
|
||||
Optional<string> locale,
|
||||
bool isPrimary,
|
||||
Optional<DateOnly> beginDate,
|
||||
Optional<DateOnly> endDate,
|
||||
bool isEnded)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Music.ArtistAliasNameCannotBeEmpty;
|
||||
|
||||
return new MusicArtistAlias(name.Trim(), sortName, type, locale, isPrimary, beginDate, endDate, isEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> 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;
|
||||
}
|
||||
}
|
||||
+106
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for a MusicBrainz work, the musical composition a track is a recording of.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Title}")]
|
||||
public sealed class MusicWork : ValueObject
|
||||
{
|
||||
private readonly List<LanguageInfo> _languages;
|
||||
private readonly List<string> _iswcs;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MusicBrainz identifier of the work.
|
||||
/// </summary>
|
||||
public MusicBrainzId MusicBrainzWorkId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the work.
|
||||
/// </summary>
|
||||
public string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional MusicBrainz type of the work (e.g., Song).
|
||||
/// </summary>
|
||||
public Optional<string> Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of languages of the work.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<LanguageInfo> Languages => _languages.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of ISWC (International Standard Musical Work Code) of the work.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> Iswcs => _iswcs.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicWork"/> class.
|
||||
/// </summary>
|
||||
/// <param name="musicBrainzWorkId">The MusicBrainz identifier of the work.</param>
|
||||
/// <param name="title">The title of the work.</param>
|
||||
/// <param name="type">The optional MusicBrainz type of the work.</param>
|
||||
/// <param name="languages">The list of languages of the work.</param>
|
||||
/// <param name="iswcs">The list of ISWC of the work.</param>
|
||||
private MusicWork(
|
||||
MusicBrainzId musicBrainzWorkId,
|
||||
string title,
|
||||
Optional<string> type,
|
||||
List<LanguageInfo> languages,
|
||||
List<string> iswcs)
|
||||
{
|
||||
MusicBrainzWorkId = musicBrainzWorkId;
|
||||
Title = title;
|
||||
Type = type;
|
||||
_languages = languages;
|
||||
_iswcs = iswcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MusicWork"/> class.
|
||||
/// </summary>
|
||||
/// <param name="musicBrainzWorkId">The MusicBrainz identifier of the work.</param>
|
||||
/// <param name="title">The title of the work.</param>
|
||||
/// <param name="type">The optional MusicBrainz type of the work.</param>
|
||||
/// <param name="languages">The list of languages of the work.</param>
|
||||
/// <param name="iswcs">The list of ISWC of the work.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MusicWork"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicWork> Create(
|
||||
MusicBrainzId musicBrainzWorkId,
|
||||
string title,
|
||||
Optional<string> type,
|
||||
List<LanguageInfo> languages,
|
||||
List<string> iswcs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
return Errors.Music.WorkTitleCannotBeEmpty;
|
||||
|
||||
return new MusicWork(musicBrainzWorkId, title.Trim(), type, languages, iswcs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> 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;
|
||||
}
|
||||
}
|
||||
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+72
@@ -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())];
|
||||
}
|
||||
}
|
||||
+61
@@ -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())];
|
||||
}
|
||||
}
|
||||
+199
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicArea"/> class.
|
||||
/// </summary>
|
||||
[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<MusicArea> result = MusicArea.Create(
|
||||
areaId,
|
||||
"United Kingdom",
|
||||
Optional<string>.Some("UK"),
|
||||
Optional<string>.Some("The United Kingdom of Great Britain and Northern Ireland"),
|
||||
Optional<string>.Some("Country"),
|
||||
Optional<string>.Some("GB"));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(areaId, result.Value.MusicBrainzAreaId);
|
||||
Assert.Equal("United Kingdom", result.Value.Name);
|
||||
Assert.Equal(Optional<string>.Some("UK"), result.Value.SortName);
|
||||
Assert.Equal(Optional<string>.Some("The United Kingdom of Great Britain and Northern Ireland"), result.Value.Disambiguation);
|
||||
Assert.Equal(Optional<string>.Some("Country"), result.Value.Type);
|
||||
Assert.Equal(Optional<string>.Some("GB"), result.Value.Iso3166Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenNameHasSurroundingWhitespace_ShouldTrimIt()
|
||||
{
|
||||
// Act
|
||||
Result<MusicArea> result = MusicArea.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
" United Kingdom ",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.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<MusicArea> result = MusicArea.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
name!,
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Music.AreaNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenOptionalValuesAreAbsent_ShouldCreateMusicAreaWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<MusicArea> result = MusicArea.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
"United Kingdom",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.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<string>.Some("UK"));
|
||||
|
||||
// Act
|
||||
MusicArea secondArea = _musicAreaFixture.Create(sortName: Optional<string>.Some("GB"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstArea, secondArea);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentDisambiguation_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArea firstArea = _musicAreaFixture.Create(disambiguation: Optional<string>.Some("The country"));
|
||||
|
||||
// Act
|
||||
MusicArea secondArea = _musicAreaFixture.Create(disambiguation: Optional<string>.Some("The region"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstArea, secondArea);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentType_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArea firstArea = _musicAreaFixture.Create(type: Optional<string>.Some("Country"));
|
||||
|
||||
// Act
|
||||
MusicArea secondArea = _musicAreaFixture.Create(type: Optional<string>.Some("City"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstArea, secondArea);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentIso3166Code_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArea firstArea = _musicAreaFixture.Create(iso3166Code: Optional<string>.Some("GB"));
|
||||
|
||||
// Act
|
||||
MusicArea secondArea = _musicAreaFixture.Create(iso3166Code: Optional<string>.Some("FR"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstArea, secondArea);
|
||||
}
|
||||
}
|
||||
+238
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicArtistAlias"/> class.
|
||||
/// </summary>
|
||||
[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<MusicArtistAlias> result = MusicArtistAlias.Create(
|
||||
"Freddie Mercury",
|
||||
Optional<string>.Some("Mercury, Freddie"),
|
||||
Optional<string>.Some("Artist name"),
|
||||
Optional<string>.Some("en"),
|
||||
isPrimary: true,
|
||||
Optional<DateOnly>.Some(beginDate),
|
||||
Optional<DateOnly>.Some(endDate),
|
||||
isEnded: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Freddie Mercury", result.Value.Name);
|
||||
Assert.Equal(Optional<string>.Some("Mercury, Freddie"), result.Value.SortName);
|
||||
Assert.Equal(Optional<string>.Some("Artist name"), result.Value.Type);
|
||||
Assert.Equal(Optional<string>.Some("en"), result.Value.Locale);
|
||||
Assert.True(result.Value.IsPrimary);
|
||||
Assert.Equal(Optional<DateOnly>.Some(beginDate), result.Value.BeginDate);
|
||||
Assert.Equal(Optional<DateOnly>.Some(endDate), result.Value.EndDate);
|
||||
Assert.True(result.Value.IsEnded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenNameHasSurroundingWhitespace_ShouldTrimIt()
|
||||
{
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = MusicArtistAlias.Create(
|
||||
" Freddie Mercury ",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
isPrimary: false,
|
||||
Optional<DateOnly>.None(),
|
||||
Optional<DateOnly>.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<MusicArtistAlias> result = MusicArtistAlias.Create(
|
||||
name!,
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
isPrimary: false,
|
||||
Optional<DateOnly>.None(),
|
||||
Optional<DateOnly>.None(),
|
||||
isEnded: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenOptionalValuesAreAbsent_ShouldCreateAliasWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = MusicArtistAlias.Create(
|
||||
"Freddie Mercury",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
isPrimary: false,
|
||||
Optional<DateOnly>.None(),
|
||||
Optional<DateOnly>.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<string>.Some("Mercury, Freddie"));
|
||||
|
||||
// Act
|
||||
MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(sortName: Optional<string>.Some("Bulsara, Farrokh"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstAlias, secondAlias);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentType_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(type: Optional<string>.Some("Artist name"));
|
||||
|
||||
// Act
|
||||
MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(type: Optional<string>.Some("Search hint"));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstAlias, secondAlias);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentLocale_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(locale: Optional<string>.Some("en"));
|
||||
|
||||
// Act
|
||||
MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(locale: Optional<string>.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<DateOnly>.Some(new DateOnly(1970, 1, 1)));
|
||||
|
||||
// Act
|
||||
MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(beginDate: Optional<DateOnly>.Some(new DateOnly(1980, 1, 1)));
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstAlias, secondAlias);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentEndDate_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAlias firstAlias = _musicArtistAliasFixture.Create(endDate: Optional<DateOnly>.Some(new DateOnly(1991, 1, 1)));
|
||||
|
||||
// Act
|
||||
MusicArtistAlias secondAlias = _musicArtistAliasFixture.Create(endDate: Optional<DateOnly>.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);
|
||||
}
|
||||
}
|
||||
+201
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicWork"/> class.
|
||||
/// </summary>
|
||||
[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<MusicWork> result = MusicWork.Create(
|
||||
workId,
|
||||
"Bohemian Rhapsody",
|
||||
Optional<string>.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<string>.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<MusicWork> result = MusicWork.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
" Bohemian Rhapsody ",
|
||||
Optional<string>.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<MusicWork> result = MusicWork.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
title!,
|
||||
Optional<string>.None(),
|
||||
[],
|
||||
[]);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Music.WorkTitleCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenOptionalAndCollectionValuesAreAbsent_ShouldCreateWorkWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<MusicWork> result = MusicWork.Create(
|
||||
_musicBrainzIdFixture.Create(),
|
||||
"Bohemian Rhapsody",
|
||||
Optional<string>.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<string>.Some("Song"));
|
||||
|
||||
// Act
|
||||
MusicWork secondWork = _musicWorkFixture.Create(type: Optional<string>.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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user