mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +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
+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