mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Persists the disambiguation comment of music tracks.
This commit is contained in:
1 parent
4ceb8f7360
commit
27c6c40b39
10 files changed
+155
-7
No files matched your search
+27
@@ -35,6 +35,7 @@ public class UpdateArtistCommandMappingTests
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly MusicAlbumMetadataDtoFixture _musicAlbumMetadataDtoFixture = new();
|
||||
private readonly MusicArtistMetadataDtoFixture _musicArtistMetadataDtoFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _musicTrackMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
@@ -254,6 +255,32 @@ public class UpdateArtistCommandMappingTests
|
||||
Assert.Empty(updatedAlbum.Tracks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenTrackHasDisambiguation_ShouldMapTheDisambiguationThrough()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||
string disambiguation = "live at Wembley";
|
||||
AddTrackCommand trackCommand = _addTrackCommandFixture.Create(
|
||||
trackId: trackId,
|
||||
metadata: _musicTrackMetadataDtoFixture.Create(disambiguation: disambiguation));
|
||||
AddAlbumCommand albumCommand = _addAlbumCommandFixture.Create(albumId: albumId, tracks: [trackCommand]);
|
||||
UpdateArtistCommand command = _updateArtistCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
artistId: artist.Id.Value.ToString(),
|
||||
albums: [albumCommand]);
|
||||
|
||||
// Act
|
||||
Result<Artist> result = command.ToDomainEntity(artist);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
||||
Assert.True(updatedTrack.Disambiguation.HasValue);
|
||||
Assert.Equal(disambiguation, updatedTrack.Disambiguation.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track, all belonging to <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
|
||||
+39
-2
@@ -119,18 +119,55 @@ public class AudioMetadataDtoMappingTests
|
||||
Assert.Equal(Errors.Music.TrackNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenDtoHasDisambiguation_ShouldUseTheDtoDisambiguation()
|
||||
{
|
||||
// Arrange
|
||||
(Artist artist, Album album, Track track) = CreateDomainArtist();
|
||||
string disambiguation = "album version";
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(disambiguation: disambiguation);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, track, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(track.Disambiguation.HasValue);
|
||||
Assert.Equal(disambiguation, track.Disambiguation.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyTo_WhenDtoHasNoDisambiguation_ShouldKeepTheTrackDisambiguation()
|
||||
{
|
||||
// Arrange
|
||||
string trackDisambiguation = "single version";
|
||||
(Artist artist, Album album, Track track) = CreateDomainArtist(trackDisambiguation);
|
||||
AudioMetadataDto dto = _audioMetadataDtoFixture.Create(includeDisambiguation: false);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = dto.ApplyTo(artist, album, track, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(track.Disambiguation.HasValue);
|
||||
Assert.Equal(trackDisambiguation, track.Disambiguation.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track.
|
||||
/// </summary>
|
||||
/// <param name="trackDisambiguation">Optional. The disambiguation of the created track.</param>
|
||||
/// <returns>The created domain artist, together with its album and track.</returns>
|
||||
private (Artist artist, Album album, Track track) CreateDomainArtist()
|
||||
private (Artist artist, Album album, Track track) CreateDomainArtist(string? trackDisambiguation = null)
|
||||
{
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid albumId = Guid.NewGuid();
|
||||
TrackEntity trackEntity = _trackEntityFixture.Create(albumId: albumId, libraryId: libraryId);
|
||||
trackEntity.Disambiguation = trackDisambiguation;
|
||||
AlbumEntity albumEntity = _albumEntityFixture.Create(
|
||||
id: albumId,
|
||||
libraryId: libraryId,
|
||||
tracks: [_trackEntityFixture.Create(albumId: albumId, libraryId: libraryId)]);
|
||||
tracks: [trackEntity]);
|
||||
ArtistEntity artistEntity = _artistEntityFixture.Create(libraryId: libraryId, albums: [albumEntity]);
|
||||
Artist artist = artistEntity.ToDomainEntity().Value;
|
||||
Album album = artist.Albums.First();
|
||||
|
||||
+46
@@ -238,6 +238,52 @@ public class UpdateTrackCommandMappingTests
|
||||
Assert.Equal(Errors.Music.TrackNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMetadataHasDisambiguation_ShouldMapTheDisambiguationThrough()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||
string disambiguation = "2011 remaster";
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
artistId: artist.Id.Value.ToString(),
|
||||
albumId: albumId.ToString(),
|
||||
trackId: trackId.ToString(),
|
||||
metadata: _musicTrackMetadataDtoFixture.Create(disambiguation: disambiguation));
|
||||
|
||||
// Act
|
||||
Result<Artist> result = command.ToDomainEntity(artist);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
||||
Assert.True(updatedTrack.Disambiguation.HasValue);
|
||||
Assert.Equal(disambiguation, updatedTrack.Disambiguation.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMetadataHasNoDisambiguation_ShouldClearTheDisambiguation()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
artistId: artist.Id.Value.ToString(),
|
||||
albumId: albumId.ToString(),
|
||||
trackId: trackId.ToString(),
|
||||
metadata: _musicTrackMetadataDtoFixture.Create(includeDisambiguation: false));
|
||||
|
||||
// Act
|
||||
Result<Artist> result = command.ToDomainEntity(artist);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
||||
Assert.False(updatedTrack.Disambiguation.HasValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a domain artist that owns a single album, which in turn owns a single track, all belonging to <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -663,6 +663,7 @@ public class ArtistTests
|
||||
Artist artist = _artistFixture.Create(albums: [album]);
|
||||
string path = "C:\\Music\\queen\\bohemian-rhapsody.flac";
|
||||
AudioMetadata metadata = _audioMetadataFixture.Create();
|
||||
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
||||
Optional<int> discNumber = Optional<int>.Some(1);
|
||||
Optional<string> script = Optional<string>.Some("Latin");
|
||||
Optional<MusicKey> key = Optional<MusicKey>.Some(MusicKey.BMajor);
|
||||
@@ -682,6 +683,7 @@ public class ArtistTests
|
||||
track,
|
||||
path,
|
||||
metadata,
|
||||
disambiguation,
|
||||
11,
|
||||
discNumber,
|
||||
script,
|
||||
@@ -700,6 +702,7 @@ public class ArtistTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(path, track.Path);
|
||||
Assert.Equal(metadata, track.Metadata);
|
||||
Assert.Equal(disambiguation, track.Disambiguation);
|
||||
Assert.Equal(11, track.TrackNumber);
|
||||
Assert.Equal(discNumber, track.DiscNumber);
|
||||
Assert.Equal(script, track.Script);
|
||||
@@ -734,6 +737,7 @@ public class ArtistTests
|
||||
track,
|
||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
||||
_audioMetadataFixture.Create(),
|
||||
Optional<string>.None(),
|
||||
11,
|
||||
Optional<int>.None(),
|
||||
Optional<string>.None(),
|
||||
@@ -771,6 +775,7 @@ public class ArtistTests
|
||||
track,
|
||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
||||
_audioMetadataFixture.Create(),
|
||||
Optional<string>.None(),
|
||||
11,
|
||||
Optional<int>.None(),
|
||||
Optional<string>.None(),
|
||||
|
||||
+5
@@ -193,6 +193,7 @@ public class TrackTests
|
||||
List<Mood> originalMoods = [.. track.Moods];
|
||||
string path = "C:\\Music\\queen\\bohemian-rhapsody.flac";
|
||||
AudioMetadata metadata = _audioMetadataFixture.Create();
|
||||
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
||||
Optional<int> discNumber = Optional<int>.Some(2);
|
||||
Optional<string> script = Optional<string>.Some("Latin");
|
||||
Optional<MusicKey> key = Optional<MusicKey>.Some(MusicKey.DMajor);
|
||||
@@ -207,6 +208,7 @@ public class TrackTests
|
||||
Result<Updated> result = track.UpdateDetails(
|
||||
path,
|
||||
metadata,
|
||||
disambiguation,
|
||||
7,
|
||||
discNumber,
|
||||
script,
|
||||
@@ -221,6 +223,7 @@ public class TrackTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(path, track.Path);
|
||||
Assert.Equal(metadata, track.Metadata);
|
||||
Assert.Equal(disambiguation, track.Disambiguation);
|
||||
Assert.Equal(7, track.TrackNumber);
|
||||
Assert.Equal(discNumber, track.DiscNumber);
|
||||
Assert.Equal(script, track.Script);
|
||||
@@ -375,6 +378,7 @@ public class TrackTests
|
||||
Result<Updated> result = track.UpdateDetails(
|
||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
||||
_audioMetadataFixture.Create(),
|
||||
Optional<string>.None(),
|
||||
11,
|
||||
Optional<int>.None(),
|
||||
Optional<string>.None(),
|
||||
@@ -388,6 +392,7 @@ public class TrackTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(track.DiscNumber.HasValue);
|
||||
Assert.False(track.Disambiguation.HasValue);
|
||||
Assert.False(track.Script.HasValue);
|
||||
Assert.False(track.Key.HasValue);
|
||||
Assert.False(track.Bpm.HasValue);
|
||||
|
||||
Reference in new issue
Block a user