mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +00:00
Implements tests for commit 067e9a21d0
This commit is contained in:
1 parent
aeefa9487e
commit
a75447062f
18 files changed
+3156
No files matched your search
+21
@@ -27,6 +27,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.
|
||||
public class AlbumEntityMappingTests
|
||||
{
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
@@ -252,6 +253,7 @@ public class AlbumEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
AlbumEntity entity = _albumEntityFixture.Create();
|
||||
entity.Artist = _artistEntityFixture.Create(name: "Queen");
|
||||
|
||||
// Act
|
||||
AlbumResponse result = entity.ToResponse();
|
||||
@@ -260,6 +262,7 @@ public class AlbumEntityMappingTests
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entity.Id, result.Id);
|
||||
Assert.Equal(entity.ArtistId, result.ArtistId);
|
||||
Assert.Equal("Queen", result.ArtistName);
|
||||
Assert.Equal(entity.LibraryId, result.LibraryId);
|
||||
// No cover path is supplied by default, so the response exposes none.
|
||||
Assert.Null(result.CoverPath);
|
||||
@@ -299,6 +302,21 @@ public class AlbumEntityMappingTests
|
||||
Assert.Equal(entity.Tracks.Select(track => track.Id), result.Tracks!.Select(track => track.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenAlbumHasNoArtist_ShouldMapAnEmptyArtistName()
|
||||
{
|
||||
// Arrange
|
||||
AlbumEntity entity = _albumEntityFixture.Create();
|
||||
entity.Artist = null;
|
||||
|
||||
// Act
|
||||
AlbumResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
// The response contract always carries an artist name, so an album loaded without its artist exposes an empty one instead of null.
|
||||
Assert.Equal(string.Empty, result.ArtistName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenLanguageSubpropertiesAreBlank_ShouldMapLanguagesToNull()
|
||||
{
|
||||
@@ -335,6 +353,8 @@ public class AlbumEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
List<AlbumEntity> entities = _albumEntityFixture.CreateMany(2);
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
entities[i].Artist = _artistEntityFixture.Create(name: $"Artist {i}");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<AlbumResponse> results = entities.ToResponses();
|
||||
@@ -346,6 +366,7 @@ public class AlbumEntityMappingTests
|
||||
{
|
||||
Assert.Equal(entities[i].Id, results[i].Id);
|
||||
Assert.Equal(entities[i].Title, results[i].Metadata.Title);
|
||||
Assert.Equal($"Artist {i}", results[i].ArtistName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
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="ShuffleTrackRowDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ShuffleTrackRowDtoMappingTests
|
||||
{
|
||||
private readonly ShuffleTrackRowFixture _shuffleTrackRowFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingTrackWithCoverPath_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTrackRowDto readModel = _shuffleTrackRowFixture.Create(
|
||||
title: "Bohemian Rhapsody",
|
||||
durationInSeconds: 355,
|
||||
albumTitle: "A Night at the Opera",
|
||||
coverPath: "a-night-at-the-opera-cover.jpg");
|
||||
|
||||
// Act
|
||||
ShuffleTrackResponse result = readModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(readModel.TrackId, result.TrackId);
|
||||
Assert.Equal(readModel.Title, result.Title);
|
||||
Assert.Equal(readModel.DurationInSeconds, result.DurationInSeconds);
|
||||
Assert.Equal(readModel.AlbumId, result.AlbumId);
|
||||
Assert.Equal(readModel.AlbumTitle, result.AlbumTitle);
|
||||
Assert.Equal(readModel.ArtistId, result.ArtistId);
|
||||
Assert.Equal("a-night-at-the-opera-cover.jpg", result.CoverPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenCoverPathIsMissing_ShouldMapNullCoverPath()
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTrackRowDto readModel = _shuffleTrackRowFixture.Create(includeCoverPath: false);
|
||||
|
||||
// Act
|
||||
ShuffleTrackResponse result = readModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.CoverPath);
|
||||
Assert.Equal(readModel.TrackId, result.TrackId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleRows_ShouldMapEveryRowAndPreserveTheOrder()
|
||||
{
|
||||
// Arrange
|
||||
List<ShuffleTrackRowDto> readModels = _shuffleTrackRowFixture.CreateMany(4);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ShuffleTrackResponse> results = readModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(readModels.Count, results.Count);
|
||||
Assert.Equal(readModels.Select(readModel => readModel.TrackId), results.Select(response => response.TrackId));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.Title), results.Select(response => response.Title));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.DurationInSeconds), results.Select(response => response.DurationInSeconds));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.AlbumId), results.Select(response => response.AlbumId));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.AlbumTitle), results.Select(response => response.AlbumTitle));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.ArtistId), results.Select(response => response.ArtistId));
|
||||
Assert.Equal(readModels.Select(readModel => readModel.CoverPath), results.Select(response => response.CoverPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenInputIsEmpty_ShouldReturnAnEmptyCollection()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<ShuffleTrackRowDto> readModels = [];
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ShuffleTrackResponse> results = readModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Empty(results);
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.ShuffleTracks;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ShuffleTracksRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ShuffleTracksRequestMappingTests
|
||||
{
|
||||
private readonly ShuffleTracksRequestFixture _shuffleTracksRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid artistId = Guid.NewGuid();
|
||||
Guid albumId = Guid.NewGuid();
|
||||
Guid firstExcludedTrackId = Guid.NewGuid();
|
||||
Guid secondExcludedTrackId = Guid.NewGuid();
|
||||
ShuffleTracksRequest request = _shuffleTracksRequestFixture.Create(
|
||||
count: 25,
|
||||
artistId: artistId,
|
||||
albumId: albumId,
|
||||
excludedTrackIds: [firstExcludedTrackId, secondExcludedTrackId]);
|
||||
|
||||
// Act
|
||||
ShuffleTracksQuery result = request.ToQuery(libraryId.ToString());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(libraryId.ToString(), result.LibraryId);
|
||||
Assert.Equal(25, result.Count);
|
||||
Assert.Equal(artistId, result.ArtistId);
|
||||
Assert.Equal(albumId, result.AlbumId);
|
||||
Assert.NotNull(result.ExcludedTrackIds);
|
||||
Assert.Equal(new[] { firstExcludedTrackId, secondExcludedTrackId }, result.ExcludedTrackIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenExcludedTrackIdsAreNull_ShouldKeepThemNull()
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTracksRequest request = _shuffleTracksRequestFixture.Create(includeExcludedTrackIds: false);
|
||||
|
||||
// Act
|
||||
ShuffleTracksQuery result = request.ToQuery(Guid.NewGuid().ToString());
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.ExcludedTrackIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenOptionalScopeIsMissing_ShouldKeepTheScopeNull()
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTracksRequest request = _shuffleTracksRequestFixture.Create(includeArtistId: false, includeAlbumId: false);
|
||||
|
||||
// Act
|
||||
ShuffleTracksQuery result = request.ToQuery(Guid.NewGuid().ToString());
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.ArtistId);
|
||||
Assert.Null(result.AlbumId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenLibraryIdArgumentIsNull_ShouldKeepItNull()
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTracksRequest request = _shuffleTracksRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
ShuffleTracksQuery result = request.ToQuery(null);
|
||||
|
||||
// Assert
|
||||
// The route value is forwarded untouched, so that the query validator reports the missing identifier.
|
||||
Assert.Null(result.LibraryId);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("not-a-guid")] // a value that cannot be parsed
|
||||
[InlineData("' OR '1'='1")] // an injection payload
|
||||
[InlineData("'; DROP TABLE Tracks; --")] // a destructive injection payload
|
||||
public void ToQuery_WhenLibraryIdArgumentIsNotParseable_ShouldPassItVerbatim(string libraryId)
|
||||
{
|
||||
// Arrange
|
||||
ShuffleTracksRequest request = _shuffleTracksRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
ShuffleTracksQuery result = request.ToQuery(libraryId);
|
||||
|
||||
// Assert
|
||||
// The raw route value must reach the validator, which is the layer that decides it is not a valid identifier.
|
||||
Assert.Equal(libraryId, result.LibraryId);
|
||||
Assert.Equal(request.Count, result.Count);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user