mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds the music library application mappings and renames the value object conversion methods
This commit is contained in:
1 parent
a939d8fd5f
commit
4f0526faa4
98 files changed
+2869
-610
No files matched your search
@@ -20,7 +20,7 @@ public static class GenreDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Genre> ToDomainEntity(this GenreDto dto)
|
||||
public static Result<Genre> ToDomainValueObject(this GenreDto dto)
|
||||
{
|
||||
return Genre.Create(
|
||||
dto.Name!
|
||||
@@ -34,8 +34,8 @@ public static class GenreDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
|
||||
public static IEnumerable<Result<Genre>> ToDomainValueObjects(this IEnumerable<GenreDto> dtos)
|
||||
{
|
||||
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public static class GenreEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
|
||||
public static Result<Genre> ToDomainValueObject(this GenreEntity repositoryEntity)
|
||||
{
|
||||
return Genre.Create(
|
||||
repositoryEntity.Name!
|
||||
@@ -57,8 +57,8 @@ public static class GenreEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Genre>> ToDomainValueObjects(this IEnumerable<GenreEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class LanguageInfoDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="LanguageInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<LanguageInfo> ToDomainEntity(this LanguageInfoDto dto)
|
||||
public static Result<LanguageInfo> ToDomainValueObject(this LanguageInfoDto dto)
|
||||
{
|
||||
return LanguageInfo.Create(
|
||||
dto.LanguageCode!,
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class ReleaseInfoDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<ReleaseInfo> ToDomainEntity(this ReleaseInfoDto dto)
|
||||
public static Result<ReleaseInfo> ToDomainValueObject(this ReleaseInfoDto dto)
|
||||
{
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(dto.OriginalReleaseDate),
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class TagDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Tag> ToDomainEntity(this TagDto dto)
|
||||
public static Result<Tag> ToDomainValueObject(this TagDto dto)
|
||||
{
|
||||
return Tag.Create(
|
||||
dto.Name!
|
||||
@@ -34,8 +34,8 @@ public static class TagDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
|
||||
public static IEnumerable<Result<Tag>> ToDomainValueObjects(this IEnumerable<TagDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public static class TagEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Tag> ToDomainEntity(this TagEntity repositoryEntity)
|
||||
public static Result<Tag> ToDomainValueObject(this TagEntity repositoryEntity)
|
||||
{
|
||||
return Tag.Create(
|
||||
repositoryEntity.Name!
|
||||
@@ -57,8 +57,8 @@ public static class TagEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Tag>> ToDomainValueObjects(this IEnumerable<TagEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+17
-6
@@ -3,7 +3,7 @@ using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
@@ -30,16 +30,17 @@ public static class AddAlbumCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Album> ToDomainEntity(this AddAlbumCommand command)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicAlbumMetadataDto metadata = command.Metadata!;
|
||||
Result<AlbumMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -78,9 +79,14 @@ public static class AddAlbumCommandMapping
|
||||
return Album.Create(
|
||||
AlbumId.Create(command.AlbumId.Value),
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
@@ -92,9 +98,14 @@ public static class AddAlbumCommandMapping
|
||||
|
||||
return Album.Create(
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
|
||||
+4
-1
@@ -27,8 +27,11 @@ public static class AddAlbumRequestMapping
|
||||
artistId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+23
-13
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
@@ -16,10 +18,6 @@ using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
@@ -49,7 +47,7 @@ public static class AlbumEntityMapping
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainEntities())
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
@@ -57,7 +55,7 @@ public static class AlbumEntityMapping
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainEntities())
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
@@ -75,13 +73,14 @@ public static class AlbumEntityMapping
|
||||
Result<AlbumMetadata> metadataResult = AlbumMetadata.Create(
|
||||
repositoryEntity.Title,
|
||||
Optional<string>.FromNullable(repositoryEntity.OriginalTitle),
|
||||
Optional<string>.FromNullable(repositoryEntity.ReleaseTitle),
|
||||
Optional<string>.FromNullable(repositoryEntity.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<MusicReleaseType>.FromNullable(repositoryEntity.ReleaseType),
|
||||
[.. repositoryEntity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType)],
|
||||
Optional<MusicReleaseStatus>.FromNullable(repositoryEntity.ReleaseStatus),
|
||||
Optional<int>.FromNullable(repositoryEntity.TotalDiscs),
|
||||
repositoryEntity.TotalTracks);
|
||||
@@ -108,7 +107,7 @@ public static class AlbumEntityMapping
|
||||
musicBrainzReleaseArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseArtistId.Value);
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
@@ -136,9 +135,14 @@ public static class AlbumEntityMapping
|
||||
return Album.Create(
|
||||
AlbumId.Create(repositoryEntity.Id),
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(repositoryEntity.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(repositoryEntity.Packaging),
|
||||
Optional<string>.FromNullable(repositoryEntity.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(repositoryEntity.CatalogNumber),
|
||||
[.. repositoryEntity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber)],
|
||||
Optional<string>.FromNullable(repositoryEntity.Label),
|
||||
Optional<string>.FromNullable(repositoryEntity.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
@@ -181,19 +185,22 @@ public static class AlbumEntityMapping
|
||||
repositoryEntity.OriginalLanguageName,
|
||||
repositoryEntity.OriginalLanguageNativeName
|
||||
) : null;
|
||||
AlbumMetadataDto metadata = new(
|
||||
MusicAlbumMetadataDto metadata = new(
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.OriginalTitle,
|
||||
repositoryEntity.Description,
|
||||
repositoryEntity.Disambiguation,
|
||||
releaseInfo,
|
||||
languageInfo,
|
||||
originalLanguageInfo,
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
repositoryEntity.ReleaseType,
|
||||
repositoryEntity.Script,
|
||||
[.. repositoryEntity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType)],
|
||||
repositoryEntity.ReleaseStatus,
|
||||
repositoryEntity.TotalDiscs,
|
||||
repositoryEntity.TotalTracks
|
||||
repositoryEntity.TotalTracks,
|
||||
repositoryEntity.ReleaseTitle
|
||||
);
|
||||
return new AlbumResponse(
|
||||
repositoryEntity.Id,
|
||||
@@ -201,8 +208,11 @@ public static class AlbumEntityMapping
|
||||
repositoryEntity.LibraryId,
|
||||
metadata,
|
||||
repositoryEntity.MediaFormat,
|
||||
repositoryEntity.Packaging,
|
||||
repositoryEntity.Barcode,
|
||||
repositoryEntity.CatalogNumber,
|
||||
repositoryEntity.CatalogNumbers.Count > 0 ? [.. repositoryEntity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber)] : null,
|
||||
repositoryEntity.Label,
|
||||
repositoryEntity.ASIN,
|
||||
repositoryEntity.MusicBrainzReleaseId,
|
||||
repositoryEntity.MusicBrainzReleaseGroupId,
|
||||
repositoryEntity.MusicBrainzReleaseArtistId,
|
||||
|
||||
+8
-2
@@ -33,7 +33,9 @@ public static class AlbumMapping
|
||||
LibraryId = libraryId,
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
ReleaseTitle = domainEntity.Metadata.ReleaseTitle.HasValue ? domainEntity.Metadata.ReleaseTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
OriginalReleaseDate = domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null,
|
||||
OriginalReleaseYear = domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null,
|
||||
ReReleaseDate = domainEntity.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseDate.Value : null,
|
||||
@@ -46,15 +48,19 @@ public static class AlbumMapping
|
||||
OriginalLanguageCode = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageCode : null,
|
||||
OriginalLanguageName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageName : null,
|
||||
OriginalLanguageNativeName = domainEntity.Metadata.OriginalLanguage.HasValue && domainEntity.Metadata.OriginalLanguage.Value.NativeName.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.NativeName.Value : null,
|
||||
Script = domainEntity.Script.HasValue ? domainEntity.Script.Value : null,
|
||||
Genres = [.. domainEntity.Metadata.Genres.ToRepositoryEntities()],
|
||||
Tags = [.. domainEntity.Metadata.Tags.ToRepositoryEntities()],
|
||||
ReleaseType = domainEntity.Metadata.ReleaseType.HasValue ? domainEntity.Metadata.ReleaseType.Value : null,
|
||||
ReleaseTypes = [.. domainEntity.Metadata.ReleaseTypes.Select(releaseType => new AlbumReleaseTypeEntity(releaseType))],
|
||||
ReleaseStatus = domainEntity.Metadata.ReleaseStatus.HasValue ? domainEntity.Metadata.ReleaseStatus.Value : null,
|
||||
TotalDiscs = domainEntity.Metadata.TotalDiscs.HasValue ? domainEntity.Metadata.TotalDiscs.Value : null,
|
||||
TotalTracks = domainEntity.Metadata.TotalTracks,
|
||||
MediaFormat = domainEntity.MediaFormat.HasValue ? domainEntity.MediaFormat.Value : null,
|
||||
Packaging = domainEntity.Packaging.HasValue ? domainEntity.Packaging.Value : null,
|
||||
Barcode = domainEntity.Barcode.HasValue ? domainEntity.Barcode.Value.Value : null,
|
||||
CatalogNumber = domainEntity.CatalogNumber.HasValue ? domainEntity.CatalogNumber.Value : null,
|
||||
CatalogNumbers = [.. domainEntity.CatalogNumbers.Select(catalogNumber => new AlbumCatalogNumberEntity(catalogNumber))],
|
||||
Label = domainEntity.Label.HasValue ? domainEntity.Label.Value : null,
|
||||
ASIN = domainEntity.ASIN.HasValue ? domainEntity.ASIN.Value : null,
|
||||
MusicBrainzReleaseId = domainEntity.MusicBrainzReleaseId.HasValue ? domainEntity.MusicBrainzReleaseId.Value.Value : null,
|
||||
MusicBrainzReleaseGroupId = domainEntity.MusicBrainzReleaseGroupId.HasValue ? domainEntity.MusicBrainzReleaseGroupId.Value.Value : null,
|
||||
MusicBrainzReleaseArtistId = domainEntity.MusicBrainzReleaseArtistId.HasValue ? domainEntity.MusicBrainzReleaseArtistId.Value.Value : null,
|
||||
|
||||
+106
-16
@@ -1,9 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
@@ -18,42 +23,126 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
/// </summary>
|
||||
public static class AlbumMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="album"/>, through the owning <paramref name="artist"/> aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The album metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the album.</param>
|
||||
/// <param name="album">The album entity to update.</param>
|
||||
/// <param name="contributors">The media contributors of the album, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this AlbumMetadataDto dto, Artist artist, Album album, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = dto.ToDomainValueObject(album.Metadata.ReleaseInfo);
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
Optional<Barcode> barcode = Optional<Barcode>.None();
|
||||
if (!string.IsNullOrWhiteSpace(dto.Barcode))
|
||||
{
|
||||
Result<Barcode> barcodeResult = Barcode.Create(dto.Barcode);
|
||||
if (barcodeResult.IsFailure)
|
||||
return barcodeResult.Errors;
|
||||
barcode = barcodeResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzReleaseId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseId is not null)
|
||||
musicBrainzReleaseId = MusicBrainzId.Create(dto.MusicBrainzReleaseId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzReleaseGroupId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseGroupId is not null)
|
||||
musicBrainzReleaseGroupId = MusicBrainzId.Create(dto.MusicBrainzReleaseGroupId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzReleaseArtistId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseArtistId is not null)
|
||||
musicBrainzReleaseArtistId = MusicBrainzId.Create(dto.MusicBrainzReleaseArtistId.Value);
|
||||
|
||||
return artist.UpdateAlbum(
|
||||
album,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(dto.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(dto.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(dto.Packaging),
|
||||
Optional<string>.FromNullable(dto.Script),
|
||||
barcode,
|
||||
dto.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(dto.Label),
|
||||
Optional<string>.FromNullable(dto.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AlbumMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <param name="existingReleaseInfo">The release information already stored for the album, used as a fallback for the fields the metadata does not provide.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AlbumMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AlbumMetadata> ToDomainEntity(this AlbumMetadataDto dto)
|
||||
private static Result<AlbumMetadata> ToDomainValueObject(this AlbumMetadataDto dto, ReleaseInfo existingReleaseInfo)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
|
||||
// The enrichment must not erase a release date that the tags already provided, so a date that the metadata does not carry falls back to the stored one.
|
||||
DateOnly? originalReleaseDate = releaseInfoDto?.OriginalReleaseDate;
|
||||
int? originalReleaseYear = releaseInfoDto?.OriginalReleaseYear;
|
||||
if (originalReleaseDate is null && originalReleaseYear is null)
|
||||
{
|
||||
originalReleaseDate = existingReleaseInfo.OriginalReleaseDate.HasValue ? existingReleaseInfo.OriginalReleaseDate.Value : null;
|
||||
originalReleaseYear = existingReleaseInfo.OriginalReleaseYear.HasValue ? existingReleaseInfo.OriginalReleaseYear.Value : null;
|
||||
}
|
||||
|
||||
DateOnly? reReleaseDate = releaseInfoDto?.ReReleaseDate;
|
||||
int? reReleaseYear = releaseInfoDto?.ReReleaseYear;
|
||||
if (reReleaseDate is null && reReleaseYear is null)
|
||||
{
|
||||
reReleaseDate = existingReleaseInfo.ReReleaseDate.HasValue ? existingReleaseInfo.ReReleaseDate.Value : null;
|
||||
reReleaseYear = existingReleaseInfo.ReReleaseYear.HasValue ? existingReleaseInfo.ReReleaseYear.Value : null;
|
||||
}
|
||||
|
||||
ReleaseCountry? releaseCountry = releaseInfoDto?.ReleaseCountry ?? (existingReleaseInfo.ReleaseCountry.HasValue ? existingReleaseInfo.ReleaseCountry.Value : null);
|
||||
string? releaseVersion = releaseInfoDto?.ReleaseVersion ?? (existingReleaseInfo.ReleaseVersion.HasValue ? existingReleaseInfo.ReleaseVersion.Value : null);
|
||||
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
Optional<DateOnly>.FromNullable(originalReleaseDate),
|
||||
Optional<int>.FromNullable(originalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(reReleaseDate),
|
||||
Optional<int>.FromNullable(reReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseCountry),
|
||||
Optional<string>.FromNullable(releaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
List<Genre> genres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainEntity();
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
List<Tag> tags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainEntity();
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
@@ -67,13 +156,14 @@ public static class AlbumMetadataDtoMapping
|
||||
return AlbumMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
Optional<string>.FromNullable(dto.ReleaseTitle),
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
genres,
|
||||
tags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<MusicReleaseType>.FromNullable(dto.ReleaseType),
|
||||
dto.ReleaseTypes is null ? [] : [.. dto.ReleaseTypes],
|
||||
Optional<MusicReleaseStatus>.FromNullable(dto.ReleaseStatus),
|
||||
Optional<int>.FromNullable(dto.TotalDiscs),
|
||||
dto.TotalTracks ?? 0);
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAlbumMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicAlbumMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AlbumMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AlbumMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AlbumMetadata> ToDomainValueObject(this MusicAlbumMetadataDto dto)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AlbumMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
Optional<string>.FromNullable(dto.ReleaseTitle),
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
dto.ReleaseTypes is null ? [] : [.. dto.ReleaseTypes],
|
||||
Optional<MusicReleaseStatus>.FromNullable(dto.ReleaseStatus),
|
||||
Optional<int>.FromNullable(dto.TotalDiscs),
|
||||
dto.TotalTracks ?? 0);
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.UpdateAlbum;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
@@ -31,16 +32,17 @@ public static class UpdateAlbumCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateAlbumCommand command, Artist artist)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicAlbumMetadataDto metadata = command.Metadata!;
|
||||
Result<AlbumMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -72,9 +74,14 @@ public static class UpdateAlbumCommandMapping
|
||||
Result<Updated> updateResult = artist.UpdateAlbum(
|
||||
album,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
|
||||
+4
-1
@@ -26,8 +26,11 @@ public static class UpdateAlbumRequestMapping
|
||||
albumId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+57
-4
@@ -1,12 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.AddArtist;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -29,8 +35,10 @@ public static class AddArtistCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this AddArtistCommand command, Guid libraryId)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = command.Metadata!;
|
||||
|
||||
// Map the media contributors referenced by the user to their domain counterparts; a contributor is identified by its id and carries the role it played.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -41,16 +49,61 @@ public static class AddArtistCommandMapping
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
IEnumerable<Result<Genre>> domainGenresResult = (metadata.Genres ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = (metadata.Tags ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<Optional<MusicArea>> areaResult = metadata.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = metadata.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = metadata.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
|
||||
Result<List<MusicArtistAlias>> aliasesResult = metadata.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
return Artist.Create(
|
||||
LibraryId.Create(libraryId),
|
||||
command.Name!,
|
||||
website,
|
||||
metadata.Name!,
|
||||
Optional<string>.FromNullable(metadata.SortName),
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(metadata.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(metadata.Gender),
|
||||
Optional<string>.FromNullable(metadata.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanEnd),
|
||||
metadata.IsEnded,
|
||||
Optional<string>.FromNullable(command.Website),
|
||||
musicBrainzArtistId,
|
||||
[.. (command.Ipis ?? [])],
|
||||
[.. (command.Isnis ?? [])],
|
||||
aliasesResult.Value,
|
||||
[.. domainGenresResult.Select(genreResult => genreResult.Value)],
|
||||
[.. domainTagsResult.Select(tagResult => tagResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainAlbumsResult.Select(albumResult => albumResult.Value)]);
|
||||
}
|
||||
|
||||
+4
-1
@@ -22,10 +22,13 @@ public static class AddArtistRequestMapping
|
||||
{
|
||||
return new AddArtistCommand(
|
||||
libraryId,
|
||||
request.Name,
|
||||
request.Metadata,
|
||||
request.Website,
|
||||
request.MusicBrainzArtistId,
|
||||
request.Ipis,
|
||||
request.Isnis,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Albums?.ToCommands(libraryId, null).ToList());
|
||||
}
|
||||
}
|
||||
+100
-4
@@ -1,16 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -36,6 +42,60 @@ public static class ArtistEntityMapping
|
||||
if (repositoryEntity.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzArtistId.Value);
|
||||
|
||||
Optional<MusicArea> area = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.Area is not null)
|
||||
{
|
||||
Result<MusicArea> areaResult = repositoryEntity.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
area = areaResult.Value;
|
||||
}
|
||||
Optional<MusicArea> beginArea = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.BeginArea is not null)
|
||||
{
|
||||
Result<MusicArea> beginAreaResult = repositoryEntity.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
beginArea = beginAreaResult.Value;
|
||||
}
|
||||
Optional<MusicArea> endArea = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.EndArea is not null)
|
||||
{
|
||||
Result<MusicArea> endAreaResult = repositoryEntity.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
endArea = endAreaResult.Value;
|
||||
}
|
||||
|
||||
Result<List<MusicArtistAlias>> domainAliasesResult = repositoryEntity.Aliases.ToDomainValueObjects();
|
||||
if (domainAliasesResult.IsFailure)
|
||||
return domainAliasesResult.Errors;
|
||||
List<MusicArtistAlias> domainAliases = domainAliasesResult.Value;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
domainRatings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
List<MusicMediaContributor> domainContributors = [];
|
||||
foreach (ArtistContributorEntity contributorEntity in repositoryEntity.Contributors)
|
||||
{
|
||||
@@ -58,8 +118,25 @@ public static class ArtistEntityMapping
|
||||
ArtistId.Create(repositoryEntity.Id),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(repositoryEntity.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(repositoryEntity.Gender),
|
||||
Optional<string>.FromNullable(repositoryEntity.Country),
|
||||
area,
|
||||
beginArea,
|
||||
endArea,
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.LifeSpanEnd),
|
||||
repositoryEntity.IsEnded,
|
||||
Optional<string>.FromNullable(repositoryEntity.Website),
|
||||
musicBrainzArtistId,
|
||||
[.. repositoryEntity.Ipis.Select(ipi => ipi.Value)],
|
||||
[.. repositoryEntity.Isnis.Select(isni => isni.Value)],
|
||||
domainAliases,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
domainRatings,
|
||||
domainContributors,
|
||||
domainAlbums,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
@@ -73,16 +150,35 @@ public static class ArtistEntityMapping
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static ArtistResponse ToResponse(this ArtistEntity repositoryEntity)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = new(
|
||||
repositoryEntity.Name,
|
||||
repositoryEntity.SortName,
|
||||
repositoryEntity.Disambiguation,
|
||||
repositoryEntity.Type,
|
||||
repositoryEntity.Gender,
|
||||
repositoryEntity.Country,
|
||||
repositoryEntity.Area.ToResponse(),
|
||||
repositoryEntity.BeginArea.ToResponse(),
|
||||
repositoryEntity.EndArea.ToResponse(),
|
||||
repositoryEntity.LifeSpanBegin,
|
||||
repositoryEntity.LifeSpanEnd,
|
||||
repositoryEntity.IsEnded,
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Aliases.Select(alias => new MusicArtistAliasDto(alias.Name, alias.SortName, alias.Type, alias.Locale, alias.IsPrimary, alias.BeginDate, alias.EndDate, alias.IsEnded))]);
|
||||
return new ArtistResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.Name,
|
||||
metadata,
|
||||
repositoryEntity.Website,
|
||||
repositoryEntity.MusicBrainzArtistId,
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Albums.Select(album => album.ToResponse())],
|
||||
[.. repositoryEntity.Ipis.Select(ipi => ipi.Value)],
|
||||
[.. repositoryEntity.Isnis.Select(isni => isni.Value)],
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc);
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Ratings.ToResponses()],
|
||||
[.. repositoryEntity.Albums.Select(album => album.ToResponse())]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+19
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -25,8 +27,25 @@ public static class ArtistMapping
|
||||
Id = domainEntity.Id.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
Name = domainEntity.Name,
|
||||
SortName = domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
Type = domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
Gender = domainEntity.Gender.HasValue ? domainEntity.Gender.Value : null,
|
||||
Country = domainEntity.Country.HasValue ? domainEntity.Country.Value : null,
|
||||
LifeSpanBegin = domainEntity.LifeSpanBegin.HasValue ? domainEntity.LifeSpanBegin.Value : null,
|
||||
LifeSpanEnd = domainEntity.LifeSpanEnd.HasValue ? domainEntity.LifeSpanEnd.Value : null,
|
||||
IsEnded = domainEntity.IsEnded,
|
||||
Website = domainEntity.Website.HasValue ? domainEntity.Website.Value : null,
|
||||
MusicBrainzArtistId = domainEntity.MusicBrainzArtistId.HasValue ? domainEntity.MusicBrainzArtistId.Value.Value : null,
|
||||
Area = domainEntity.Area.HasValue ? domainEntity.Area.Value.ToRepositoryEntity() : null,
|
||||
BeginArea = domainEntity.BeginArea.HasValue ? domainEntity.BeginArea.Value.ToRepositoryEntity() : null,
|
||||
EndArea = domainEntity.EndArea.HasValue ? domainEntity.EndArea.Value.ToRepositoryEntity() : null,
|
||||
Aliases = [.. domainEntity.Aliases.ToRepositoryEntities()],
|
||||
Ipis = [.. domainEntity.Ipis.Select(ipi => new ArtistIpiEntity(ipi))],
|
||||
Isnis = [.. domainEntity.Isnis.Select(isni => new ArtistIsniEntity(isni))],
|
||||
Genres = [.. domainEntity.Genres.ToRepositoryEntities()],
|
||||
Tags = [.. domainEntity.Tags.ToRepositoryEntities()],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new ArtistContributorEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ArtistMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class ArtistMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="artist"/>, through the aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The artist metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate the metadata is applied to.</param>
|
||||
/// <param name="contributors">The media contributors that make up the artist, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this ArtistMetadataDto dto, Artist artist, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<Optional<MusicArea>> areaResult = dto.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = dto.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = dto.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
Result<List<MusicArtistAlias>> aliasesResult = dto.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
List<Genre> genres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> tags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(dto.MusicBrainzArtistId.Value);
|
||||
|
||||
// The website is only replaced when the provider returned one, so a locally captured website is never cleared.
|
||||
Optional<string> website = string.IsNullOrWhiteSpace(dto.Website) ? artist.Website : Optional<string>.FromNullable(dto.Website);
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(
|
||||
string.IsNullOrWhiteSpace(dto.Name) ? artist.Name : dto.Name,
|
||||
Optional<string>.FromNullable(dto.SortName),
|
||||
Optional<string>.FromNullable(dto.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(dto.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(dto.Gender),
|
||||
Optional<string>.FromNullable(dto.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(dto.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(dto.LifeSpanEnd),
|
||||
dto.IsEnded,
|
||||
website,
|
||||
musicBrainzArtistId);
|
||||
if (updateDetailsResult.IsFailure)
|
||||
return updateDetailsResult.Errors;
|
||||
|
||||
artist.UpdateAliases(aliasesResult.Value);
|
||||
artist.UpdateIpis([.. dto.Ipis ?? []]);
|
||||
artist.UpdateIsnis([.. dto.Isnis ?? []]);
|
||||
artist.UpdateGenres(genres);
|
||||
artist.UpdateTags(tags);
|
||||
artist.UpdateRatings(ratings);
|
||||
artist.UpdateContributors(contributors);
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -26,8 +26,11 @@ public static class UpdateArtistAlbumRequestMapping
|
||||
artistId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+68
-6
@@ -1,11 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.UpdateArtist;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -28,8 +34,10 @@ public static class UpdateArtistCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateArtistCommand command, Artist artist)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = command.Metadata!;
|
||||
|
||||
// Map the media contributors that make up the artist to their domain counterparts.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -40,15 +48,64 @@ public static class UpdateArtistCommandMapping
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
IEnumerable<Result<Genre>> domainGenresResult = (metadata.Genres ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = (metadata.Tags ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<Optional<MusicArea>> areaResult = metadata.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = metadata.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = metadata.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
|
||||
Result<List<MusicArtistAlias>> aliasesResult = metadata.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
// The details and the media contributors of the artist are replaced in place, preserving its identity and creation metadata.
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(command.Name!, website, musicBrainzArtistId);
|
||||
// The details and the media library collections of the artist are replaced in place, preserving its identity and creation metadata.
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(
|
||||
metadata.Name!,
|
||||
Optional<string>.FromNullable(metadata.SortName),
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(metadata.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(metadata.Gender),
|
||||
Optional<string>.FromNullable(metadata.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanEnd),
|
||||
metadata.IsEnded,
|
||||
Optional<string>.FromNullable(command.Website),
|
||||
musicBrainzArtistId);
|
||||
if (updateDetailsResult.IsFailure)
|
||||
return updateDetailsResult.Errors;
|
||||
|
||||
artist.UpdateAliases(aliasesResult.Value);
|
||||
artist.UpdateIpis([.. (command.Ipis ?? [])]);
|
||||
artist.UpdateIsnis([.. (command.Isnis ?? [])]);
|
||||
artist.UpdateGenres([.. domainGenresResult.Select(genreResult => genreResult.Value)]);
|
||||
artist.UpdateTags([.. domainTagsResult.Select(tagResult => tagResult.Value)]);
|
||||
artist.UpdateRatings([.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]);
|
||||
artist.UpdateContributors([.. domainContributorsResult.Select(contributorResult => contributorResult.Value)]);
|
||||
|
||||
List<Album> domainAlbums = [.. domainAlbumsResult.Select(albumResult => albumResult.Value)];
|
||||
@@ -70,9 +127,14 @@ public static class UpdateArtistCommandMapping
|
||||
Result<Updated> updateAlbumResult = artist.UpdateAlbum(
|
||||
existingAlbum,
|
||||
domainAlbum.Metadata,
|
||||
domainAlbum.Disambiguation,
|
||||
domainAlbum.MediaFormat,
|
||||
domainAlbum.Packaging,
|
||||
domainAlbum.Script,
|
||||
domainAlbum.Barcode,
|
||||
domainAlbum.CatalogNumber,
|
||||
[.. domainAlbum.CatalogNumbers],
|
||||
domainAlbum.Label,
|
||||
domainAlbum.ASIN,
|
||||
domainAlbum.MusicBrainzReleaseId,
|
||||
domainAlbum.MusicBrainzReleaseGroupId,
|
||||
domainAlbum.MusicBrainzReleaseArtistId,
|
||||
@@ -103,10 +165,10 @@ public static class UpdateArtistCommandMapping
|
||||
domainTrack.Script,
|
||||
domainTrack.Key,
|
||||
domainTrack.Bpm,
|
||||
domainTrack.IsVideo,
|
||||
domainTrack.Work,
|
||||
domainTrack.MusicBrainzRecordingId,
|
||||
domainTrack.MusicBrainzTrackId,
|
||||
domainTrack.MusicBrainzWorkId,
|
||||
domainTrack.Moods,
|
||||
domainTrack.Isrcs,
|
||||
domainTrack.Contributors,
|
||||
|
||||
+4
-1
@@ -23,10 +23,13 @@ public static class UpdateArtistRequestMapping
|
||||
return new UpdateArtistCommand(
|
||||
libraryId,
|
||||
artistId,
|
||||
request.Name,
|
||||
request.Metadata,
|
||||
request.Website,
|
||||
request.MusicBrainzArtistId,
|
||||
request.Ipis,
|
||||
request.Isnis,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Albums?.ToCommands(libraryId, artistId).ToList());
|
||||
}
|
||||
}
|
||||
-1
@@ -36,7 +36,6 @@ public static class UpdateArtistTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
public static class ArtistAliasEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicArtistAlias"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArtistAlias> ToDomainValueObject(this ArtistAliasEntity repositoryEntity)
|
||||
{
|
||||
return MusicArtistAlias.Create(
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Type),
|
||||
Optional<string>.FromNullable(repositoryEntity.Locale),
|
||||
repositoryEntity.IsPrimary,
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.BeginDate),
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.EndDate),
|
||||
repositoryEntity.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted aliases, or an error message.
|
||||
/// </returns>
|
||||
public static Result<List<MusicArtistAlias>> ToDomainValueObjects(this IEnumerable<ArtistAliasEntity> repositoryEntities)
|
||||
{
|
||||
List<MusicArtistAlias> aliases = [];
|
||||
foreach (ArtistAliasEntity repositoryEntity in repositoryEntities)
|
||||
{
|
||||
Result<MusicArtistAlias> aliasResult = repositoryEntity.ToDomainValueObject();
|
||||
if (aliasResult.IsFailure)
|
||||
return aliasResult.Errors;
|
||||
aliases.Add(aliasResult.Value);
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -21,7 +21,7 @@ public static class AudioRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioRating> ToDomainEntity(this AudioRatingDto dto)
|
||||
public static Result<AudioRating> ToDomainValueObject(this AudioRatingDto dto)
|
||||
{
|
||||
return AudioRating.Create(
|
||||
dto.Value ?? default,
|
||||
@@ -38,8 +38,8 @@ public static class AudioRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainEntities(this IEnumerable<AudioRatingDto> dtos)
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainValueObjects(this IEnumerable<AudioRatingDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -47,7 +47,7 @@ public static class AudioRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioRating> ToDomainEntity(this AudioRatingEntity repositoryEntity)
|
||||
public static Result<AudioRating> ToDomainValueObject(this AudioRatingEntity repositoryEntity)
|
||||
{
|
||||
return AudioRating.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
@@ -64,8 +64,8 @@ public static class AudioRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainEntities(this IEnumerable<AudioRatingEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainValueObjects(this IEnumerable<AudioRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ public static class IsrcDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this IsrcDto dto)
|
||||
public static Result<Isrc> ToDomainValueObject(this IsrcDto dto)
|
||||
{
|
||||
return Isrc.Create(dto.Value!);
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public static class IsrcDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isrc>> ToDomainEntities(this IEnumerable<IsrcDto> dtos)
|
||||
public static IEnumerable<Result<Isrc>> ToDomainValueObjects(this IEnumerable<IsrcDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -43,7 +43,7 @@ public static class IsrcEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this TrackIsrcEntity repositoryEntity)
|
||||
public static Result<Isrc> ToDomainValueObject(this TrackIsrcEntity repositoryEntity)
|
||||
{
|
||||
return Isrc.Create(repositoryEntity.Value!);
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public static class IsrcEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isrc>> ToDomainEntities(this IEnumerable<TrackIsrcEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Isrc>> ToDomainValueObjects(this IEnumerable<TrackIsrcEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ public static class MoodDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this MoodDto dto)
|
||||
public static Result<Mood> ToDomainValueObject(this MoodDto dto)
|
||||
{
|
||||
return Mood.Create(dto.Name!);
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public static class MoodDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Mood>> ToDomainEntities(this IEnumerable<MoodDto> dtos)
|
||||
public static IEnumerable<Result<Mood>> ToDomainValueObjects(this IEnumerable<MoodDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -43,7 +43,7 @@ public static class MoodEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this TrackMoodEntity repositoryEntity)
|
||||
public static Result<Mood> ToDomainValueObject(this TrackMoodEntity repositoryEntity)
|
||||
{
|
||||
return Mood.Create(repositoryEntity.Name!);
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public static class MoodEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Mood>> ToDomainEntities(this IEnumerable<TrackMoodEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Mood>> ToDomainValueObjects(this IEnumerable<TrackMoodEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAreaDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="areaDto"/> to a domain <see cref="MusicArea"/>, wrapped in an <see cref="Optional{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="areaDto">The area data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted optional area, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Optional<MusicArea>> ToDomainValueObject(this MusicAreaDto? areaDto)
|
||||
{
|
||||
if (areaDto is null || areaDto.MusicBrainzAreaId is null)
|
||||
return Optional<MusicArea>.None();
|
||||
|
||||
Result<MusicArea> areaResult = MusicArea.Create(
|
||||
MusicBrainzId.Create(areaDto.MusicBrainzAreaId.Value),
|
||||
areaDto.Name!,
|
||||
Optional<string>.FromNullable(areaDto.SortName),
|
||||
Optional<string>.FromNullable(areaDto.Disambiguation),
|
||||
Optional<string>.FromNullable(areaDto.Type),
|
||||
Optional<string>.FromNullable(areaDto.Iso3166Code));
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
return Optional<MusicArea>.Some(areaResult.Value);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAreaEntity"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicArea"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicArea"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArea> ToDomainValueObject(this MusicAreaEntity repositoryEntity)
|
||||
{
|
||||
return MusicArea.Create(
|
||||
MusicBrainzId.Create(repositoryEntity.MusicBrainzAreaId),
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<string>.FromNullable(repositoryEntity.Type),
|
||||
Optional<string>.FromNullable(repositoryEntity.Iso3166Code));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicAreaDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object, or <see langword="null"/> when the repository entity is <see langword="null"/>.</returns>
|
||||
public static MusicAreaDto? ToResponse(this MusicAreaEntity? repositoryEntity)
|
||||
{
|
||||
return repositoryEntity is null
|
||||
? null
|
||||
: new MusicAreaDto(repositoryEntity.MusicBrainzAreaId, repositoryEntity.Name, repositoryEntity.SortName, repositoryEntity.Disambiguation, repositoryEntity.Type, repositoryEntity.Iso3166Code);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArea"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="MusicAreaEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static MusicAreaEntity ToRepositoryEntity(this MusicArea domainEntity)
|
||||
{
|
||||
return new MusicAreaEntity(
|
||||
domainEntity.MusicBrainzAreaId.Value,
|
||||
domainEntity.Name,
|
||||
domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
domainEntity.Iso3166Code.HasValue ? domainEntity.Iso3166Code.Value : null);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArtistAliasDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicArtistAliasDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="aliasDto"/> to a domain <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="aliasDto">The alias data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted alias, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArtistAlias> ToDomainValueObject(this MusicArtistAliasDto aliasDto)
|
||||
{
|
||||
return MusicArtistAlias.Create(
|
||||
aliasDto.Name!,
|
||||
Optional<string>.FromNullable(aliasDto.SortName),
|
||||
Optional<string>.FromNullable(aliasDto.Type),
|
||||
Optional<string>.FromNullable(aliasDto.Locale),
|
||||
aliasDto.IsPrimary,
|
||||
Optional<DateOnly>.FromNullable(aliasDto.BeginDate),
|
||||
Optional<DateOnly>.FromNullable(aliasDto.EndDate),
|
||||
aliasDto.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="aliasDtos"/> to a collection of domain <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="aliasDtos">The alias data transfer objects to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted aliases, or an error message.
|
||||
/// </returns>
|
||||
public static Result<List<MusicArtistAlias>> ToDomainValueObjects(this IEnumerable<MusicArtistAliasDto>? aliasDtos)
|
||||
{
|
||||
List<MusicArtistAlias> aliases = [];
|
||||
foreach (MusicArtistAliasDto aliasDto in aliasDtos ?? [])
|
||||
{
|
||||
Result<MusicArtistAlias> aliasResult = aliasDto.ToDomainValueObject();
|
||||
if (aliasResult.IsFailure)
|
||||
return aliasResult.Errors;
|
||||
aliases.Add(aliasResult.Value);
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
public static class MusicArtistAliasMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static ArtistAliasEntity ToRepositoryEntity(this MusicArtistAlias domainEntity)
|
||||
{
|
||||
return new ArtistAliasEntity(
|
||||
domainEntity.Name,
|
||||
domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
domainEntity.Locale.HasValue ? domainEntity.Locale.Value : null,
|
||||
domainEntity.IsPrimary,
|
||||
domainEntity.BeginDate.HasValue ? domainEntity.BeginDate.Value : null,
|
||||
domainEntity.EndDate.HasValue ? domainEntity.EndDate.Value : null,
|
||||
domainEntity.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntities">The domain entities to be converted.</param>
|
||||
/// <returns>The converted repository entities.</returns>
|
||||
public static List<ArtistAliasEntity> ToRepositoryEntities(this IEnumerable<MusicArtistAlias> domainEntities)
|
||||
{
|
||||
return [.. domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity())];
|
||||
}
|
||||
}
|
||||
+22
-12
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
@@ -29,39 +30,46 @@ public static class AddTrackCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Track> ToDomainEntity(this AddTrackCommand command)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicTrackMetadataDto metadata = command.Metadata!;
|
||||
Result<AudioMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (command.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = command.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
List<Mood> moods = [.. domainMoodsResult.Select(moodResult => moodResult.Value)];
|
||||
List<Isrc> isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
|
||||
@@ -74,17 +82,18 @@ public static class AddTrackCommandMapping
|
||||
TrackId.Create(command.TrackId.Value),
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
metadata.IsVideo,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings,
|
||||
DateTime.UtcNow,
|
||||
@@ -93,17 +102,18 @@ public static class AddTrackCommandMapping
|
||||
return Track.Create(
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
metadata.IsVideo,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
-1
@@ -36,7 +36,6 @@ public static class AddTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+164
-35
@@ -1,10 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,65 +24,188 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
public static class AudioMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>.
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="track"/>, through the owning <paramref name="artist"/> aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The audio metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the album of the track.</param>
|
||||
/// <param name="album">The album the track belongs to.</param>
|
||||
/// <param name="track">The track entity to update.</param>
|
||||
/// <param name="contributors">The media contributors of the track, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this AudioMetadataDto dto, Artist artist, Album album, Track track, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = dto.ToDomainValueObject(track);
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
// The work, the moods and the ISRCs of the track are only replaced when the provider returned values, so locally extracted data is never cleared.
|
||||
Optional<MusicWork> work = track.Work;
|
||||
if (dto.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = dto.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
List<Mood> moods = [.. track.Moods];
|
||||
if (dto.Moods is { Count: > 0 })
|
||||
{
|
||||
moods = [];
|
||||
foreach (MoodDto mood in dto.Moods)
|
||||
{
|
||||
Result<Mood> moodResult = mood.ToDomainValueObject();
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
moods.Add(moodResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
List<Isrc> isrcs = [.. track.Isrcs];
|
||||
if (dto.Isrcs is { Count: > 0 })
|
||||
{
|
||||
isrcs = [];
|
||||
foreach (IsrcDto isrc in dto.Isrcs)
|
||||
{
|
||||
Result<Isrc> isrcResult = isrc.ToDomainValueObject();
|
||||
if (isrcResult.IsFailure)
|
||||
return isrcResult.Errors;
|
||||
isrcs.Add(isrcResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<string> script = Optional<string>.FromNullable(dto.Script);
|
||||
if (!script.HasValue)
|
||||
script = track.Script;
|
||||
Optional<MusicKey> key = Optional<MusicKey>.FromNullable(dto.Key);
|
||||
if (!key.HasValue)
|
||||
key = track.Key;
|
||||
Optional<int> bpm = Optional<int>.FromNullable(dto.Bpm);
|
||||
if (!bpm.HasValue)
|
||||
bpm = track.Bpm;
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(dto.MusicBrainzRecordingId.Value);
|
||||
else
|
||||
musicBrainzRecordingId = track.MusicBrainzRecordingId;
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(dto.MusicBrainzTrackId.Value);
|
||||
else
|
||||
musicBrainzTrackId = track.MusicBrainzTrackId;
|
||||
|
||||
return artist.UpdateTrackInAlbum(
|
||||
album,
|
||||
track,
|
||||
track.Path,
|
||||
metadataResult.Value,
|
||||
track.TrackNumber,
|
||||
track.DiscNumber,
|
||||
script,
|
||||
key,
|
||||
bpm,
|
||||
dto.IsVideo,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
moods,
|
||||
isrcs,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>, keeping the locally extracted audio properties that the provider did not return.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <param name="track">The existing track whose locally extracted properties are preserved for the fields the provider left empty.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioMetadata> ToDomainEntity(this AudioMetadataDto dto)
|
||||
private static Result<AudioMetadata> ToDomainValueObject(this AudioMetadataDto dto, Track track)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
Result<ReleaseInfo> releaseInfoResult = dto.ReleaseInfo is null
|
||||
? ReleaseInfo.Create(
|
||||
track.Metadata.ReleaseInfo.OriginalReleaseDate,
|
||||
track.Metadata.ReleaseInfo.OriginalReleaseYear,
|
||||
track.Metadata.ReleaseInfo.ReReleaseDate,
|
||||
track.Metadata.ReleaseInfo.ReReleaseYear,
|
||||
track.Metadata.ReleaseInfo.ReleaseCountry,
|
||||
track.Metadata.ReleaseInfo.ReleaseVersion)
|
||||
: ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(dto.ReleaseInfo.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(dto.ReleaseInfo.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(dto.ReleaseInfo.ReReleaseDate),
|
||||
Optional<int>.FromNullable(dto.ReleaseInfo.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(dto.ReleaseInfo.ReleaseCountry),
|
||||
Optional<string>.FromNullable(dto.ReleaseInfo.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
List<Genre> genres = [.. track.Metadata.Genres];
|
||||
if (dto.Genres is { Count: > 0 })
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainEntity();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
genres = [];
|
||||
foreach (GenreDto genre in dto.Genres)
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
List<Tag> tags = [.. track.Metadata.Tags];
|
||||
if (dto.Tags is { Count: > 0 })
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainEntity();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
tags = [];
|
||||
foreach (TagDto tag in dto.Tags)
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
Optional<LanguageInfo> language = track.Metadata.Language;
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
Optional<LanguageInfo> originalLanguage = track.Metadata.OriginalLanguage;
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AudioMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
dto.DurationInSeconds ?? 0,
|
||||
dto.SampleRate ?? 0,
|
||||
dto.Channels ?? 0,
|
||||
string.IsNullOrWhiteSpace(dto.Title) ? track.Metadata.Title : dto.Title,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle).HasValue ? Optional<string>.FromNullable(dto.OriginalTitle) : track.Metadata.OriginalTitle,
|
||||
dto.DurationInSeconds is > 0 ? dto.DurationInSeconds.Value : track.Metadata.DurationInSeconds,
|
||||
dto.SampleRate is > 0 ? dto.SampleRate.Value : track.Metadata.SampleRate,
|
||||
dto.Channels is > 0 ? dto.Channels.Value : track.Metadata.Channels,
|
||||
releaseInfoResult.Value,
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
domainGenres,
|
||||
domainTags,
|
||||
Optional<string>.FromNullable(dto.Description).HasValue ? Optional<string>.FromNullable(dto.Description) : track.Metadata.Description,
|
||||
genres,
|
||||
tags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(dto.BitDepth),
|
||||
Optional<string>.FromNullable(dto.AudioCodec),
|
||||
Optional<int>.FromNullable(dto.Bitrate));
|
||||
Optional<int>.FromNullable(dto.BitDepth).HasValue ? Optional<int>.FromNullable(dto.BitDepth) : track.Metadata.BitDepth,
|
||||
Optional<string>.FromNullable(dto.AudioCodec).HasValue ? Optional<string>.FromNullable(dto.AudioCodec) : track.Metadata.AudioCodec,
|
||||
Optional<int>.FromNullable(dto.Bitrate).HasValue ? Optional<int>.FromNullable(dto.Bitrate) : track.Metadata.Bitrate,
|
||||
track.Metadata.AcoustId,
|
||||
track.Metadata.ReplayGainTrackGain,
|
||||
track.Metadata.ReplayGainTrackPeak,
|
||||
track.Metadata.ReplayGainAlbumGain,
|
||||
track.Metadata.ReplayGainAlbumPeak);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicTrackMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicTrackMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioMetadata> ToDomainValueObject(this MusicTrackMetadataDto dto)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AudioMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
dto.DurationInSeconds ?? 0,
|
||||
dto.SampleRate ?? 0,
|
||||
dto.Channels ?? 0,
|
||||
releaseInfoResult.Value,
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(dto.BitDepth),
|
||||
Optional<string>.FromNullable(dto.AudioCodec),
|
||||
Optional<int>.FromNullable(dto.Bitrate),
|
||||
Optional<string>.FromNullable(dto.AcoustId),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainTrackGain),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainTrackPeak),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainAlbumGain),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainAlbumPeak));
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicWorkDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicWorkDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="MusicWork"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicWork"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicWork> ToDomainValueObject(this MusicWorkDto dto)
|
||||
{
|
||||
if (dto.MusicBrainzWorkId is null)
|
||||
return Domain.Common.Errors.Errors.Music.MusicBrainzIdInvalidFormat;
|
||||
if (string.IsNullOrWhiteSpace(dto.Title))
|
||||
return Domain.Common.Errors.Errors.Music.WorkTitleCannotBeEmpty;
|
||||
|
||||
List<LanguageInfo> languages = [];
|
||||
foreach (LanguageInfoDto languageDto in dto.Languages ?? [])
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(languageDto.LanguageCode) || string.IsNullOrWhiteSpace(languageDto.LanguageName))
|
||||
continue;
|
||||
languages.Add(LanguageInfo.Create(languageDto.LanguageCode, languageDto.LanguageName, Optional<string>.FromNullable(languageDto.NativeName)));
|
||||
}
|
||||
|
||||
List<string> iswcs = [.. (dto.Iswcs ?? []).Where(iswc => !string.IsNullOrWhiteSpace(iswc)).Select(iswc => iswc.Trim())];
|
||||
|
||||
return MusicWork.Create(
|
||||
MusicBrainzId.Create(dto.MusicBrainzWorkId.Value),
|
||||
dto.Title,
|
||||
Optional<string>.FromNullable(dto.Type),
|
||||
languages,
|
||||
iswcs);
|
||||
}
|
||||
}
|
||||
+54
-16
@@ -8,7 +8,6 @@ using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
@@ -48,7 +47,7 @@ public static class TrackEntityMapping
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainEntities())
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
@@ -56,7 +55,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainEntities())
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
@@ -85,7 +84,12 @@ public static class TrackEntityMapping
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(repositoryEntity.BitDepth),
|
||||
Optional<string>.FromNullable(repositoryEntity.AudioCodec),
|
||||
Optional<int>.FromNullable(repositoryEntity.Bitrate));
|
||||
Optional<int>.FromNullable(repositoryEntity.Bitrate),
|
||||
Optional<string>.FromNullable(repositoryEntity.AcoustId),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainTrackGain),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainTrackPeak),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainAlbumGain),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainAlbumPeak));
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
@@ -95,12 +99,27 @@ public static class TrackEntityMapping
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value);
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null && !string.IsNullOrWhiteSpace(repositoryEntity.WorkTitle))
|
||||
{
|
||||
List<LanguageInfo> workLanguages = [];
|
||||
foreach (TrackWorkLanguageEntity workLanguage in repositoryEntity.WorkLanguages)
|
||||
workLanguages.Add(LanguageInfo.Create(workLanguage.LanguageCode, workLanguage.LanguageName, Optional<string>.FromNullable(workLanguage.NativeName)));
|
||||
|
||||
Result<MusicWork> workResult = MusicWork.Create(
|
||||
MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value),
|
||||
repositoryEntity.WorkTitle,
|
||||
Optional<string>.FromNullable(repositoryEntity.WorkType),
|
||||
workLanguages,
|
||||
[.. repositoryEntity.WorkIswcs.Select(workIswc => workIswc.Value)]);
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
List<Mood> domainMoods = [];
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainEntities())
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainValueObjects())
|
||||
{
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
@@ -108,7 +127,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<Isrc> domainIsrcs = [];
|
||||
foreach (Result<Isrc> isrcResult in repositoryEntity.Isrcs.ToDomainEntities())
|
||||
foreach (Result<Isrc> isrcResult in repositoryEntity.Isrcs.ToDomainValueObjects())
|
||||
{
|
||||
if (isrcResult.IsFailure)
|
||||
return isrcResult.Errors;
|
||||
@@ -116,7 +135,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
@@ -136,17 +155,18 @@ public static class TrackEntityMapping
|
||||
TrackId.Create(repositoryEntity.Id),
|
||||
repositoryEntity.Path,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
repositoryEntity.TrackNumber,
|
||||
Optional<int>.FromNullable(repositoryEntity.DiscNumber),
|
||||
domainMoods,
|
||||
Optional<string>.FromNullable(repositoryEntity.Script),
|
||||
Optional<MusicKey>.FromNullable(repositoryEntity.Key),
|
||||
Optional<int>.FromNullable(repositoryEntity.Bpm),
|
||||
repositoryEntity.IsVideo,
|
||||
domainIsrcs,
|
||||
Optional<string>.FromNullable(repositoryEntity.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
domainContributors,
|
||||
domainRatings,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
@@ -185,21 +205,40 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.OriginalLanguageName,
|
||||
repositoryEntity.OriginalLanguageNativeName
|
||||
) : null;
|
||||
AudioMetadataDto metadata = new(
|
||||
MusicWorkDto? work = null;
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null && !string.IsNullOrWhiteSpace(repositoryEntity.WorkTitle))
|
||||
work = new MusicWorkDto(
|
||||
repositoryEntity.MusicBrainzWorkId,
|
||||
repositoryEntity.WorkTitle,
|
||||
repositoryEntity.WorkType,
|
||||
repositoryEntity.WorkLanguages.Count > 0
|
||||
? [.. repositoryEntity.WorkLanguages.Select(workLanguage => new LanguageInfoDto(workLanguage.LanguageCode, workLanguage.LanguageName, workLanguage.NativeName))]
|
||||
: null,
|
||||
repositoryEntity.WorkIswcs.Count > 0
|
||||
? [.. repositoryEntity.WorkIswcs.Select(workIswc => workIswc.Value)]
|
||||
: null);
|
||||
MusicTrackMetadataDto metadata = new(
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.OriginalTitle,
|
||||
repositoryEntity.Description,
|
||||
repositoryEntity.Disambiguation,
|
||||
releaseInfo,
|
||||
languageInfo,
|
||||
originalLanguageInfo,
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
repositoryEntity.IsVideo,
|
||||
repositoryEntity.DurationInSeconds,
|
||||
repositoryEntity.SampleRate,
|
||||
repositoryEntity.Channels,
|
||||
repositoryEntity.BitDepth,
|
||||
repositoryEntity.AudioCodec,
|
||||
repositoryEntity.Bitrate
|
||||
repositoryEntity.Bitrate,
|
||||
repositoryEntity.AcoustId,
|
||||
repositoryEntity.ReplayGainTrackGain,
|
||||
repositoryEntity.ReplayGainTrackPeak,
|
||||
repositoryEntity.ReplayGainAlbumGain,
|
||||
repositoryEntity.ReplayGainAlbumPeak
|
||||
);
|
||||
return new TrackResponse(
|
||||
repositoryEntity.Id,
|
||||
@@ -212,10 +251,9 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.Script,
|
||||
repositoryEntity.Key,
|
||||
repositoryEntity.Bpm,
|
||||
repositoryEntity.Work,
|
||||
work,
|
||||
repositoryEntity.MusicBrainzRecordingId,
|
||||
repositoryEntity.MusicBrainzTrackId,
|
||||
repositoryEntity.MusicBrainzWorkId,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
[.. repositoryEntity.Moods.ToResponses()],
|
||||
|
||||
+16
-3
@@ -5,7 +5,6 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibrary
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -33,6 +32,7 @@ public static class TrackMapping
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
OriginalReleaseDate = domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null,
|
||||
OriginalReleaseYear = domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null,
|
||||
ReReleaseDate = domainEntity.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseDate.Value : null,
|
||||
@@ -53,15 +53,22 @@ public static class TrackMapping
|
||||
BitDepth = domainEntity.Metadata.BitDepth.HasValue ? domainEntity.Metadata.BitDepth.Value : null,
|
||||
AudioCodec = domainEntity.Metadata.AudioCodec.HasValue ? domainEntity.Metadata.AudioCodec.Value : null,
|
||||
Bitrate = domainEntity.Metadata.Bitrate.HasValue ? domainEntity.Metadata.Bitrate.Value : null,
|
||||
AcoustId = domainEntity.Metadata.AcoustId.HasValue ? domainEntity.Metadata.AcoustId.Value : null,
|
||||
ReplayGainTrackGain = domainEntity.Metadata.ReplayGainTrackGain.HasValue ? domainEntity.Metadata.ReplayGainTrackGain.Value : null,
|
||||
ReplayGainTrackPeak = domainEntity.Metadata.ReplayGainTrackPeak.HasValue ? domainEntity.Metadata.ReplayGainTrackPeak.Value : null,
|
||||
ReplayGainAlbumGain = domainEntity.Metadata.ReplayGainAlbumGain.HasValue ? domainEntity.Metadata.ReplayGainAlbumGain.Value : null,
|
||||
ReplayGainAlbumPeak = domainEntity.Metadata.ReplayGainAlbumPeak.HasValue ? domainEntity.Metadata.ReplayGainAlbumPeak.Value : null,
|
||||
TrackNumber = domainEntity.TrackNumber,
|
||||
DiscNumber = domainEntity.DiscNumber.HasValue ? domainEntity.DiscNumber.Value : null,
|
||||
Script = domainEntity.Script.HasValue ? domainEntity.Script.Value : null,
|
||||
Key = domainEntity.Key.HasValue ? domainEntity.Key.Value : null,
|
||||
Bpm = domainEntity.Bpm.HasValue ? domainEntity.Bpm.Value : null,
|
||||
Work = domainEntity.Work.HasValue ? domainEntity.Work.Value : null,
|
||||
IsVideo = domainEntity.IsVideo,
|
||||
WorkTitle = domainEntity.Work.HasValue ? domainEntity.Work.Value.Title : null,
|
||||
WorkType = domainEntity.Work.HasValue && domainEntity.Work.Value.Type.HasValue ? domainEntity.Work.Value.Type.Value : null,
|
||||
MusicBrainzRecordingId = domainEntity.MusicBrainzRecordingId.HasValue ? domainEntity.MusicBrainzRecordingId.Value.Value : null,
|
||||
MusicBrainzTrackId = domainEntity.MusicBrainzTrackId.HasValue ? domainEntity.MusicBrainzTrackId.Value.Value : null,
|
||||
MusicBrainzWorkId = domainEntity.MusicBrainzWorkId.HasValue ? domainEntity.MusicBrainzWorkId.Value.Value : null,
|
||||
MusicBrainzWorkId = domainEntity.Work.HasValue ? domainEntity.Work.Value.MusicBrainzWorkId.Value : null,
|
||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new TrackContributorEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
@@ -74,6 +81,12 @@ public static class TrackMapping
|
||||
})],
|
||||
Moods = [.. domainEntity.Moods.ToRepositoryEntities()],
|
||||
Isrcs = [.. domainEntity.Isrcs.ToRepositoryEntities()],
|
||||
WorkLanguages = domainEntity.Work.HasValue
|
||||
? [.. domainEntity.Work.Value.Languages.Select(language => new TrackWorkLanguageEntity(language.LanguageCode, language.LanguageName, language.NativeName.HasValue ? language.NativeName.Value : null))]
|
||||
: [],
|
||||
WorkIswcs = domainEntity.Work.HasValue
|
||||
? [.. domainEntity.Work.Value.Iswcs.Select(iswc => new TrackWorkIswcEntity(iswc))]
|
||||
: [],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
|
||||
+18
-10
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
@@ -32,39 +33,46 @@ public static class UpdateTrackCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateTrackCommand command, Artist artist)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicTrackMetadataDto metadata = command.Metadata!;
|
||||
Result<AudioMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (command.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = command.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
// The album and the track are entities inside the artist aggregate, so they are referenced by object, not by id; the aggregate members are located here and passed through.
|
||||
Album? album = artist.Albums.FirstOrDefault(album => album.Id.Value == Guid.Parse(command.AlbumId!));
|
||||
@@ -84,10 +92,10 @@ public static class UpdateTrackCommandMapping
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
metadata.IsVideo,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
[.. domainMoodsResult.Select(moodResult => moodResult.Value)],
|
||||
[.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)],
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
|
||||
-1
@@ -36,7 +36,6 @@ public static class UpdateTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+3
-3
@@ -32,17 +32,17 @@ public static class AddBookCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this AddBookCommand command, Guid libraryId)
|
||||
{
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainValueObjects();
|
||||
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
|
||||
+4
-4
@@ -40,22 +40,22 @@ public static class BookEntityMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this BookEntity repositoryEntity)
|
||||
{
|
||||
IEnumerable<Result<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> tagsResult = repositoryEntity.Tags.ToDomainValueObjects();
|
||||
foreach (Result<Tag> tagResult in tagsResult)
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
|
||||
IEnumerable<Result<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> genresResult = repositoryEntity.Genres.ToDomainValueObjects();
|
||||
foreach (Result<Genre> genreResult in genresResult)
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainValueObjects();
|
||||
foreach (Result<Isbn> isbnResult in isbnsResult)
|
||||
if (isbnResult.IsFailure)
|
||||
return isbnResult.Errors;
|
||||
|
||||
IEnumerable<Result<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainValueObjects();
|
||||
foreach (Result<BookRating> bookRatingResult in bookRatingsResult)
|
||||
if (bookRatingResult.IsFailure)
|
||||
return bookRatingResult.Errors;
|
||||
|
||||
+3
-3
@@ -33,17 +33,17 @@ public static class UpdateBookCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this UpdateBookCommand command, BookEntity existingBook)
|
||||
{
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainValueObjects();
|
||||
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ public static class BookRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<BookRating> ToDomainEntity(this BookRatingDto dto)
|
||||
public static Result<BookRating> ToDomainValueObject(this BookRatingDto dto)
|
||||
{
|
||||
return BookRating.Create(
|
||||
dto.Value ?? default,
|
||||
@@ -39,8 +39,8 @@ public static class BookRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
|
||||
public static IEnumerable<Result<BookRating>> ToDomainValueObjects(this IEnumerable<BookRatingDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -48,7 +48,7 @@ public static class BookRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
|
||||
public static Result<BookRating> ToDomainValueObject(this BookRatingEntity repositoryEntity)
|
||||
{
|
||||
return BookRating.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
@@ -65,8 +65,8 @@ public static class BookRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<BookRating>> ToDomainValueObjects(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -21,7 +21,7 @@ public static class IsbnDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnDto dto)
|
||||
public static Result<Isbn> ToDomainValueObject(this IsbnDto dto)
|
||||
{
|
||||
return Isbn.Create(
|
||||
dto.Value!,
|
||||
@@ -36,8 +36,8 @@ public static class IsbnDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
|
||||
public static IEnumerable<Result<Isbn>> ToDomainValueObjects(this IEnumerable<IsbnDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -44,7 +44,7 @@ public static class IsbnEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
|
||||
public static Result<Isbn> ToDomainValueObject(this IsbnEntity repositoryEntity)
|
||||
{
|
||||
return Isbn.Create(
|
||||
repositoryEntity.Value!,
|
||||
@@ -59,8 +59,8 @@ public static class IsbnEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Isbn>> ToDomainValueObjects(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -22,28 +22,28 @@ public static class WrittenContentMetadataDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="WrittenContentMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<WrittenContentMetadata> ToDomainEntity(this WrittenContentMetadataDto dto)
|
||||
public static Result<WrittenContentMetadata> ToDomainValueObject(this WrittenContentMetadataDto dto)
|
||||
{
|
||||
|
||||
Result<ReleaseInfo>? domainReleaseInfoResult = dto.ReleaseInfo!.ToDomainEntity();
|
||||
Result<ReleaseInfo>? domainReleaseInfoResult = dto.ReleaseInfo!.ToDomainValueObject();
|
||||
if (domainReleaseInfoResult.Value.IsFailure)
|
||||
return domainReleaseInfoResult.Value.Errors;
|
||||
|
||||
IEnumerable<Result<Genre>> domainGenresResult = dto.Genres!.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> domainGenresResult = dto.Genres!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = dto.Tags!.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> domainTagsResult = dto.Tags!.ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<LanguageInfo>? domainLanguageInfoResult = dto.Language?.ToDomainEntity();
|
||||
Result<LanguageInfo>? domainLanguageInfoResult = dto.Language?.ToDomainValueObject();
|
||||
if (domainLanguageInfoResult.HasValue && domainLanguageInfoResult.Value.IsFailure)
|
||||
return domainLanguageInfoResult.Value.Errors;
|
||||
|
||||
Result<LanguageInfo>? domainOriginalLanguageInfoResult = dto.OriginalLanguage?.ToDomainEntity();
|
||||
Result<LanguageInfo>? domainOriginalLanguageInfoResult = dto.OriginalLanguage?.ToDomainValueObject();
|
||||
if (domainOriginalLanguageInfoResult.HasValue && domainOriginalLanguageInfoResult.Value.IsFailure)
|
||||
return domainOriginalLanguageInfoResult.Value.Errors;
|
||||
|
||||
|
||||
+8
-8
@@ -20,13 +20,13 @@ public class GenreDtoMappingTests
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidGenreDto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidGenreDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: "Rock");
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
Result<Genre> result = genreDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -39,13 +39,13 @@ public class GenreDtoMappingTests
|
||||
[InlineData("Jazz")]
|
||||
[InlineData("Classical")]
|
||||
[InlineData("Pop")]
|
||||
public void ToDomainEntity_WhenMappingDifferentValidGenreDtos_ShouldMapCorrectly(string name)
|
||||
public void ToDomainValueObject_WhenMappingDifferentValidGenreDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
Result<Genre> result = genreDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -57,13 +57,13 @@ public class GenreDtoMappingTests
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreDto_ShouldReturnError(string? invalidName)
|
||||
public void ToDomainValueObject_WhenMappingInvalidGenreDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
Result<Genre> result = genreDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -82,7 +82,7 @@ public class GenreDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Genre>> results = genreDtos.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> results = genreDtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
@@ -109,7 +109,7 @@ public class GenreDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Genre>> results = genreDtos.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> results = genreDtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+6
-6
@@ -70,13 +70,13 @@ public class GenreEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: "Fiction");
|
||||
|
||||
// Act
|
||||
Result<Genre> result = entity.ToDomainEntity();
|
||||
Result<Genre> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -88,13 +88,13 @@ public class GenreEntityMappingTests
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
public void ToDomainValueObject_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = entity.ToDomainEntity();
|
||||
Result<Genre> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -102,7 +102,7 @@ public class GenreEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GenreEntity> entities =
|
||||
@@ -114,7 +114,7 @@ public class GenreEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Genre>> results = entities.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+4
-4
@@ -18,13 +18,13 @@ public class LanguageInfoDtoMappingTests
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteLanguageInfoDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingCompleteLanguageInfoDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto dto = _languageInfoDtoFixture.Create(languageCode: "EN", languageName: "English", nativeName: "English");
|
||||
|
||||
// Act
|
||||
Result<LanguageInfo> result = dto.ToDomainEntity();
|
||||
Result<LanguageInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -35,13 +35,13 @@ public class LanguageInfoDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenNativeNameIsMissing_ShouldMapWithoutNativeName()
|
||||
public void ToDomainValueObject_WhenNativeNameIsMissing_ShouldMapWithoutNativeName()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto dto = _languageInfoDtoFixture.Create(includeNativeName: false);
|
||||
|
||||
// Act
|
||||
Result<LanguageInfo> result = dto.ToDomainEntity();
|
||||
Result<LanguageInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
|
||||
+8
-8
@@ -20,7 +20,7 @@ public class ReleaseInfoDtoMappingTests
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteReleaseInfoDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingCompleteReleaseInfoDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto dto = _releaseInfoDtoFixture.Create(
|
||||
@@ -32,7 +32,7 @@ public class ReleaseInfoDtoMappingTests
|
||||
releaseVersion: "Director's Cut");
|
||||
|
||||
// Act
|
||||
Result<ReleaseInfo> result = dto.ToDomainEntity();
|
||||
Result<ReleaseInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -51,13 +51,13 @@ public class ReleaseInfoDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalValuesAreMissing_ShouldMapWithoutOptionalValues()
|
||||
public void ToDomainValueObject_WhenOptionalValuesAreMissing_ShouldMapWithoutOptionalValues()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto dto = _releaseInfoDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<ReleaseInfo> result = dto.ToDomainEntity();
|
||||
Result<ReleaseInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -70,7 +70,7 @@ public class ReleaseInfoDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOriginalReleaseDateAndYearDoNotMatch_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenOriginalReleaseDateAndYearDoNotMatch_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto dto = _releaseInfoDtoFixture.Create(
|
||||
@@ -78,14 +78,14 @@ public class ReleaseInfoDtoMappingTests
|
||||
originalReleaseYear: 2024);
|
||||
|
||||
// Act
|
||||
Result<ReleaseInfo> result = dto.ToDomainEntity();
|
||||
Result<ReleaseInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReReleaseDateAndYearDoNotMatch_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenReReleaseDateAndYearDoNotMatch_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto dto = _releaseInfoDtoFixture.Create(
|
||||
@@ -93,7 +93,7 @@ public class ReleaseInfoDtoMappingTests
|
||||
reReleaseYear: 2024);
|
||||
|
||||
// Act
|
||||
Result<ReleaseInfo> result = dto.ToDomainEntity();
|
||||
Result<ReleaseInfo> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+8
-8
@@ -20,13 +20,13 @@ public class TagDtoMappingTests
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTagDto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidTagDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: "indie");
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
Result<Tag> result = tagDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -40,13 +40,13 @@ public class TagDtoMappingTests
|
||||
[InlineData("instrumental")]
|
||||
[InlineData("live")]
|
||||
[InlineData("acoustic")]
|
||||
public void ToDomainEntity_WhenMappingDifferentValidTagDtos_ShouldMapCorrectly(string name)
|
||||
public void ToDomainValueObject_WhenMappingDifferentValidTagDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
Result<Tag> result = tagDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -58,13 +58,13 @@ public class TagDtoMappingTests
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidTagDto_ShouldReturnError(string? invalidName)
|
||||
public void ToDomainValueObject_WhenMappingInvalidTagDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
Result<Tag> result = tagDto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -83,7 +83,7 @@ public class TagDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Tag>> results = tagDtos.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> results = tagDtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
@@ -110,7 +110,7 @@ public class TagDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Tag>> results = tagDtos.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> results = tagDtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+6
-6
@@ -70,13 +70,13 @@ public class TagEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = _tagEntityFixture.Create(name: "Fantasy");
|
||||
|
||||
// Act
|
||||
Result<Tag> result = entity.ToDomainEntity();
|
||||
Result<Tag> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -88,13 +88,13 @@ public class TagEntityMappingTests
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
public void ToDomainValueObject_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = _tagEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = entity.ToDomainEntity();
|
||||
Result<Tag> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -102,7 +102,7 @@ public class TagEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TagEntity> entities =
|
||||
@@ -114,7 +114,7 @@ public class TagEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Tag>> results = entities.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ public class AddAlbumCommandMappingTests
|
||||
{
|
||||
private readonly AddAlbumCommandFixture _addAlbumCommandFixture = new();
|
||||
private readonly AddTrackCommandFixture _addTrackCommandFixture = new();
|
||||
private readonly AlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly MusicAlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly IsrcDtoFixture _isrcDtoFixture = new();
|
||||
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||
@@ -46,7 +46,7 @@ public class AddAlbumCommandMappingTests
|
||||
Assert.Equal(command.Metadata!.Title, album.Metadata.Title);
|
||||
Assert.Equal(command.MediaFormat, album.MediaFormat.Value);
|
||||
Assert.Equal(command.Barcode, album.Barcode.Value.Value);
|
||||
Assert.Equal(command.CatalogNumber, album.CatalogNumber.Value);
|
||||
Assert.Equal(command.CatalogNumbers, album.CatalogNumbers);
|
||||
Assert.Equal(command.MusicBrainzReleaseId, album.MusicBrainzReleaseId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzReleaseGroupId, album.MusicBrainzReleaseGroupId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzReleaseArtistId, album.MusicBrainzReleaseArtistId.Value.Value);
|
||||
@@ -95,7 +95,7 @@ public class AddAlbumCommandMappingTests
|
||||
AddAlbumCommand command = _addAlbumCommandFixture.Create(
|
||||
includeMediaFormat: false,
|
||||
includeBarcode: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false,
|
||||
@@ -112,7 +112,7 @@ public class AddAlbumCommandMappingTests
|
||||
Assert.Equal(command.Metadata!.Title, album.Metadata.Title);
|
||||
Assert.False(album.MediaFormat.HasValue);
|
||||
Assert.False(album.Barcode.HasValue);
|
||||
Assert.False(album.CatalogNumber.HasValue);
|
||||
Assert.Empty(album.CatalogNumbers);
|
||||
Assert.False(album.MusicBrainzReleaseId.HasValue);
|
||||
Assert.False(album.MusicBrainzReleaseGroupId.HasValue);
|
||||
Assert.False(album.MusicBrainzReleaseArtistId.HasValue);
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ public class AddAlbumRequestMappingTests
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Equal(request.MediaFormat, result.MediaFormat);
|
||||
Assert.Equal(request.Barcode, result.Barcode);
|
||||
Assert.Equal(request.CatalogNumber, result.CatalogNumber);
|
||||
Assert.Equal(request.CatalogNumbers, result.CatalogNumbers);
|
||||
Assert.Equal(request.MusicBrainzReleaseId, result.MusicBrainzReleaseId);
|
||||
Assert.Equal(request.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(request.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
||||
@@ -80,7 +80,7 @@ public class AddAlbumRequestMappingTests
|
||||
AddAlbumRequest request = _addAlbumRequestFixture.Create(
|
||||
includeMediaFormat: false,
|
||||
includeBarcode: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false,
|
||||
@@ -93,7 +93,7 @@ public class AddAlbumRequestMappingTests
|
||||
Assert.NotNull(result.Metadata);
|
||||
Assert.Null(result.MediaFormat);
|
||||
Assert.Null(result.Barcode);
|
||||
Assert.Null(result.CatalogNumber);
|
||||
Assert.Null(result.CatalogNumbers);
|
||||
Assert.Null(result.MusicBrainzReleaseId);
|
||||
Assert.Null(result.MusicBrainzReleaseGroupId);
|
||||
Assert.Null(result.MusicBrainzReleaseArtistId);
|
||||
|
||||
+4
-4
@@ -58,13 +58,13 @@ public class AlbumMappingTests
|
||||
Assert.Equal(album.Metadata.OriginalLanguage.HasValue && album.Metadata.OriginalLanguage.Value.NativeName.HasValue ? album.Metadata.OriginalLanguage.Value.NativeName.Value : null, result.OriginalLanguageNativeName);
|
||||
Assert.Equal(album.Metadata.Genres.ToRepositoryEntities().Distinct().Select(genre => genre.Name).OrderBy(name => name), result.Genres.Select(genre => genre.Name).OrderBy(name => name));
|
||||
Assert.Equal(album.Metadata.Tags.ToRepositoryEntities().Distinct().Select(tag => tag.Name).OrderBy(name => name), result.Tags.Select(tag => tag.Name).OrderBy(name => name));
|
||||
Assert.Equal(album.Metadata.ReleaseType.HasValue ? album.Metadata.ReleaseType.Value : null, result.ReleaseType);
|
||||
Assert.Equal(album.Metadata.ReleaseTypes.OrderBy(releaseType => releaseType), result.ReleaseTypes.Select(releaseType => releaseType.ReleaseType).OrderBy(releaseType => releaseType));
|
||||
Assert.Equal(album.Metadata.ReleaseStatus.HasValue ? album.Metadata.ReleaseStatus.Value : null, result.ReleaseStatus);
|
||||
Assert.Equal(album.Metadata.TotalDiscs.HasValue ? album.Metadata.TotalDiscs.Value : null, result.TotalDiscs);
|
||||
Assert.Equal(album.Metadata.TotalTracks, result.TotalTracks);
|
||||
Assert.Equal(album.MediaFormat.HasValue ? album.MediaFormat.Value : null, result.MediaFormat);
|
||||
Assert.Equal(album.Barcode.HasValue ? album.Barcode.Value.Value : null, result.Barcode);
|
||||
Assert.Equal(album.CatalogNumber.HasValue ? album.CatalogNumber.Value : null, result.CatalogNumber);
|
||||
Assert.Equal(album.CatalogNumbers, result.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber));
|
||||
Assert.Equal(album.MusicBrainzReleaseId.HasValue ? album.MusicBrainzReleaseId.Value.Value : null, result.MusicBrainzReleaseId);
|
||||
Assert.Equal(album.MusicBrainzReleaseGroupId.HasValue ? album.MusicBrainzReleaseGroupId.Value.Value : null, result.MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(album.MusicBrainzReleaseArtistId.HasValue ? album.MusicBrainzReleaseArtistId.Value.Value : null, result.MusicBrainzReleaseArtistId);
|
||||
@@ -133,7 +133,7 @@ public class AlbumMappingTests
|
||||
Album album = _albumFixture.Create(
|
||||
mediaFormat: Optional<MusicMediaFormat>.None(),
|
||||
barcode: Optional<Barcode>.None(),
|
||||
catalogNumber: Optional<string>.None(),
|
||||
catalogNumbers: [],
|
||||
musicBrainzReleaseId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzReleaseGroupId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzReleaseArtistId: Optional<MusicBrainzId>.None(),
|
||||
@@ -147,7 +147,7 @@ public class AlbumMappingTests
|
||||
// Assert
|
||||
Assert.Null(result.MediaFormat);
|
||||
Assert.Null(result.Barcode);
|
||||
Assert.Null(result.CatalogNumber);
|
||||
Assert.Empty(result.CatalogNumbers);
|
||||
Assert.Null(result.MusicBrainzReleaseId);
|
||||
Assert.Null(result.MusicBrainzReleaseGroupId);
|
||||
Assert.Null(result.MusicBrainzReleaseArtistId);
|
||||
|
||||
+104
-87
@@ -1,13 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -22,129 +29,119 @@ public class AlbumMetadataDtoMappingTests
|
||||
{
|
||||
private readonly AlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly MusicMediaContributorFixture _musicMediaContributorFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ApplyTo_WhenMappingCompleteDto_ShouldApplyAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create();
|
||||
List<MusicMediaContributor> contributors = _musicMediaContributorFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, contributors);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.True(metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, metadata.OriginalTitle.Value);
|
||||
Assert.True(metadata.Description.HasValue);
|
||||
Assert.Equal(dto.Description, metadata.Description.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo!.OriginalReleaseDate, metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.OriginalReleaseYear, metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseDate, metadata.ReleaseInfo.ReReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseYear, metadata.ReleaseInfo.ReReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseCountry, metadata.ReleaseInfo.ReleaseCountry.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseVersion, metadata.ReleaseInfo.ReleaseVersion.Value);
|
||||
Assert.True(metadata.Language.HasValue);
|
||||
Assert.Equal(dto.Language!.LanguageCode!.ToLowerInvariant(), metadata.Language.Value.LanguageCode);
|
||||
Assert.Equal(dto.Language.LanguageName, metadata.Language.Value.LanguageName);
|
||||
Assert.Equal(dto.Language.NativeName, metadata.Language.Value.NativeName.Value);
|
||||
Assert.True(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Equal(dto.OriginalLanguage!.LanguageCode!.ToLowerInvariant(), metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(dto.OriginalLanguage.LanguageName, metadata.OriginalLanguage.Value.LanguageName);
|
||||
Assert.Equal(dto.OriginalLanguage.NativeName, metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
Assert.Equal(dto.Genres!.Select(genre => genre.Name), metadata.Genres.Select(genre => genre.Name));
|
||||
Assert.Equal(dto.Tags!.Select(tag => tag.Name), metadata.Tags.Select(tag => tag.Name));
|
||||
Assert.True(metadata.ReleaseType.HasValue);
|
||||
Assert.Equal(dto.ReleaseType, metadata.ReleaseType.Value);
|
||||
Assert.True(metadata.ReleaseStatus.HasValue);
|
||||
Assert.Equal(dto.ReleaseStatus, metadata.ReleaseStatus.Value);
|
||||
Assert.True(metadata.TotalDiscs.HasValue);
|
||||
Assert.Equal(dto.TotalDiscs, metadata.TotalDiscs.Value);
|
||||
Assert.Equal(dto.TotalTracks, metadata.TotalTracks);
|
||||
Assert.Equal(dto.Title, album.Metadata.Title);
|
||||
Assert.True(album.Metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, album.Metadata.OriginalTitle.Value);
|
||||
Assert.True(album.Metadata.Description.HasValue);
|
||||
Assert.Equal(dto.Description, album.Metadata.Description.Value);
|
||||
Assert.Equal(dto.TotalTracks, album.Metadata.TotalTracks);
|
||||
Assert.Equal(dto.ReleaseTypes!.Count, album.Metadata.ReleaseTypes.Count);
|
||||
Assert.True(album.Metadata.ReleaseStatus.HasValue);
|
||||
Assert.Equal(dto.ReleaseStatus, album.Metadata.ReleaseStatus.Value);
|
||||
Assert.True(album.Disambiguation.HasValue);
|
||||
Assert.Equal(dto.Disambiguation, album.Disambiguation.Value);
|
||||
Assert.True(album.Script.HasValue);
|
||||
Assert.Equal(dto.Script, album.Script.Value);
|
||||
Assert.True(album.Barcode.HasValue);
|
||||
Assert.Equal(dto.Barcode, album.Barcode.Value.Value);
|
||||
Assert.NotEmpty(album.CatalogNumbers);
|
||||
Assert.Equal(dto.CatalogNumbers, album.CatalogNumbers);
|
||||
Assert.True(album.Label.HasValue);
|
||||
Assert.Equal(dto.Label, album.Label.Value);
|
||||
Assert.True(album.ASIN.HasValue);
|
||||
Assert.Equal(dto.ASIN, album.ASIN.Value);
|
||||
Assert.True(album.MusicBrainzReleaseId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzReleaseId, album.MusicBrainzReleaseId.Value.Value);
|
||||
Assert.True(album.MusicBrainzReleaseGroupId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzReleaseGroupId, album.MusicBrainzReleaseGroupId.Value.Value);
|
||||
Assert.True(album.MusicBrainzReleaseArtistId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzReleaseArtistId, album.MusicBrainzReleaseArtistId.Value.Value);
|
||||
Assert.Equal(contributors.Count, album.Contributors.Count);
|
||||
Assert.Equal(dto.Ratings!.Count, album.Ratings.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndDefaults()
|
||||
public void ApplyTo_WhenBarcodeIsMissing_ShouldMapTheBarcodeToNone()
|
||||
{
|
||||
// Arrange
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(
|
||||
includeOriginalTitle: false,
|
||||
includeDescription: false,
|
||||
includeReleaseInfo: false,
|
||||
includeLanguage: false,
|
||||
includeOriginalLanguage: false,
|
||||
includeTags: false,
|
||||
includeGenres: false,
|
||||
includeReleaseType: false,
|
||||
includeReleaseStatus: false,
|
||||
includeTotalDiscs: false,
|
||||
includeTotalTracks: false);
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(includeBarcode: false);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.False(metadata.OriginalTitle.HasValue);
|
||||
Assert.False(metadata.Description.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.False(metadata.Language.HasValue);
|
||||
Assert.False(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Empty(metadata.Genres);
|
||||
Assert.Empty(metadata.Tags);
|
||||
Assert.False(metadata.ReleaseType.HasValue);
|
||||
Assert.False(metadata.ReleaseStatus.HasValue);
|
||||
Assert.False(metadata.TotalDiscs.HasValue);
|
||||
Assert.Equal(0, metadata.TotalTracks);
|
||||
Assert.False(album.Barcode.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMissingRequiredSubproperties_ShouldMapLanguageToNone()
|
||||
public void ApplyTo_WhenTheMetadataHasAReleaseTitle_ShouldApplyIt()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto incompleteLanguage = _languageInfoDtoFixture.Create(includeLanguageCode: false);
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(
|
||||
language: incompleteLanguage,
|
||||
originalLanguage: _languageInfoDtoFixture.Create(includeLanguageName: false));
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(releaseTitle: "Greatest Hits I");
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
Assert.True(album.Metadata.ReleaseTitle.HasValue);
|
||||
Assert.Equal("Greatest Hits I", album.Metadata.ReleaseTitle.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
public void ApplyTo_WhenTheMetadataHasNoReleaseDate_ShouldKeepTheStoredReleaseDate()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
DateOnly storedReleaseDate = album.Metadata.ReleaseInfo.OriginalReleaseDate.Value;
|
||||
int storedReleaseYear = album.Metadata.ReleaseInfo.OriginalReleaseYear.Value;
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(includeReleaseInfo: false);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(album.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(storedReleaseDate, album.Metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
Assert.True(album.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(storedReleaseYear, album.Metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
ReleaseInfoDto releaseInfo = _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2000, 1, 1),
|
||||
originalReleaseYear: 1999);
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(releaseInfo: releaseInfo);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, []);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -152,13 +149,14 @@ public class AlbumMetadataDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenGenreIsInvalid_ShouldReturnError()
|
||||
public void ApplyTo_WhenGenreIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album) = CreateDomainArtist();
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: string.Empty)]);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, []);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -166,16 +164,35 @@ public class AlbumMetadataDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTagIsInvalid_ShouldReturnError()
|
||||
public void ApplyTo_WhenAlbumDoesNotBelongToArtist_ShouldReturnAlbumNotFound()
|
||||
{
|
||||
// Arrange
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
(Artist artist, Album _) = CreateDomainArtist();
|
||||
(Artist _, Album foreignAlbum) = CreateDomainArtist();
|
||||
AlbumMetadataDto dto = _albumMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, foreignAlbum, []);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
|
||||
Assert.Equal(Errors.Music.AlbumNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track.
|
||||
/// </summary>
|
||||
/// <returns>The created domain artist, together with its album.</returns>
|
||||
private (Artist artist, Album album) CreateDomainArtist()
|
||||
{
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid albumId = Guid.NewGuid();
|
||||
AlbumEntity albumEntity = _albumEntityFixture.Create(
|
||||
id: albumId,
|
||||
libraryId: libraryId,
|
||||
tracks: [_trackEntityFixture.Create(albumId: albumId, libraryId: libraryId)]);
|
||||
ArtistEntity artistEntity = _artistEntityFixture.Create(libraryId: libraryId, albums: [albumEntity]);
|
||||
Artist artist = artistEntity.ToDomainEntity().Value;
|
||||
return (artist, artist.Albums.First());
|
||||
}
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicAlbumMetadataDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicAlbumMetadataDtoMappingTests
|
||||
{
|
||||
private readonly MusicAlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.True(metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, metadata.OriginalTitle.Value);
|
||||
Assert.True(metadata.Description.HasValue);
|
||||
Assert.Equal(dto.Description, metadata.Description.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo!.OriginalReleaseDate, metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.OriginalReleaseYear, metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseDate, metadata.ReleaseInfo.ReReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseYear, metadata.ReleaseInfo.ReReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseCountry, metadata.ReleaseInfo.ReleaseCountry.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseVersion, metadata.ReleaseInfo.ReleaseVersion.Value);
|
||||
Assert.True(metadata.Language.HasValue);
|
||||
Assert.Equal(dto.Language!.LanguageCode!.ToLowerInvariant(), metadata.Language.Value.LanguageCode);
|
||||
Assert.Equal(dto.Language.LanguageName, metadata.Language.Value.LanguageName);
|
||||
Assert.Equal(dto.Language.NativeName, metadata.Language.Value.NativeName.Value);
|
||||
Assert.True(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Equal(dto.OriginalLanguage!.LanguageCode!.ToLowerInvariant(), metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(dto.OriginalLanguage.LanguageName, metadata.OriginalLanguage.Value.LanguageName);
|
||||
Assert.Equal(dto.OriginalLanguage.NativeName, metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
Assert.Equal(dto.Genres!.Select(genre => genre.Name), metadata.Genres.Select(genre => genre.Name));
|
||||
Assert.Equal(dto.Tags!.Select(tag => tag.Name), metadata.Tags.Select(tag => tag.Name));
|
||||
Assert.NotEmpty(metadata.ReleaseTypes);
|
||||
Assert.Equal(dto.ReleaseTypes, metadata.ReleaseTypes);
|
||||
Assert.True(metadata.ReleaseStatus.HasValue);
|
||||
Assert.Equal(dto.ReleaseStatus, metadata.ReleaseStatus.Value);
|
||||
Assert.True(metadata.TotalDiscs.HasValue);
|
||||
Assert.Equal(dto.TotalDiscs, metadata.TotalDiscs.Value);
|
||||
Assert.Equal(dto.TotalTracks, metadata.TotalTracks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndDefaults()
|
||||
{
|
||||
// Arrange
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create(
|
||||
includeOriginalTitle: false,
|
||||
includeDescription: false,
|
||||
includeReleaseInfo: false,
|
||||
includeLanguage: false,
|
||||
includeOriginalLanguage: false,
|
||||
includeTags: false,
|
||||
includeGenres: false,
|
||||
includeReleaseTypes: false,
|
||||
includeReleaseStatus: false,
|
||||
includeTotalDiscs: false,
|
||||
includeTotalTracks: false);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.False(metadata.OriginalTitle.HasValue);
|
||||
Assert.False(metadata.Description.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.False(metadata.Language.HasValue);
|
||||
Assert.False(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Empty(metadata.Genres);
|
||||
Assert.Empty(metadata.Tags);
|
||||
Assert.Empty(metadata.ReleaseTypes);
|
||||
Assert.False(metadata.ReleaseStatus.HasValue);
|
||||
Assert.False(metadata.TotalDiscs.HasValue);
|
||||
Assert.Equal(0, metadata.TotalTracks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMissingRequiredSubproperties_ShouldMapLanguageToNone()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto incompleteLanguage = _languageInfoDtoFixture.Create(includeLanguageCode: false);
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create(
|
||||
language: incompleteLanguage,
|
||||
originalLanguage: _languageInfoDtoFixture.Create(includeLanguageName: false));
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto releaseInfo = _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2000, 1, 1),
|
||||
originalReleaseYear: 1999);
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create(releaseInfo: releaseInfo);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.OriginalReleaseDateAndYearMustMatch, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenGenreIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: string.Empty)]);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTagIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicAlbumMetadataDto dto = _albumMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
|
||||
// Act
|
||||
Result<AlbumMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -28,7 +28,7 @@ public class UpdateAlbumCommandMappingTests
|
||||
private readonly UpdateAlbumCommandFixture _updateAlbumCommandFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly AlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly MusicAlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class UpdateAlbumCommandMappingTests
|
||||
Assert.Equal(command.Metadata!.Title, updatedAlbum.Metadata.Title);
|
||||
Assert.Equal(command.MediaFormat, updatedAlbum.MediaFormat.Value);
|
||||
Assert.Equal(command.Barcode, updatedAlbum.Barcode.Value.Value);
|
||||
Assert.Equal(command.CatalogNumber, updatedAlbum.CatalogNumber.Value);
|
||||
Assert.Equal(command.CatalogNumbers, updatedAlbum.CatalogNumbers);
|
||||
Assert.Equal(command.MusicBrainzReleaseId, updatedAlbum.MusicBrainzReleaseId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzReleaseGroupId, updatedAlbum.MusicBrainzReleaseGroupId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzReleaseArtistId, updatedAlbum.MusicBrainzReleaseArtistId.Value.Value);
|
||||
@@ -70,7 +70,7 @@ public class UpdateAlbumCommandMappingTests
|
||||
albumId: albumId.ToString(),
|
||||
includeMediaFormat: false,
|
||||
includeBarcode: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false,
|
||||
@@ -86,7 +86,7 @@ public class UpdateAlbumCommandMappingTests
|
||||
Assert.Equal(command.Metadata!.Title, updatedAlbum.Metadata.Title);
|
||||
Assert.False(updatedAlbum.MediaFormat.HasValue);
|
||||
Assert.False(updatedAlbum.Barcode.HasValue);
|
||||
Assert.False(updatedAlbum.CatalogNumber.HasValue);
|
||||
Assert.Empty(updatedAlbum.CatalogNumbers);
|
||||
Assert.False(updatedAlbum.MusicBrainzReleaseId.HasValue);
|
||||
Assert.False(updatedAlbum.MusicBrainzReleaseGroupId.HasValue);
|
||||
Assert.False(updatedAlbum.MusicBrainzReleaseArtistId.HasValue);
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ public class UpdateAlbumRequestMappingTests
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Equal(request.MediaFormat, result.MediaFormat);
|
||||
Assert.Equal(request.Barcode, result.Barcode);
|
||||
Assert.Equal(request.CatalogNumber, result.CatalogNumber);
|
||||
Assert.Equal(request.CatalogNumbers, result.CatalogNumbers);
|
||||
Assert.Equal(request.MusicBrainzReleaseId, result.MusicBrainzReleaseId);
|
||||
Assert.Equal(request.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(request.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
||||
@@ -52,7 +52,7 @@ public class UpdateAlbumRequestMappingTests
|
||||
UpdateAlbumRequest request = _updateAlbumRequestFixture.Create(
|
||||
includeMediaFormat: false,
|
||||
includeBarcode: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false);
|
||||
@@ -64,7 +64,7 @@ public class UpdateAlbumRequestMappingTests
|
||||
Assert.NotNull(result.Metadata);
|
||||
Assert.Null(result.MediaFormat);
|
||||
Assert.Null(result.Barcode);
|
||||
Assert.Null(result.CatalogNumber);
|
||||
Assert.Null(result.CatalogNumbers);
|
||||
Assert.Null(result.MusicBrainzReleaseId);
|
||||
Assert.Null(result.MusicBrainzReleaseGroupId);
|
||||
Assert.Null(result.MusicBrainzReleaseArtistId);
|
||||
|
||||
+4
-3
@@ -24,7 +24,8 @@ public class AddArtistCommandMappingTests
|
||||
{
|
||||
private readonly AddArtistCommandFixture _addArtistCommandFixture = new();
|
||||
private readonly AddAlbumCommandFixture _addAlbumCommandFixture = new();
|
||||
private readonly AlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly MusicArtistMetadataDtoFixture _musicArtistMetadataDtoFixture = new();
|
||||
private readonly MusicAlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
@@ -41,7 +42,7 @@ public class AddArtistCommandMappingTests
|
||||
Assert.False(result.IsFailure);
|
||||
Artist artist = result.Value;
|
||||
Assert.Equal(libraryId, artist.LibraryId.Value);
|
||||
Assert.Equal(command.Name, artist.Name);
|
||||
Assert.Equal(command.Metadata!.Name, artist.Name);
|
||||
Assert.True(artist.Website.HasValue);
|
||||
Assert.Equal(command.Website, artist.Website.Value);
|
||||
Assert.True(artist.MusicBrainzArtistId.HasValue);
|
||||
@@ -94,7 +95,7 @@ public class AddArtistCommandMappingTests
|
||||
public void ToDomainEntity_WhenArtistNameIsEmpty_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AddArtistCommand command = _addArtistCommandFixture.Create(name: string.Empty);
|
||||
AddArtistCommand command = _addArtistCommandFixture.Create(metadata: _musicArtistMetadataDtoFixture.Create(name: string.Empty));
|
||||
|
||||
// Act
|
||||
Result<Artist> result = command.ToDomainEntity(Guid.NewGuid());
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ public class AddArtistRequestMappingTests
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId.ToString(), result.LibraryId);
|
||||
Assert.Equal(request.Name, result.Name);
|
||||
Assert.Equal(request.Metadata!.Name, result.Metadata!.Name);
|
||||
Assert.Equal(request.Website, result.Website);
|
||||
Assert.Equal(request.MusicBrainzArtistId, result.MusicBrainzArtistId);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
@@ -58,7 +58,7 @@ public class AddArtistRequestMappingTests
|
||||
Assert.Equal(request.Albums[i].Metadata, result.Albums[i].Metadata);
|
||||
Assert.Equal(request.Albums[i].MediaFormat, result.Albums[i].MediaFormat);
|
||||
Assert.Equal(request.Albums[i].Barcode, result.Albums[i].Barcode);
|
||||
Assert.Equal(request.Albums[i].CatalogNumber, result.Albums[i].CatalogNumber);
|
||||
Assert.Equal(request.Albums[i].CatalogNumbers, result.Albums[i].CatalogNumbers);
|
||||
Assert.Equal(request.Albums[i].MusicBrainzReleaseId, result.Albums[i].MusicBrainzReleaseId);
|
||||
Assert.Equal(request.Albums[i].MusicBrainzReleaseGroupId, result.Albums[i].MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(request.Albums[i].MusicBrainzReleaseArtistId, result.Albums[i].MusicBrainzReleaseArtistId);
|
||||
|
||||
+2
-2
@@ -102,7 +102,7 @@ public class ArtistMappingTests
|
||||
Album album = _albumFixture.Create(
|
||||
mediaFormat: Optional<MusicMediaFormat>.None(),
|
||||
barcode: Optional<Barcode>.None(),
|
||||
catalogNumber: Optional<string>.None(),
|
||||
catalogNumbers: [],
|
||||
musicBrainzReleaseId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzReleaseGroupId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzReleaseArtistId: Optional<MusicBrainzId>.None());
|
||||
@@ -122,7 +122,7 @@ public class ArtistMappingTests
|
||||
Assert.Single(result.Albums);
|
||||
Assert.Null(result.Albums[0].MediaFormat);
|
||||
Assert.Null(result.Albums[0].Barcode);
|
||||
Assert.Null(result.Albums[0].CatalogNumber);
|
||||
Assert.Empty(result.Albums[0].CatalogNumbers);
|
||||
Assert.Null(result.Albums[0].MusicBrainzReleaseId);
|
||||
Assert.Null(result.Albums[0].MusicBrainzReleaseGroupId);
|
||||
Assert.Null(result.Albums[0].MusicBrainzReleaseArtistId);
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ArtistMetadataDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistMetadataDtoMappingTests
|
||||
{
|
||||
private readonly ArtistMetadataDtoFixture _artistMetadataDtoFixture = new();
|
||||
private readonly MusicAreaDtoFixture _musicAreaDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly MusicMediaContributorFixture _musicMediaContributorFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenMappingCompleteDto_ShouldApplyAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Artist artist = CreateDomainArtist();
|
||||
ArtistMetadataDto dto = _artistMetadataDtoFixture.Create();
|
||||
List<MusicMediaContributor> contributors = _musicMediaContributorFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, contributors);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(dto.Name, artist.Name);
|
||||
Assert.True(artist.SortName.HasValue);
|
||||
Assert.Equal(dto.SortName, artist.SortName.Value);
|
||||
Assert.True(artist.Disambiguation.HasValue);
|
||||
Assert.Equal(dto.Disambiguation, artist.Disambiguation.Value);
|
||||
Assert.True(artist.Country.HasValue);
|
||||
Assert.Equal(dto.Country, artist.Country.Value);
|
||||
Assert.True(artist.Area.HasValue);
|
||||
Assert.Equal(dto.Area!.Name, artist.Area.Value.Name);
|
||||
Assert.True(artist.BeginArea.HasValue);
|
||||
Assert.True(artist.EndArea.HasValue);
|
||||
Assert.True(artist.LifeSpanBegin.HasValue);
|
||||
Assert.Equal(dto.LifeSpanBegin, artist.LifeSpanBegin.Value);
|
||||
Assert.True(artist.LifeSpanEnd.HasValue);
|
||||
Assert.Equal(dto.LifeSpanEnd, artist.LifeSpanEnd.Value);
|
||||
Assert.Equal(dto.IsEnded, artist.IsEnded);
|
||||
Assert.True(artist.Website.HasValue);
|
||||
Assert.Equal(dto.Website, artist.Website.Value);
|
||||
Assert.True(artist.MusicBrainzArtistId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzArtistId, artist.MusicBrainzArtistId.Value.Value);
|
||||
Assert.Equal(dto.Ipis!.Count, artist.Ipis.Count);
|
||||
Assert.Equal(dto.Isnis!.Count, artist.Isnis.Count);
|
||||
Assert.Equal(dto.Aliases!.Count, artist.Aliases.Count);
|
||||
Assert.Equal(dto.Genres!.Count, artist.Genres.Count);
|
||||
Assert.Equal(dto.Tags!.Count, artist.Tags.Count);
|
||||
Assert.Equal(dto.Ratings!.Count, artist.Ratings.Count);
|
||||
Assert.Equal(contributors.Count, artist.Contributors.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenNameAndWebsiteAreMissing_ShouldPreserveTheStoredValues()
|
||||
{
|
||||
// Arrange
|
||||
Artist artist = CreateDomainArtist();
|
||||
string storedName = artist.Name;
|
||||
bool hadStoredWebsite = artist.Website.HasValue;
|
||||
string? storedWebsite = artist.Website.HasValue ? artist.Website.Value : null;
|
||||
ArtistMetadataDto dto = _artistMetadataDtoFixture.Create(includeName: false, includeWebsite: false);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(storedName, artist.Name);
|
||||
Assert.Equal(hadStoredWebsite, artist.Website.HasValue);
|
||||
if (hadStoredWebsite)
|
||||
Assert.Equal(storedWebsite, artist.Website.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenAreaIsMissingItsIdentifier_ShouldMapTheAreaToNone()
|
||||
{
|
||||
// Arrange
|
||||
Artist artist = CreateDomainArtist();
|
||||
ArtistMetadataDto dto = _artistMetadataDtoFixture.Create(area: _musicAreaDtoFixture.Create(includeMusicBrainzAreaId: false));
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(artist.Area.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenGenreIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Artist artist = CreateDomainArtist();
|
||||
ArtistMetadataDto dto = _artistMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: string.Empty)]);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, []);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track.
|
||||
/// </summary>
|
||||
/// <returns>The created domain artist.</returns>
|
||||
private Artist CreateDomainArtist()
|
||||
{
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid albumId = Guid.NewGuid();
|
||||
AlbumEntity albumEntity = _albumEntityFixture.Create(
|
||||
id: albumId,
|
||||
libraryId: libraryId,
|
||||
tracks: [_trackEntityFixture.Create(albumId: albumId, libraryId: libraryId)]);
|
||||
ArtistEntity artistEntity = _artistEntityFixture.Create(libraryId: libraryId, albums: [albumEntity]);
|
||||
return artistEntity.ToDomainEntity().Value;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -38,7 +38,7 @@ public class UpdateArtistAlbumRequestMappingTests
|
||||
Assert.Equal(request.Metadata, result.Metadata);
|
||||
Assert.Equal(request.MediaFormat, result.MediaFormat);
|
||||
Assert.Equal(request.Barcode, result.Barcode);
|
||||
Assert.Equal(request.CatalogNumber, result.CatalogNumber);
|
||||
Assert.Equal(request.CatalogNumbers, result.CatalogNumbers);
|
||||
Assert.Equal(request.MusicBrainzReleaseId, result.MusicBrainzReleaseId);
|
||||
Assert.Equal(request.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(request.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
||||
@@ -84,7 +84,7 @@ public class UpdateArtistAlbumRequestMappingTests
|
||||
includeAlbumId: false,
|
||||
includeMediaFormat: false,
|
||||
includeBarcode: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false,
|
||||
@@ -98,7 +98,7 @@ public class UpdateArtistAlbumRequestMappingTests
|
||||
Assert.Null(result.AlbumId);
|
||||
Assert.Null(result.MediaFormat);
|
||||
Assert.Null(result.Barcode);
|
||||
Assert.Null(result.CatalogNumber);
|
||||
Assert.Null(result.CatalogNumbers);
|
||||
Assert.Null(result.MusicBrainzReleaseId);
|
||||
Assert.Null(result.MusicBrainzReleaseGroupId);
|
||||
Assert.Null(result.MusicBrainzReleaseArtistId);
|
||||
|
||||
+4
-4
@@ -33,7 +33,8 @@ public class UpdateArtistCommandMappingTests
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly AlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly MusicAlbumMetadataDtoFixture _albumMetadataDtoFixture = new();
|
||||
private readonly MusicArtistMetadataDtoFixture _musicArtistMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
@@ -56,7 +57,7 @@ public class UpdateArtistCommandMappingTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Same(artist, result.Value);
|
||||
Assert.Equal(command.Name, result.Value.Name);
|
||||
Assert.Equal(command.Metadata!.Name, result.Value.Name);
|
||||
Assert.True(result.Value.Website.HasValue);
|
||||
Assert.Equal(command.Website, result.Value.Website.Value);
|
||||
Assert.True(result.Value.MusicBrainzArtistId.HasValue);
|
||||
@@ -90,7 +91,6 @@ public class UpdateArtistCommandMappingTests
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false,
|
||||
includeMoods: false,
|
||||
includeIsrcs: false,
|
||||
contributors: [],
|
||||
@@ -134,7 +134,7 @@ public class UpdateArtistCommandMappingTests
|
||||
UpdateArtistCommand command = _updateArtistCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
artistId: artist.Id.Value.ToString(),
|
||||
name: string.Empty,
|
||||
metadata: _musicArtistMetadataDtoFixture.Create(name: string.Empty),
|
||||
albums: [albumCommand]);
|
||||
|
||||
// Act
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class UpdateArtistRequestMappingTests
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId.ToString(), result.LibraryId);
|
||||
Assert.Equal(artistId.ToString(), result.ArtistId);
|
||||
Assert.Equal(request.Name, result.Name);
|
||||
Assert.Equal(request.Metadata!.Name, result.Metadata!.Name);
|
||||
Assert.Equal(request.Website, result.Website);
|
||||
Assert.Equal(request.MusicBrainzArtistId, result.MusicBrainzArtistId);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
|
||||
+1
-4
@@ -19,7 +19,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.
|
||||
public class UpdateArtistTrackRequestMappingTests
|
||||
{
|
||||
private readonly UpdateArtistTrackRequestFixture _updateArtistTrackRequestFixture = new();
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -48,7 +48,6 @@ public class UpdateArtistTrackRequestMappingTests
|
||||
Assert.Equal(request.Work, result.Work);
|
||||
Assert.Equal(request.MusicBrainzRecordingId, result.MusicBrainzRecordingId);
|
||||
Assert.Equal(request.MusicBrainzTrackId, result.MusicBrainzTrackId);
|
||||
Assert.Equal(request.MusicBrainzWorkId, result.MusicBrainzWorkId);
|
||||
Assert.Equal(request.Moods, result.Moods);
|
||||
Assert.Equal(request.Isrcs, result.Isrcs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
@@ -70,7 +69,6 @@ public class UpdateArtistTrackRequestMappingTests
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false,
|
||||
includeMoods: false,
|
||||
includeIsrcs: false,
|
||||
includeTrackId: false);
|
||||
@@ -89,7 +87,6 @@ public class UpdateArtistTrackRequestMappingTests
|
||||
Assert.Null(result.Work);
|
||||
Assert.Null(result.MusicBrainzRecordingId);
|
||||
Assert.Null(result.MusicBrainzTrackId);
|
||||
Assert.Null(result.MusicBrainzWorkId);
|
||||
Assert.Null(result.Moods);
|
||||
Assert.Null(result.Isrcs);
|
||||
Assert.Null(result.TrackId);
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ArtistAliasEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistAliasEntityMappingTests
|
||||
{
|
||||
private readonly ArtistAliasEntityFixture _artistAliasEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidArtistAliasEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ArtistAliasEntity entity = _artistAliasEntityFixture.Create(name: "Freddie Mercury", isPrimary: true);
|
||||
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Freddie Mercury", result.Value.Name);
|
||||
Assert.True(result.Value.IsPrimary);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainValueObject_WhenNameIsEmpty_ShouldReturnError(string name)
|
||||
{
|
||||
// Arrange
|
||||
ArtistAliasEntity entity = _artistAliasEntityFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<ArtistAliasEntity> entities = _artistAliasEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
Result<List<MusicArtistAlias>> result = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(entities.Count, result.Value.Count);
|
||||
for (int index = 0; index < entities.Count; index++)
|
||||
Assert.Equal(entities[index].Name, result.Value[index].Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenAnEntityIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
List<ArtistAliasEntity> entities =
|
||||
[
|
||||
_artistAliasEntityFixture.Create(name: "Freddie Mercury"),
|
||||
_artistAliasEntityFixture.Create(name: string.Empty)
|
||||
];
|
||||
|
||||
// Act
|
||||
Result<List<MusicArtistAlias>> result = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -21,13 +21,13 @@ public class AudioRatingDtoMappingTests
|
||||
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteAudioRatingDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingCompleteAudioRatingDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingDto dto = _audioRatingDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = dto.ToDomainEntity();
|
||||
Result<AudioRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -41,13 +41,13 @@ public class AudioRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndNones()
|
||||
public void ToDomainValueObject_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndNones()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingDto dto = _audioRatingDtoFixture.Create(includeSource: false, includeVoteCount: false);
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = dto.ToDomainEntity();
|
||||
Result<AudioRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -58,13 +58,13 @@ public class AudioRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenValueIsGreaterThanMaxValue_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenValueIsGreaterThanMaxValue_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingDto dto = _audioRatingDtoFixture.Create(value: 10, maxValue: 5);
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = dto.ToDomainEntity();
|
||||
Result<AudioRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -72,13 +72,13 @@ public class AudioRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidAudioRatingDtos_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidAudioRatingDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<AudioRatingDto> dtos = _audioRatingDtoFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<AudioRating>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<AudioRating>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
@@ -91,7 +91,7 @@ public class AudioRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidAudioRatingDtos_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidAudioRatingDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<AudioRatingDto> dtos =
|
||||
@@ -102,7 +102,7 @@ public class AudioRatingDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<AudioRating>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<AudioRating>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
|
||||
+10
-10
@@ -75,13 +75,13 @@ public class AudioRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidAudioRatingEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidAudioRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingEntity entity = _audioRatingEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = entity.ToDomainEntity();
|
||||
Result<AudioRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -95,13 +95,13 @@ public class AudioRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingAudioRatingEntityWithNulls_ShouldMapToDefaults()
|
||||
public void ToDomainValueObject_WhenMappingAudioRatingEntityWithNulls_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingEntity entity = _audioRatingEntityFixture.Create(includeValue: false, includeMaxValue: false, includeSource: false, includeVoteCount: false);
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = entity.ToDomainEntity();
|
||||
Result<AudioRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -112,13 +112,13 @@ public class AudioRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenValueIsGreaterThanMaxValue_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenValueIsGreaterThanMaxValue_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AudioRatingEntity entity = _audioRatingEntityFixture.Create(value: 6, maxValue: 5, source: AudioRatingSource.MusicBrainz, voteCount: 10);
|
||||
|
||||
// Act
|
||||
Result<AudioRating> result = entity.ToDomainEntity();
|
||||
Result<AudioRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -126,13 +126,13 @@ public class AudioRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidAudioRatingEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidAudioRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<AudioRatingEntity> entities = _audioRatingEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<AudioRating>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<AudioRating>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
@@ -145,7 +145,7 @@ public class AudioRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidAudioRatingEntities_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidAudioRatingEntities_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<AudioRatingEntity> entities =
|
||||
@@ -156,7 +156,7 @@ public class AudioRatingEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<AudioRating>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<AudioRating>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
|
||||
+12
-12
@@ -21,13 +21,13 @@ public class IsrcDtoMappingTests
|
||||
private readonly IsrcDtoFixture _isrcDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsrcDto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidIsrcDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsrcDto dto = _isrcDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = dto.ToDomainEntity();
|
||||
Result<Isrc> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -36,13 +36,13 @@ public class IsrcDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingLowercaseIsrcDto_ShouldNormalizeTheValue()
|
||||
public void ToDomainValueObject_WhenMappingLowercaseIsrcDto_ShouldNormalizeTheValue()
|
||||
{
|
||||
// Arrange
|
||||
IsrcDto dto = _isrcDtoFixture.Create(value: "gbum71029604");
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = dto.ToDomainEntity();
|
||||
Result<Isrc> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -53,13 +53,13 @@ public class IsrcDtoMappingTests
|
||||
[InlineData(null)] // missing value
|
||||
[InlineData("")] // empty value
|
||||
[InlineData(" ")] // whitespace value
|
||||
public void ToDomainEntity_WhenValueIsNullOrWhitespace_ShouldReturnError(string? value)
|
||||
public void ToDomainValueObject_WhenValueIsNullOrWhitespace_ShouldReturnError(string? value)
|
||||
{
|
||||
// Arrange
|
||||
IsrcDto dto = _isrcDtoFixture.Create(value: value, includeValue: value is not null);
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = dto.ToDomainEntity();
|
||||
Result<Isrc> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -72,13 +72,13 @@ public class IsrcDtoMappingTests
|
||||
[InlineData("GBUM71029604X")] // too long
|
||||
[InlineData("1BUM71029604")] // country code is not two letters
|
||||
[InlineData("GBUM7102960A")] // designation code is not all digits
|
||||
public void ToDomainEntity_WhenValueIsMalformed_ShouldReturnError(string value)
|
||||
public void ToDomainValueObject_WhenValueIsMalformed_ShouldReturnError(string value)
|
||||
{
|
||||
// Arrange
|
||||
IsrcDto dto = _isrcDtoFixture.Create(value: value);
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = dto.ToDomainEntity();
|
||||
Result<Isrc> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -86,13 +86,13 @@ public class IsrcDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidIsrcDtos_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidIsrcDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsrcDto> dtos = _isrcDtoFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<Isrc>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<Isrc>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
@@ -104,7 +104,7 @@ public class IsrcDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidIsrcDtos_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidIsrcDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<IsrcDto> dtos =
|
||||
@@ -115,7 +115,7 @@ public class IsrcDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<Isrc>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<Isrc>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
|
||||
+10
-10
@@ -51,13 +51,13 @@ public class IsrcEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTrackIsrcEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidTrackIsrcEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TrackIsrcEntity entity = _trackIsrcEntityFixture.Create(value: "GBUM71029604");
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = entity.ToDomainEntity();
|
||||
Result<Isrc> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -68,13 +68,13 @@ public class IsrcEntityMappingTests
|
||||
[Theory]
|
||||
[InlineData("")] // empty value
|
||||
[InlineData(" ")] // whitespace value
|
||||
public void ToDomainEntity_WhenValueIsWhitespace_ShouldReturnError(string value)
|
||||
public void ToDomainValueObject_WhenValueIsWhitespace_ShouldReturnError(string value)
|
||||
{
|
||||
// Arrange
|
||||
TrackIsrcEntity entity = _trackIsrcEntityFixture.Create(value: value);
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = entity.ToDomainEntity();
|
||||
Result<Isrc> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -82,13 +82,13 @@ public class IsrcEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenValueIsMalformed_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenValueIsMalformed_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
TrackIsrcEntity entity = _trackIsrcEntityFixture.Create(value: "not-an-isrc");
|
||||
|
||||
// Act
|
||||
Result<Isrc> result = entity.ToDomainEntity();
|
||||
Result<Isrc> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -96,13 +96,13 @@ public class IsrcEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidTrackIsrcEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidTrackIsrcEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TrackIsrcEntity> entities = _trackIsrcEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<Isrc>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<Isrc>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
@@ -114,7 +114,7 @@ public class IsrcEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidTrackIsrcEntities_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidTrackIsrcEntities_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<TrackIsrcEntity> entities =
|
||||
@@ -125,7 +125,7 @@ public class IsrcEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<Isrc>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<Isrc>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
|
||||
+8
-8
@@ -21,13 +21,13 @@ public class MoodDtoMappingTests
|
||||
private readonly MoodDtoFixture _moodDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidMoodDto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidMoodDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MoodDto dto = _moodDtoFixture.Create(name: " Calm ");
|
||||
|
||||
// Act
|
||||
Result<Mood> result = dto.ToDomainEntity();
|
||||
Result<Mood> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -39,13 +39,13 @@ public class MoodDtoMappingTests
|
||||
[InlineData(null)] // missing name
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainEntity_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name)
|
||||
public void ToDomainValueObject_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name)
|
||||
{
|
||||
// Arrange
|
||||
MoodDto dto = _moodDtoFixture.Create(name: name, includeName: name is not null);
|
||||
|
||||
// Act
|
||||
Result<Mood> result = dto.ToDomainEntity();
|
||||
Result<Mood> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -53,13 +53,13 @@ public class MoodDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidMoodDtos_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidMoodDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<MoodDto> dtos = _moodDtoFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<Mood>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<Mood>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
@@ -71,7 +71,7 @@ public class MoodDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidMoodDtos_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidMoodDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<MoodDto> dtos =
|
||||
@@ -82,7 +82,7 @@ public class MoodDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<Mood>> results = [.. dtos.ToDomainEntities()];
|
||||
List<Result<Mood>> results = [.. dtos.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(dtos.Count, results.Count);
|
||||
|
||||
+8
-8
@@ -51,13 +51,13 @@ public class MoodEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTrackMoodEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidTrackMoodEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TrackMoodEntity entity = _trackMoodEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Mood> result = entity.ToDomainEntity();
|
||||
Result<Mood> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -68,13 +68,13 @@ public class MoodEntityMappingTests
|
||||
[Theory]
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainEntity_WhenNameIsWhitespace_ShouldReturnError(string name)
|
||||
public void ToDomainValueObject_WhenNameIsWhitespace_ShouldReturnError(string name)
|
||||
{
|
||||
// Arrange
|
||||
TrackMoodEntity entity = _trackMoodEntityFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<Mood> result = entity.ToDomainEntity();
|
||||
Result<Mood> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -82,13 +82,13 @@ public class MoodEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidTrackMoodEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidTrackMoodEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TrackMoodEntity> entities = _trackMoodEntityFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<Result<Mood>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<Mood>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
@@ -100,7 +100,7 @@ public class MoodEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMixedValidAndInvalidTrackMoodEntities_ShouldReturnMixedResults()
|
||||
public void ToDomainValueObjects_WhenMappingMixedValidAndInvalidTrackMoodEntities_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<TrackMoodEntity> entities =
|
||||
@@ -111,7 +111,7 @@ public class MoodEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<Result<Mood>> results = [.. entities.ToDomainEntities()];
|
||||
List<Result<Mood>> results = [.. entities.ToDomainValueObjects()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(entities.Count, results.Count);
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicAreaDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicAreaDtoMappingTests
|
||||
{
|
||||
private readonly MusicAreaDtoFixture _musicAreaDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidMusicAreaDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaDto dto = _musicAreaDtoFixture.Create(name: "United Kingdom", iso3166Code: "GB");
|
||||
|
||||
// Act
|
||||
Result<Optional<MusicArea>> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.HasValue);
|
||||
MusicArea area = result.Value.Value;
|
||||
Assert.Equal(dto.MusicBrainzAreaId, area.MusicBrainzAreaId.Value);
|
||||
Assert.Equal("United Kingdom", area.Name);
|
||||
Assert.Equal("GB", area.Iso3166Code.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenAreaDtoIsNull_ShouldReturnNoArea()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaDto? dto = null;
|
||||
|
||||
// Act
|
||||
Result<Optional<MusicArea>> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMusicBrainzAreaIdIsMissing_ShouldReturnNoArea()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaDto dto = _musicAreaDtoFixture.Create(includeMusicBrainzAreaId: false);
|
||||
|
||||
// Act
|
||||
Result<Optional<MusicArea>> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.HasValue);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // missing name
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainValueObject_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name)
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaDto dto = _musicAreaDtoFixture.Create(name: name, includeName: name is not null);
|
||||
|
||||
// Act
|
||||
Result<Optional<MusicArea>> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.AreaNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicAreaEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicAreaEntityMappingTests
|
||||
{
|
||||
private readonly MusicAreaEntityFixture _musicAreaEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidMusicAreaEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaEntity entity = _musicAreaEntityFixture.Create(name: "United Kingdom", iso3166Code: "GB");
|
||||
|
||||
// Act
|
||||
Result<MusicArea> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(entity.MusicBrainzAreaId, result.Value.MusicBrainzAreaId.Value);
|
||||
Assert.Equal("United Kingdom", result.Value.Name);
|
||||
Assert.Equal("GB", result.Value.Iso3166Code.Value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainValueObject_WhenNameIsEmpty_ShouldReturnError(string name)
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaEntity entity = _musicAreaEntityFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<MusicArea> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.AreaNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenEntityIsNull_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaEntity? entity = null;
|
||||
|
||||
// Act
|
||||
MusicAreaDto? result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicAreaEntity entity = _musicAreaEntityFixture.Create(name: "United Kingdom", iso3166Code: "GB");
|
||||
|
||||
// Act
|
||||
MusicAreaDto? result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entity.MusicBrainzAreaId, result!.MusicBrainzAreaId);
|
||||
Assert.Equal("United Kingdom", result.Name);
|
||||
Assert.Equal("GB", result.Iso3166Code);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicAreaMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicAreaMappingTests
|
||||
{
|
||||
private readonly MusicAreaFixture _musicAreaFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidMusicArea_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicArea area = _musicAreaFixture.Create(name: "United Kingdom", iso3166Code: Optional<string>.Some("GB"));
|
||||
|
||||
// Act
|
||||
MusicAreaEntity result = area.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(area.MusicBrainzAreaId.Value, result.MusicBrainzAreaId);
|
||||
Assert.Equal("United Kingdom", result.Name);
|
||||
Assert.Equal("GB", result.Iso3166Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenOptionalValuesAreAbsent_ShouldMapThemToNull()
|
||||
{
|
||||
// Arrange
|
||||
MusicArea area = _musicAreaFixture.Create(
|
||||
sortName: Optional<string>.None(),
|
||||
disambiguation: Optional<string>.None(),
|
||||
type: Optional<string>.None(),
|
||||
iso3166Code: Optional<string>.None());
|
||||
|
||||
// Act
|
||||
MusicAreaEntity result = area.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.SortName);
|
||||
Assert.Null(result.Disambiguation);
|
||||
Assert.Null(result.Type);
|
||||
Assert.Null(result.Iso3166Code);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicArtistAliasDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicArtistAliasDtoMappingTests
|
||||
{
|
||||
private readonly MusicArtistAliasDtoFixture _musicArtistAliasDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObject_WhenMappingValidMusicArtistAliasDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAliasDto dto = _musicArtistAliasDtoFixture.Create(name: "Freddie Mercury", isPrimary: true);
|
||||
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Freddie Mercury", result.Value.Name);
|
||||
Assert.True(result.Value.IsPrimary);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // missing name
|
||||
[InlineData("")] // empty name
|
||||
[InlineData(" ")] // whitespace name
|
||||
public void ToDomainValueObject_WhenNameIsNullOrWhitespace_ShouldReturnError(string? name)
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAliasDto dto = _musicArtistAliasDtoFixture.Create(name: name, includeName: name is not null);
|
||||
|
||||
// Act
|
||||
Result<MusicArtistAlias> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidAliasDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<MusicArtistAliasDto> dtos = _musicArtistAliasDtoFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
Result<List<MusicArtistAlias>> result = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(dtos.Count, result.Value.Count);
|
||||
for (int index = 0; index < dtos.Count; index++)
|
||||
Assert.Equal(dtos[index].Name, result.Value[index].Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenAliasDtosIsNull_ShouldReturnAnEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<MusicArtistAliasDto>? dtos = null;
|
||||
|
||||
// Act
|
||||
Result<List<MusicArtistAlias>> result = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainValueObjects_WhenAnAliasIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
List<MusicArtistAliasDto> dtos =
|
||||
[
|
||||
_musicArtistAliasDtoFixture.Create(name: "Freddie Mercury"),
|
||||
_musicArtistAliasDtoFixture.Create(name: string.Empty, includeName: true)
|
||||
];
|
||||
|
||||
// Act
|
||||
Result<List<MusicArtistAlias>> result = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.ArtistAliasNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicArtistAliasMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicArtistAliasMappingTests
|
||||
{
|
||||
private readonly MusicArtistAliasFixture _musicArtistAliasFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidMusicArtistAlias_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAlias alias = _musicArtistAliasFixture.Create(name: "Freddie Mercury", isPrimary: true);
|
||||
|
||||
// Act
|
||||
ArtistAliasEntity result = alias.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Freddie Mercury", result.Name);
|
||||
Assert.True(result.IsPrimary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenOptionalValuesAreAbsent_ShouldMapThemToNull()
|
||||
{
|
||||
// Arrange
|
||||
MusicArtistAlias alias = _musicArtistAliasFixture.Create(
|
||||
sortName: Optional<string>.None(),
|
||||
type: Optional<string>.None(),
|
||||
locale: Optional<string>.None(),
|
||||
beginDate: Optional<System.DateOnly>.None(),
|
||||
endDate: Optional<System.DateOnly>.None());
|
||||
|
||||
// Act
|
||||
ArtistAliasEntity result = alias.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.SortName);
|
||||
Assert.Null(result.Type);
|
||||
Assert.Null(result.Locale);
|
||||
Assert.Null(result.BeginDate);
|
||||
Assert.Null(result.EndDate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleAliases_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<MusicArtistAlias> aliases = _musicArtistAliasFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
List<ArtistAliasEntity> result = aliases.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(aliases.Count, result.Count);
|
||||
for (int index = 0; index < aliases.Count; index++)
|
||||
Assert.Equal(aliases[index].Name, result[index].Name);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -23,7 +23,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.
|
||||
public class AddTrackCommandMappingTests
|
||||
{
|
||||
private readonly AddTrackCommandFixture _addTrackCommandFixture = new();
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly MoodDtoFixture _moodDtoFixture = new();
|
||||
private readonly IsrcDtoFixture _isrcDtoFixture = new();
|
||||
@@ -47,10 +47,10 @@ public class AddTrackCommandMappingTests
|
||||
Assert.Equal(command.Script, result.Value.Script.Value);
|
||||
Assert.Equal(command.Key, result.Value.Key.Value);
|
||||
Assert.Equal(command.Bpm, result.Value.Bpm.Value);
|
||||
Assert.Equal(command.Work, result.Value.Work.Value);
|
||||
Assert.Equal(command.Work!.Title, result.Value.Work.Value.Title);
|
||||
Assert.Equal(command.MusicBrainzRecordingId, result.Value.MusicBrainzRecordingId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzTrackId, result.Value.MusicBrainzTrackId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzWorkId, result.Value.MusicBrainzWorkId.Value.Value);
|
||||
Assert.Equal(command.Work!.MusicBrainzWorkId, result.Value.Work.Value.MusicBrainzWorkId.Value);
|
||||
Assert.Equal(command.Moods!.Count, result.Value.Moods.Count);
|
||||
Assert.Equal(command.Isrcs!.Count, result.Value.Isrcs.Count);
|
||||
Assert.Equal(command.Contributors!.Count, result.Value.Contributors.Count);
|
||||
|
||||
+1
-4
@@ -19,7 +19,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.
|
||||
public class AddTrackRequestMappingTests
|
||||
{
|
||||
private readonly AddTrackRequestFixture _addTrackRequestFixture = new();
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -48,7 +48,6 @@ public class AddTrackRequestMappingTests
|
||||
Assert.Equal(request.Work, result.Work);
|
||||
Assert.Equal(request.MusicBrainzRecordingId, result.MusicBrainzRecordingId);
|
||||
Assert.Equal(request.MusicBrainzTrackId, result.MusicBrainzTrackId);
|
||||
Assert.Equal(request.MusicBrainzWorkId, result.MusicBrainzWorkId);
|
||||
Assert.Equal(request.Moods, result.Moods);
|
||||
Assert.Equal(request.Isrcs, result.Isrcs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
@@ -70,7 +69,6 @@ public class AddTrackRequestMappingTests
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false,
|
||||
includeMoods: false,
|
||||
includeIsrcs: false);
|
||||
|
||||
@@ -88,7 +86,6 @@ public class AddTrackRequestMappingTests
|
||||
Assert.Null(result.Work);
|
||||
Assert.Null(result.MusicBrainzRecordingId);
|
||||
Assert.Null(result.MusicBrainzTrackId);
|
||||
Assert.Null(result.MusicBrainzWorkId);
|
||||
Assert.Null(result.Moods);
|
||||
Assert.Null(result.Isrcs);
|
||||
}
|
||||
|
||||
+78
-126
@@ -1,13 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -21,167 +26,114 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.
|
||||
public class AudioMetadataDtoMappingTests
|
||||
{
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly MusicMediaContributorFixture _musicMediaContributorFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ApplyTo_WhenMappingCompleteDto_ShouldApplyAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album, Track track) = CreateDomainArtist();
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create();
|
||||
List<MusicMediaContributor> contributors = _musicMediaContributorFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, track, contributors);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AudioMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.True(metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, metadata.OriginalTitle.Value);
|
||||
Assert.True(metadata.Description.HasValue);
|
||||
Assert.Equal(dto.Description, metadata.Description.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo!.OriginalReleaseDate, metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.OriginalReleaseYear, metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseDate, metadata.ReleaseInfo.ReReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseYear, metadata.ReleaseInfo.ReReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseCountry, metadata.ReleaseInfo.ReleaseCountry.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseVersion, metadata.ReleaseInfo.ReleaseVersion.Value);
|
||||
Assert.True(metadata.Language.HasValue);
|
||||
Assert.Equal(dto.Language!.LanguageCode!.ToLowerInvariant(), metadata.Language.Value.LanguageCode);
|
||||
Assert.Equal(dto.Language.LanguageName, metadata.Language.Value.LanguageName);
|
||||
Assert.Equal(dto.Language.NativeName, metadata.Language.Value.NativeName.Value);
|
||||
Assert.True(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Equal(dto.OriginalLanguage!.LanguageCode!.ToLowerInvariant(), metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(dto.OriginalLanguage.LanguageName, metadata.OriginalLanguage.Value.LanguageName);
|
||||
Assert.Equal(dto.OriginalLanguage.NativeName, metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
Assert.Equal(dto.DurationInSeconds, metadata.DurationInSeconds);
|
||||
Assert.Equal(dto.SampleRate, metadata.SampleRate);
|
||||
Assert.Equal(dto.Channels, metadata.Channels);
|
||||
Assert.True(metadata.BitDepth.HasValue);
|
||||
Assert.Equal(dto.BitDepth, metadata.BitDepth.Value);
|
||||
Assert.True(metadata.AudioCodec.HasValue);
|
||||
Assert.Equal(dto.AudioCodec, metadata.AudioCodec.Value);
|
||||
Assert.True(metadata.Bitrate.HasValue);
|
||||
Assert.Equal(dto.Bitrate, metadata.Bitrate.Value);
|
||||
Assert.Equal(dto.Genres!.Select(genre => genre.Name), metadata.Genres.Select(genre => genre.Name));
|
||||
Assert.Equal(dto.Tags!.Select(tag => tag.Name), metadata.Tags.Select(tag => tag.Name));
|
||||
Assert.Equal(dto.Title, track.Metadata.Title);
|
||||
Assert.Equal(dto.DurationInSeconds, track.Metadata.DurationInSeconds);
|
||||
Assert.Equal(dto.SampleRate, track.Metadata.SampleRate);
|
||||
Assert.Equal(dto.Channels, track.Metadata.Channels);
|
||||
Assert.Equal(dto.BitDepth, track.Metadata.BitDepth.Value);
|
||||
Assert.Equal(dto.AudioCodec, track.Metadata.AudioCodec.Value);
|
||||
Assert.Equal(dto.Bitrate, track.Metadata.Bitrate.Value);
|
||||
Assert.True(track.Script.HasValue);
|
||||
Assert.Equal(dto.Script, track.Script.Value);
|
||||
Assert.True(track.Key.HasValue);
|
||||
Assert.Equal(dto.Key, track.Key.Value);
|
||||
Assert.True(track.Bpm.HasValue);
|
||||
Assert.Equal(dto.Bpm, track.Bpm.Value);
|
||||
Assert.Equal(dto.IsVideo, track.IsVideo);
|
||||
Assert.True(track.Work.HasValue);
|
||||
Assert.Equal(dto.Work!.MusicBrainzWorkId, track.Work.Value.MusicBrainzWorkId.Value);
|
||||
Assert.Equal(dto.Isrcs!.Count, track.Isrcs.Count);
|
||||
Assert.Equal(dto.Moods!.Count, track.Moods.Count);
|
||||
Assert.True(track.MusicBrainzRecordingId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzRecordingId, track.MusicBrainzRecordingId.Value.Value);
|
||||
Assert.True(track.MusicBrainzTrackId.HasValue);
|
||||
Assert.Equal(dto.MusicBrainzTrackId, track.MusicBrainzTrackId.Value.Value);
|
||||
Assert.Equal(contributors.Count, track.Contributors.Count);
|
||||
Assert.Equal(dto.Ratings!.Count, track.Ratings.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndDefaults()
|
||||
public void ApplyTo_WhenProviderFieldsAreMissing_ShouldPreserveTheLocallyExtractedValues()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album, Track track) = CreateDomainArtist();
|
||||
int storedDuration = track.Metadata.DurationInSeconds;
|
||||
int storedSampleRate = track.Metadata.SampleRate;
|
||||
int storedChannels = track.Metadata.Channels;
|
||||
bool hadStoredWork = track.Work.HasValue;
|
||||
int storedIsrcCount = track.Isrcs.Count;
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(
|
||||
includeOriginalTitle: false,
|
||||
includeDescription: false,
|
||||
includeReleaseInfo: false,
|
||||
includeLanguage: false,
|
||||
includeOriginalLanguage: false,
|
||||
includeTags: false,
|
||||
includeGenres: false,
|
||||
includeDurationInSeconds: false,
|
||||
includeSampleRate: false,
|
||||
includeChannels: false,
|
||||
includeBitDepth: false,
|
||||
includeAudioCodec: false,
|
||||
includeBitrate: false);
|
||||
includeBitrate: false,
|
||||
includeWork: false,
|
||||
includeIsrcs: false,
|
||||
includeMoods: false);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, track, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AudioMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.False(metadata.OriginalTitle.HasValue);
|
||||
Assert.False(metadata.Description.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(0, metadata.DurationInSeconds);
|
||||
Assert.Equal(0, metadata.SampleRate);
|
||||
Assert.Equal(0, metadata.Channels);
|
||||
Assert.False(metadata.BitDepth.HasValue);
|
||||
Assert.False(metadata.AudioCodec.HasValue);
|
||||
Assert.False(metadata.Bitrate.HasValue);
|
||||
Assert.False(metadata.Language.HasValue);
|
||||
Assert.False(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Empty(metadata.Genres);
|
||||
Assert.Empty(metadata.Tags);
|
||||
Assert.Equal(storedDuration, track.Metadata.DurationInSeconds);
|
||||
Assert.Equal(storedSampleRate, track.Metadata.SampleRate);
|
||||
Assert.Equal(storedChannels, track.Metadata.Channels);
|
||||
Assert.Equal(hadStoredWork, track.Work.HasValue);
|
||||
Assert.Equal(storedIsrcCount, track.Isrcs.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMissingRequiredSubproperties_ShouldMapLanguageToNone()
|
||||
public void ApplyTo_WhenTrackDoesNotBelongToAlbum_ShouldReturnTrackNotFound()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto incompleteLanguage = _languageInfoDtoFixture.Create(includeLanguageCode: false);
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(
|
||||
language: incompleteLanguage,
|
||||
originalLanguage: _languageInfoDtoFixture.Create(includeLanguageName: false));
|
||||
(Artist artist, Album album, Track _) = CreateDomainArtist();
|
||||
(Artist _, Album _, Track foreignTrack) = CreateDomainArtist();
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto releaseInfo = _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2000, 1, 1),
|
||||
originalReleaseYear: 1999);
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(releaseInfo: releaseInfo);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, foreignTrack, []);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.OriginalReleaseDateAndYearMustMatch, result.FirstError);
|
||||
Assert.Equal(Errors.Music.TrackNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenGenreIsInvalid_ShouldReturnError()
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track.
|
||||
/// </summary>
|
||||
/// <returns>The created domain artist, together with its album and track.</returns>
|
||||
private (Artist artist, Album album, Track track) CreateDomainArtist()
|
||||
{
|
||||
// Arrange
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: string.Empty)]);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTagIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid albumId = Guid.NewGuid();
|
||||
AlbumEntity albumEntity = _albumEntityFixture.Create(
|
||||
id: albumId,
|
||||
libraryId: libraryId,
|
||||
tracks: [_trackEntityFixture.Create(albumId: albumId, libraryId: libraryId)]);
|
||||
ArtistEntity artistEntity = _artistEntityFixture.Create(libraryId: libraryId, albums: [albumEntity]);
|
||||
Artist artist = artistEntity.ToDomainEntity().Value;
|
||||
Album album = artist.Albums.First();
|
||||
return (artist, album, album.Tracks.First());
|
||||
}
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicTrackMetadataDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicTrackMetadataDtoMappingTests
|
||||
{
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AudioMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.True(metadata.OriginalTitle.HasValue);
|
||||
Assert.Equal(dto.OriginalTitle, metadata.OriginalTitle.Value);
|
||||
Assert.True(metadata.Description.HasValue);
|
||||
Assert.Equal(dto.Description, metadata.Description.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo!.OriginalReleaseDate, metadata.ReleaseInfo.OriginalReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.OriginalReleaseYear, metadata.ReleaseInfo.OriginalReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseDate, metadata.ReleaseInfo.ReReleaseDate.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReReleaseYear, metadata.ReleaseInfo.ReReleaseYear.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseCountry, metadata.ReleaseInfo.ReleaseCountry.Value);
|
||||
Assert.True(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(dto.ReleaseInfo.ReleaseVersion, metadata.ReleaseInfo.ReleaseVersion.Value);
|
||||
Assert.True(metadata.Language.HasValue);
|
||||
Assert.Equal(dto.Language!.LanguageCode!.ToLowerInvariant(), metadata.Language.Value.LanguageCode);
|
||||
Assert.Equal(dto.Language.LanguageName, metadata.Language.Value.LanguageName);
|
||||
Assert.Equal(dto.Language.NativeName, metadata.Language.Value.NativeName.Value);
|
||||
Assert.True(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Equal(dto.OriginalLanguage!.LanguageCode!.ToLowerInvariant(), metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(dto.OriginalLanguage.LanguageName, metadata.OriginalLanguage.Value.LanguageName);
|
||||
Assert.Equal(dto.OriginalLanguage.NativeName, metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
Assert.Equal(dto.DurationInSeconds, metadata.DurationInSeconds);
|
||||
Assert.Equal(dto.SampleRate, metadata.SampleRate);
|
||||
Assert.Equal(dto.Channels, metadata.Channels);
|
||||
Assert.True(metadata.BitDepth.HasValue);
|
||||
Assert.Equal(dto.BitDepth, metadata.BitDepth.Value);
|
||||
Assert.True(metadata.AudioCodec.HasValue);
|
||||
Assert.Equal(dto.AudioCodec, metadata.AudioCodec.Value);
|
||||
Assert.True(metadata.Bitrate.HasValue);
|
||||
Assert.Equal(dto.Bitrate, metadata.Bitrate.Value);
|
||||
Assert.Equal(dto.Genres!.Select(genre => genre.Name), metadata.Genres.Select(genre => genre.Name));
|
||||
Assert.Equal(dto.Tags!.Select(tag => tag.Name), metadata.Tags.Select(tag => tag.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndDefaults()
|
||||
{
|
||||
// Arrange
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create(
|
||||
includeOriginalTitle: false,
|
||||
includeDescription: false,
|
||||
includeReleaseInfo: false,
|
||||
includeLanguage: false,
|
||||
includeOriginalLanguage: false,
|
||||
includeTags: false,
|
||||
includeGenres: false,
|
||||
includeDurationInSeconds: false,
|
||||
includeSampleRate: false,
|
||||
includeChannels: false,
|
||||
includeBitDepth: false,
|
||||
includeAudioCodec: false,
|
||||
includeBitrate: false);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AudioMetadata metadata = result.Value;
|
||||
Assert.Equal(dto.Title, metadata.Title);
|
||||
Assert.False(metadata.OriginalTitle.HasValue);
|
||||
Assert.False(metadata.Description.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseDate.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReReleaseYear.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseCountry.HasValue);
|
||||
Assert.False(metadata.ReleaseInfo.ReleaseVersion.HasValue);
|
||||
Assert.Equal(0, metadata.DurationInSeconds);
|
||||
Assert.Equal(0, metadata.SampleRate);
|
||||
Assert.Equal(0, metadata.Channels);
|
||||
Assert.False(metadata.BitDepth.HasValue);
|
||||
Assert.False(metadata.AudioCodec.HasValue);
|
||||
Assert.False(metadata.Bitrate.HasValue);
|
||||
Assert.False(metadata.Language.HasValue);
|
||||
Assert.False(metadata.OriginalLanguage.HasValue);
|
||||
Assert.Empty(metadata.Genres);
|
||||
Assert.Empty(metadata.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMissingRequiredSubproperties_ShouldMapLanguageToNone()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto incompleteLanguage = _languageInfoDtoFixture.Create(includeLanguageCode: false);
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create(
|
||||
language: incompleteLanguage,
|
||||
originalLanguage: _languageInfoDtoFixture.Create(includeLanguageName: false));
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto releaseInfo = _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2000, 1, 1),
|
||||
originalReleaseYear: 1999);
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create(releaseInfo: releaseInfo);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.OriginalReleaseDateAndYearMustMatch, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenGenreIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: string.Empty)]);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTagIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicTrackMetadataDto dto = _audioMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
|
||||
// Act
|
||||
Result<AudioMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicWorkDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicWorkDtoMappingTests
|
||||
{
|
||||
private readonly MusicWorkDtoFixture _musicWorkDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
MusicWork work = result.Value;
|
||||
Assert.Equal(dto.MusicBrainzWorkId!.Value, work.MusicBrainzWorkId.Value);
|
||||
Assert.Equal(dto.Title, work.Title);
|
||||
Assert.True(work.Type.HasValue);
|
||||
Assert.Equal(dto.Type, work.Type.Value);
|
||||
Assert.Equal(dto.Languages!.Count, work.Languages.Count);
|
||||
Assert.Equal(dto.Iswcs, work.Iswcs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMapped_ShouldLowercaseTheLanguageCode()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto language = _languageInfoDtoFixture.Create(languageCode: "EN", languageName: "English", nativeName: "English");
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(languages: [language]);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
LanguageInfo mappedLanguage = Assert.Single(result.Value.Languages);
|
||||
Assert.Equal("en", mappedLanguage.LanguageCode);
|
||||
Assert.Equal("English", mappedLanguage.LanguageName);
|
||||
Assert.Equal("English", mappedLanguage.NativeName.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMusicBrainzWorkIdIsMissing_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(includeMusicBrainzWorkId: false);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.MusicBrainzIdInvalidFormat, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTitleIsMissing_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(includeTitle: false);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.WorkTitleCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // empty work title
|
||||
[InlineData(" ")] // whitespace work title
|
||||
public void ToDomainEntity_WhenTitleIsEmptyOrWhitespace_ShouldReturnError(string title)
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(title: title);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.WorkTitleCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalPropertiesAreMissing_ShouldMapTheRequiredValuesAndDefaults()
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(
|
||||
includeType: false,
|
||||
includeLanguages: false,
|
||||
includeIswcs: false);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
MusicWork work = result.Value;
|
||||
Assert.Equal(dto.Title, work.Title);
|
||||
Assert.False(work.Type.HasValue);
|
||||
Assert.Empty(work.Languages);
|
||||
Assert.Empty(work.Iswcs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenLanguageIsMissingRequiredSubproperties_ShouldSkipIt()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto languageWithoutCode = _languageInfoDtoFixture.Create(languageName: "English", includeLanguageCode: false);
|
||||
LanguageInfoDto languageWithoutName = _languageInfoDtoFixture.Create(languageCode: "fr", includeLanguageName: false);
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(languages: [languageWithoutCode, languageWithoutName]);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value.Languages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenIswcsContainBlankValues_ShouldTrimThemAndSkipTheBlankOnes()
|
||||
{
|
||||
// Arrange
|
||||
MusicWorkDto dto = _musicWorkDtoFixture.Create(iswcs: [" T1234567890 ", " ", ""]);
|
||||
|
||||
// Act
|
||||
Result<MusicWork> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(["T1234567890"], result.Value.Iswcs);
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -74,10 +74,10 @@ public class TrackMappingTests
|
||||
Assert.Equal(track.Script.HasValue ? track.Script.Value : null, result.Script);
|
||||
Assert.Equal(track.Key.HasValue ? track.Key.Value : null, result.Key);
|
||||
Assert.Equal(track.Bpm.HasValue ? track.Bpm.Value : null, result.Bpm);
|
||||
Assert.Equal(track.Work.HasValue ? track.Work.Value : null, result.Work);
|
||||
Assert.Equal(track.Work.HasValue ? track.Work.Value.Title : null, result.WorkTitle);
|
||||
Assert.Equal(track.MusicBrainzRecordingId.HasValue ? track.MusicBrainzRecordingId.Value.Value : null, result.MusicBrainzRecordingId);
|
||||
Assert.Equal(track.MusicBrainzTrackId.HasValue ? track.MusicBrainzTrackId.Value.Value : null, result.MusicBrainzTrackId);
|
||||
Assert.Equal(track.MusicBrainzWorkId.HasValue ? track.MusicBrainzWorkId.Value.Value : null, result.MusicBrainzWorkId);
|
||||
Assert.Equal(track.Work.HasValue ? track.Work.Value.MusicBrainzWorkId.Value : null, result.MusicBrainzWorkId);
|
||||
Assert.Equal(track.Moods.ToRepositoryEntities(), result.Moods);
|
||||
Assert.Equal(track.Isrcs.ToRepositoryEntities(), result.Isrcs);
|
||||
Assert.Equal(track.Ratings.ToRepositoryEntities(), result.Ratings);
|
||||
@@ -141,12 +141,11 @@ public class TrackMappingTests
|
||||
script: Optional<string>.None(),
|
||||
key: Optional<MusicKey>.None(),
|
||||
bpm: Optional<int>.None(),
|
||||
work: Optional<string>.None(),
|
||||
work: Optional<MusicWork>.None(),
|
||||
moods: [],
|
||||
isrcs: [],
|
||||
musicBrainzRecordingId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzTrackId: Optional<MusicBrainzId>.None(),
|
||||
musicBrainzWorkId: Optional<MusicBrainzId>.None(),
|
||||
contributors: [],
|
||||
ratings: []);
|
||||
|
||||
@@ -175,7 +174,7 @@ public class TrackMappingTests
|
||||
Assert.Null(result.Script);
|
||||
Assert.Null(result.Key);
|
||||
Assert.Null(result.Bpm);
|
||||
Assert.Null(result.Work);
|
||||
Assert.Null(result.WorkTitle);
|
||||
Assert.Null(result.MusicBrainzRecordingId);
|
||||
Assert.Null(result.MusicBrainzTrackId);
|
||||
Assert.Null(result.MusicBrainzWorkId);
|
||||
|
||||
+4
-5
@@ -32,7 +32,7 @@ public class UpdateTrackCommandMappingTests
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly MoodDtoFixture _moodDtoFixture = new();
|
||||
private readonly IsrcDtoFixture _isrcDtoFixture = new();
|
||||
@@ -67,10 +67,10 @@ public class UpdateTrackCommandMappingTests
|
||||
Assert.True(updatedTrack.Bpm.HasValue);
|
||||
Assert.Equal(command.Bpm, updatedTrack.Bpm.Value);
|
||||
Assert.True(updatedTrack.Work.HasValue);
|
||||
Assert.Equal(command.Work, updatedTrack.Work.Value);
|
||||
Assert.Equal(command.Work!.Title, updatedTrack.Work.Value.Title);
|
||||
Assert.Equal(command.MusicBrainzRecordingId, updatedTrack.MusicBrainzRecordingId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzTrackId, updatedTrack.MusicBrainzTrackId.Value.Value);
|
||||
Assert.Equal(command.MusicBrainzWorkId, updatedTrack.MusicBrainzWorkId.Value.Value);
|
||||
Assert.Equal(command.Work!.MusicBrainzWorkId, updatedTrack.Work.Value.MusicBrainzWorkId.Value);
|
||||
Assert.Equal(command.Moods!.Count, updatedTrack.Moods.Count);
|
||||
Assert.Equal(command.Isrcs!.Count, updatedTrack.Isrcs.Count);
|
||||
Assert.Equal(command.Contributors!.Count, updatedTrack.Contributors.Count);
|
||||
@@ -84,7 +84,7 @@ public class UpdateTrackCommandMappingTests
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||
string updatedPath = "/music/queen/a-night-at-the-opera/03-you-re-my-best-friend.flac";
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString(), path: updatedPath, includeDiscNumber: false, includeScript: false, includeKey: false, includeBpm: false, includeWork: false, includeMusicBrainzRecordingId: false, includeMusicBrainzTrackId: false, includeMusicBrainzWorkId: false, includeMoods: false, includeIsrcs: false, contributors: [], ratings: []);
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString(), path: updatedPath, includeDiscNumber: false, includeScript: false, includeKey: false, includeBpm: false, includeWork: false, includeMusicBrainzRecordingId: false, includeMusicBrainzTrackId: false, includeMoods: false, includeIsrcs: false, contributors: [], ratings: []);
|
||||
|
||||
// Act
|
||||
Result<Artist> result = command.ToDomainEntity(artist);
|
||||
@@ -101,7 +101,6 @@ public class UpdateTrackCommandMappingTests
|
||||
Assert.False(updatedTrack.Work.HasValue);
|
||||
Assert.False(updatedTrack.MusicBrainzRecordingId.HasValue);
|
||||
Assert.False(updatedTrack.MusicBrainzTrackId.HasValue);
|
||||
Assert.False(updatedTrack.MusicBrainzWorkId.HasValue);
|
||||
Assert.Empty(updatedTrack.Moods);
|
||||
Assert.Empty(updatedTrack.Isrcs);
|
||||
Assert.Empty(updatedTrack.Contributors);
|
||||
|
||||
+1
-5
@@ -48,7 +48,6 @@ public class UpdateTrackRequestMappingTests
|
||||
Assert.Equal(request.Work, result.Work);
|
||||
Assert.Equal(request.MusicBrainzRecordingId, result.MusicBrainzRecordingId);
|
||||
Assert.Equal(request.MusicBrainzTrackId, result.MusicBrainzTrackId);
|
||||
Assert.Equal(request.MusicBrainzWorkId, result.MusicBrainzWorkId);
|
||||
Assert.Equal(request.Moods, result.Moods);
|
||||
Assert.Equal(request.Isrcs, result.Isrcs);
|
||||
Assert.Equal(request.Contributors, result.Contributors);
|
||||
@@ -71,7 +70,6 @@ public class UpdateTrackRequestMappingTests
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false,
|
||||
includeMoods: false,
|
||||
includeIsrcs: false,
|
||||
contributors: [],
|
||||
@@ -95,7 +93,6 @@ public class UpdateTrackRequestMappingTests
|
||||
Assert.Null(result.Work);
|
||||
Assert.Null(result.MusicBrainzRecordingId);
|
||||
Assert.Null(result.MusicBrainzTrackId);
|
||||
Assert.Null(result.MusicBrainzWorkId);
|
||||
Assert.Null(result.Moods);
|
||||
Assert.Null(result.Isrcs);
|
||||
Assert.Empty(result.Contributors!);
|
||||
@@ -121,8 +118,7 @@ public class UpdateTrackRequestMappingTests
|
||||
includeBpm: false,
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false);
|
||||
includeMusicBrainzTrackId: false);
|
||||
|
||||
// Act
|
||||
UpdateTrackCommand result = request.ToCommand(libraryId.ToString(), artistId.ToString(), albumId.ToString(), trackId.ToString());
|
||||
|
||||
+8
-8
@@ -21,13 +21,13 @@ public class BookRatingDtoMappingTests
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteBookRatinDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingCompleteBookRatinDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainEntity();
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -53,13 +53,13 @@ public class BookRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingMinimalBookRatingDto_ShouldMapRequiredPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingMinimalBookRatingDto_ShouldMapRequiredPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create(includeSource: false, includeVoteCount: false);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainEntity();
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -71,13 +71,13 @@ public class BookRatingDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidBookRatingDto_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenMappingInvalidBookRatingDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.Create(value: 10, maxValue: 5);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = dto.ToDomainEntity();
|
||||
Result<BookRating> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -94,7 +94,7 @@ public class BookRatingDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
@@ -129,7 +129,7 @@ public class BookRatingDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+6
-6
@@ -76,13 +76,13 @@ public class BookRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.Create();
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = entity.ToDomainEntity();
|
||||
Result<BookRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -94,13 +94,13 @@ public class BookRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
public void ToDomainValueObject_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.Create(includeValues: false);
|
||||
|
||||
// Act
|
||||
Result<BookRating> result = entity.ToDomainEntity();
|
||||
Result<BookRating> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -112,13 +112,13 @@ public class BookRatingEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities = _fixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<BookRating>> results = entities.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+10
-10
@@ -22,13 +22,13 @@ public class IsbnDtoMappingTests
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbn10Dto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidIsbn10Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create(format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainEntity();
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -38,13 +38,13 @@ public class IsbnDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbn13Dto_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidIsbn13Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create(format: IsbnFormat.Isbn13);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainEntity();
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -54,13 +54,13 @@ public class IsbnDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingDtoWithoutFormat_ShouldUseDefaultFormat()
|
||||
public void ToDomainValueObject_WhenMappingDtoWithoutFormat_ShouldUseDefaultFormat()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainEntity();
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -70,13 +70,13 @@ public class IsbnDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidIsbnDto_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenMappingInvalidIsbnDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.Create("invalid-isbn", IsbnFormat.Isbn13);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = dto.ToDomainEntity();
|
||||
Result<Isbn> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -94,7 +94,7 @@ public class IsbnDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
@@ -125,7 +125,7 @@ public class IsbnDtoMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> results = dtos.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+7
-7
@@ -61,7 +61,7 @@ public class IsbnEntityMappingTests
|
||||
public void ToResponse_WhenMappingInvalidIsbnEntity_ShouldPreserveValues(string? value, IsbnFormat? format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format, includeValue: value is not null);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format, includeValue: value is not null, includeFormat: false);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
@@ -72,13 +72,13 @@ public class IsbnEntityMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainEntity();
|
||||
Result<Isbn> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -91,20 +91,20 @@ public class IsbnEntityMappingTests
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
|
||||
public void ToDomainValueObject_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: invalidValue, includeValue: invalidValue is not null);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainEntity();
|
||||
Result<Isbn> result = entity.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
public void ToDomainValueObjects_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
@@ -114,7 +114,7 @@ public class IsbnEntityMappingTests
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<Result<Isbn>> results = entities.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> results = entities.ToDomainValueObjects();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
|
||||
+10
-10
@@ -23,13 +23,13 @@ public class WrittenContentMetadataDtoMappingTests
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteWrittenContentMetadataDto_ShouldMapAllPropertiesCorrectly()
|
||||
public void ToDomainValueObject_WhenMappingCompleteWrittenContentMetadataDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -51,7 +51,7 @@ public class WrittenContentMetadataDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenOptionalValuesAreMissing_ShouldMapWithoutOptionalValues()
|
||||
public void ToDomainValueObject_WhenOptionalValuesAreMissing_ShouldMapWithoutOptionalValues()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(
|
||||
@@ -63,7 +63,7 @@ public class WrittenContentMetadataDtoMappingTests
|
||||
includePageCount: false);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -76,7 +76,7 @@ public class WrittenContentMetadataDtoMappingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenReleaseInfoCreationFails_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenReleaseInfoCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(
|
||||
@@ -85,33 +85,33 @@ public class WrittenContentMetadataDtoMappingTests
|
||||
originalReleaseYear: 2024));
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenGenreCreationFails_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenGenreCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(genres: [_genreDtoFixture.Create(name: "")]);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTagCreationFails_ShouldReturnError()
|
||||
public void ToDomainValueObject_WhenTagCreationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
WrittenContentMetadataDto dto = _writtenContentMetadataDtoFixture.Create(tags: [_tagDtoFixture.Create(name: "")]);
|
||||
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> result = dto.ToDomainValueObject();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
Reference in new issue
Block a user