mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Extends the music library listings with covers, sorting and alpha filtering.
This commit is contained in:
1 parent
0019821e87
commit
9d82f283e4
69 files changed
+3613
-268
No files matched your search
+108
@@ -15,6 +15,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NSubstitute;
|
||||
@@ -44,6 +45,7 @@ public class AlbumRepositoryTests
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new();
|
||||
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
@@ -601,6 +603,112 @@ public class AlbumRepositoryTests
|
||||
Assert.Equal(expectedRowCount, result.Value.Data.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsSet_ShouldProjectItAsReleaseYear()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-releaseyear-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
AlbumRepository sut = CreateAlbumRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity artist = await SeedArtistAsync(context, libraryId);
|
||||
AlbumEntity album = _albumEntityFixture.Create(
|
||||
artistId: artist.Id, libraryId: libraryId, originalReleaseYear: 1975, reReleaseYear: 2011, includeTracks: false, includeMetadata: false);
|
||||
context.Albums.Add(album);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal(2011, row.ReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsNull_ShouldFallBackToOriginalReleaseYear()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-originalyear-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
AlbumRepository sut = CreateAlbumRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity artist = await SeedArtistAsync(context, libraryId);
|
||||
AlbumEntity album = _albumEntityFixture.Create(
|
||||
artistId: artist.Id, libraryId: libraryId, originalReleaseYear: 1975, includeReReleaseYear: false, includeTracks: false, includeMetadata: false);
|
||||
context.Albums.Add(album);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal(1975, row.ReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAlbumsLiteByArtistIdAsync_WhenTheReleaseHasTypes_ShouldProjectThem()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-releasetypes-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
AlbumRepository sut = CreateAlbumRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity artist = await SeedArtistAsync(context, libraryId);
|
||||
AlbumEntity album = _albumEntityFixture.Create(
|
||||
artistId: artist.Id, libraryId: libraryId, releaseType: MusicReleaseType.Single, includeTracks: false, includeMetadata: false);
|
||||
context.Albums.Add(album);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.NotNull(row.ReleaseTypes);
|
||||
Assert.Equal(MusicReleaseType.Single, Assert.Single(row.ReleaseTypes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAlbumsLiteByArtistIdAsync_WhenCoverArtworkExists_ShouldProjectTheCoverPath()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-cover-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
AlbumRepository sut = CreateAlbumRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity artist = await SeedArtistAsync(context, libraryId);
|
||||
AlbumEntity album = _albumEntityFixture.Create(artistId: artist.Id, libraryId: libraryId, includeTracks: false, includeMetadata: false);
|
||||
context.Albums.Add(album);
|
||||
context.MusicArtwork.Add(
|
||||
_musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: album.Id, artworkType: ArtworkType.Cover, fileName: "covers/opera.jpg"));
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
AlbumLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("covers/opera.jpg", row.CoverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an album repository backed by the provided context, wiring the real track repository.
|
||||
/// </summary>
|
||||
|
||||
+253
@@ -17,6 +17,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
@@ -51,6 +52,7 @@ public class ArtistRepositoryTests
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
|
||||
private readonly LibraryFilterDtoFixture _libraryFilterDtoFixture = new();
|
||||
private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_WhenCalledWithAValidArtist_ShouldPersistTheArtistAndItsAggregate()
|
||||
@@ -1079,6 +1081,257 @@ public class ArtistRepositoryTests
|
||||
Assert.Equal(keptTrackContributor.Id, Assert.Single(storedTrack.Contributors).Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteByLibraryIdAsync_WhenCalled_ShouldDeleteOnlyTheLibraryArtistsAndTheirChildren()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-deletebylibrary-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity targetArtist = await SeedArtistAsync(context, libraryId, "Queen");
|
||||
AlbumEntity targetAlbum = await SeedAlbumAsync(context, libraryId, targetArtist.Id);
|
||||
context.Tracks.Add(_trackEntityFixture.Create(albumId: targetAlbum.Id, libraryId: libraryId, includeMetadata: false));
|
||||
ArtistEntity artistOfAnotherLibrary = await SeedArtistAsync(context, Guid.NewGuid(), "Pink Floyd");
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await sut.DeleteByLibraryIdAsync(libraryId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
context.ChangeTracker.Clear();
|
||||
// Only the artists of the target library are deleted, and the database cascade removes their albums and tracks.
|
||||
ArtistEntity survivor = Assert.Single(await context.Artists.AsNoTracking().ToListAsync());
|
||||
Assert.Equal(artistOfAnotherLibrary.Id, survivor.Id);
|
||||
Assert.Empty(await context.Albums.AsNoTracking().Where(candidate => candidate.LibraryId == libraryId).ToListAsync());
|
||||
Assert.Empty(await context.Tracks.AsNoTracking().Where(candidate => candidate.LibraryId == libraryId).ToListAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenAlphaKeyIsTheNumberKey_ShouldMatchOnlyNamesStartingWithADigit()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-number-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity numericArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "1984", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity letterArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity symbolArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "!Voyager", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(numericArtist, letterArtist, symbolArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: LibraryItemAlphaKeys.NUMBER);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("1984", row.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenAlphaKeyIsTheSymbolKey_ShouldMatchOnlyNamesStartingWithASymbol()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-symbol-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity symbolArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "!Voyager", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity numericArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "1984", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity letterArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(symbolArtist, numericArtist, letterArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: LibraryItemAlphaKeys.SYMBOL);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("!Voyager", row.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenAlphaKeyIsALetter_ShouldMatchOnlyNamesStartingWithIt()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-letter-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity alphaArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity bravoArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Bravo", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity charlieArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Charlie", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(alphaArtist, bravoArtist, charlieArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b");
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("Bravo", row.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenSearchTermAndAlphaKeyAreProvided_ShouldCombineThemWithAnd()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-search-alpha-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity matchingArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha Band", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity artistMatchingOnlyTheAlphaKey = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity artistMatchingOnlyTheSearchTerm = _artistEntityFixture.Create(libraryId: libraryId, name: "Beta Band", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(matchingArtist, artistMatchingOnlyTheAlphaKey, artistMatchingOnlyTheSearchTerm);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, searchTerm: "Band", filterAlphaKey: "a");
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal(matchingArtist.Id, row.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenIgnoringThePrefix_ShouldFilterOnTheStrippedName()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-the-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity adeleArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(beatlesArtist, adeleArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b", shouldIgnoreThePrefixForAlphaPicker: true);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("The Beatles", row.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenNotIgnoringThePrefix_ShouldFilterOnTheFullName()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-the-off-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity adeleArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(beatlesArtist, adeleArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b", shouldIgnoreThePrefixForAlphaPicker: false);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value.Data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenIgnoringThePrefixForSorting_ShouldSortByTheStrippedName()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-sort-the-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity beneathArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Beneath the Surface", includeAlbums: false, includeContributors: false);
|
||||
ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.AddRange(beneathArtist, beatlesArtist);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, shouldIgnoreThePrefixForAlphaPicker: true);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
// With the prefix stripped, the sort key of "The Beatles" is "beatles", which sorts before "beneath".
|
||||
Assert.Equal(["The Beatles", "Beneath the Surface"], result.Value.Data.Select(row => row.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllLiteAsync_WhenCoverArtworkExists_ShouldReturnItsPath()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-cover-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
ArtistRepository sut = CreateArtistRepository(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ArtistEntity artist = _artistEntityFixture.Create(libraryId: libraryId, name: "Queen", includeAlbums: false, includeContributors: false);
|
||||
context.Artists.Add(artist);
|
||||
context.MusicArtwork.Add(
|
||||
_musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artist.Id, artworkType: ArtworkType.Cover, fileName: "covers/queen.jpg"));
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId);
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ArtistLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal("covers/queen.jpg", row.CoverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds an artist that owns the requested number of albums, each with the requested number of tracks, all of them with distinct shared reference names.
|
||||
/// </summary>
|
||||
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.DataAccess.Core.Repositories.MusicLibrary.Specifications;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.IntegrationTests.Core.Repositories.MusicLibrary.Specifications;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="ArtistAlphaFilterSpecification"/> class, exercising it against a real SQLite database.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistAlphaFilterSpecificationTests : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
private readonly LuminaDbContext _context;
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArtistAlphaFilterSpecificationTests"/> class.
|
||||
/// </summary>
|
||||
public ArtistAlphaFilterSpecificationTests()
|
||||
{
|
||||
// The specification translates to the SQLite glob() function, so it can only be exercised against a real SQLite database.
|
||||
_connection = new SqliteConnection("Data Source=:memory:");
|
||||
_connection.Open();
|
||||
_context = new LuminaDbContext(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(_connection).Options);
|
||||
_context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsNull_ShouldMatchEveryArtist()
|
||||
{
|
||||
// Arrange
|
||||
List<ArtistEntity> artists = SeedArtists("Alpha", "Beta", "1984");
|
||||
ArtistAlphaFilterSpecification specification = new(null, false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> result = [.. _context.Artists.Where(specification.ToExpression())];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(artists.Count, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsALowercaseLetter_ShouldMatchOnlyArtistsWhoseNameStartsWithIt()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("Foo Fighters", "Helloween", "The Beatles");
|
||||
ArtistAlphaFilterSpecification specification = new("f", false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["Foo Fighters"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsAnUppercaseLetter_ShouldMatchArtistsWhoseNameStartsWithItsLowercase()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("Foo Fighters", "Helloween");
|
||||
ArtistAlphaFilterSpecification specification = new("F", false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["Foo Fighters"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenNoNameStartsWithTheAlphaKey_ShouldNotMatchAnyArtist()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("Foo Fighters", "Helloween");
|
||||
ArtistAlphaFilterSpecification specification = new("z", false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> result = [.. _context.Artists.Where(specification.ToExpression())];
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsTheNumberKey_ShouldMatchOnlyArtistsWhoseNameStartsWithADigit()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("1984", "Alpha", "Beta");
|
||||
ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.NUMBER, false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["1984"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsTheSymbolKey_ShouldMatchOnlyArtistsWhoseNameStartsWithASymbol()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("!Important", "1984", "Alpha");
|
||||
ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.SYMBOL, false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["!Important"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenIgnoringThePrefixAndNameStartsWithThe_ShouldMatchOnTheStrippedName()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("The Beatles", "Adele");
|
||||
ArtistAlphaFilterSpecification specification = new("b", true);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["The Beatles"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenNotIgnoringThePrefixAndNameStartsWithThe_ShouldNotMatchOnTheStrippedName()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("The Beatles", "Adele");
|
||||
ArtistAlphaFilterSpecification specification = new("b", false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> result = [.. _context.Artists.Where(specification.ToExpression())];
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsTheNumberKeyAndNameStartsWithASymbol_ShouldNotMatchIt()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("!Voyager", "1984", "Alpha");
|
||||
ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.NUMBER, false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
// Only the artist whose name starts with a digit matches; a symbol and a letter do not.
|
||||
Assert.Equal(["1984"], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsTheSymbolKeyAndNameIsEmpty_ShouldMatchIt()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists(string.Empty);
|
||||
ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.SYMBOL, false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> result = [.. _context.Artists.Where(specification.ToExpression())];
|
||||
|
||||
// Assert
|
||||
// An empty effective name is neither a letter nor a digit, so it is categorized as a symbol.
|
||||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsALetterAndNameIsEmpty_ShouldNotMatchAnyArtist()
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists(string.Empty);
|
||||
ArtistAlphaFilterSpecification specification = new("a", false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> result = [.. _context.Artists.Where(specification.ToExpression())];
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("a", "Alpha")] // the first letter of the alphabet
|
||||
[InlineData("b", "Bravo")] // a letter in the middle of the alphabet
|
||||
[InlineData("c", "Charlie")] // another letter in the middle of the alphabet
|
||||
public void ToExpression_WhenAlphaKeyIsALetter_ShouldMatchOnlyTheNamesStartingWithIt(string alphaKey, string matchingName)
|
||||
{
|
||||
// Arrange
|
||||
SeedArtists("Alpha", "Bravo", "Charlie");
|
||||
ArtistAlphaFilterSpecification specification = new(alphaKey, false);
|
||||
|
||||
// Act
|
||||
List<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal([matchingName], result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds artists with the provided names.
|
||||
/// </summary>
|
||||
/// <param name="names">The names of the artists to seed.</param>
|
||||
/// <returns>The seeded <see cref="ArtistEntity"/> instances.</returns>
|
||||
private List<ArtistEntity> SeedArtists(params string[] names)
|
||||
{
|
||||
List<ArtistEntity> entities = [];
|
||||
foreach (string name in names)
|
||||
entities.Add(_artistEntityFixture.Create(name: name, includeAlbums: false, includeContributors: false));
|
||||
_context.Artists.AddRange(entities);
|
||||
_context.SaveChanges();
|
||||
return entities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the database context and its underlying connection.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_context.Dispose();
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
+83
-1
@@ -567,7 +567,7 @@ public class TrackRepositoryTests
|
||||
|
||||
List<TrackEntity> albumTracks = [firstDiscFirstTrack, firstDiscSecondTrack, secondDiscTrack];
|
||||
Guid[] expectedOrder = [.. albumTracks
|
||||
.OrderBy(track => track.DiscNumber)
|
||||
.OrderBy(track => track.DiscNumber ?? 1)
|
||||
.ThenBy(track => track.TrackNumber)
|
||||
.ThenBy(track => track.Id)
|
||||
.Select(track => track.Id)];
|
||||
@@ -634,6 +634,34 @@ public class TrackRepositoryTests
|
||||
Assert.Equal(3, page.PerPage);
|
||||
Assert.Equal(1, page.NumberOfPages);
|
||||
Assert.DoesNotContain(page.Data, row => row.Id == trackOfAnotherAlbum.Id);
|
||||
Assert.Equal(tracks.Select(track => track.DurationInSeconds), page.Data.Select(row => row.DurationInSeconds));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTracksLiteByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-lite-nodisc-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
TrackRepository sut = new(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AlbumEntity album = await SeedAlbumAsync(context, libraryId);
|
||||
TrackEntity secondTrackWithoutDiscNumber = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/second.flac", trackNumber: 2, includeMetadata: false);
|
||||
secondTrackWithoutDiscNumber.DiscNumber = null;
|
||||
TrackEntity thirdTrack = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/third.flac", trackNumber: 3, includeMetadata: false);
|
||||
thirdTrack.DiscNumber = 1;
|
||||
context.Tracks.AddRange(secondTrackWithoutDiscNumber, thirdTrack);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<TrackLiteRow>> result = await sut.GetTracksLiteByAlbumIdAsync(album.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal([secondTrackWithoutDiscNumber.Id, thirdTrack.Id], result.Value.Data.Select(row => row.Id));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -686,6 +714,60 @@ public class TrackRepositoryTests
|
||||
Assert.Equal(expectedRowCount, page.Data.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-nodisc-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
TrackRepository sut = new(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AlbumEntity album = await SeedAlbumAsync(context, libraryId);
|
||||
TrackEntity secondDiscTrack = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/second-disc.flac", trackNumber: 1, includeMetadata: false);
|
||||
secondDiscTrack.DiscNumber = 2;
|
||||
TrackEntity trackWithoutDiscNumber = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/first-disc.flac", trackNumber: 2, includeMetadata: false);
|
||||
trackWithoutDiscNumber.DiscNumber = null;
|
||||
context.Tracks.AddRange(secondDiscTrack, trackWithoutDiscNumber);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<TrackEntity>> result = await sut.GetByAlbumIdAsync(album.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
// A track without a disc number belongs to the first disc, so it is ordered before the tracks of disc 2.
|
||||
Assert.Equal([trackWithoutDiscNumber.Id, secondDiscTrack.Id], result.Value.Select(track => track.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTracksLiteByAlbumIdAsync_WhenCalled_ShouldProjectTheDurationInSeconds()
|
||||
{
|
||||
// Arrange
|
||||
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-lite-duration-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
|
||||
anchorConnection.Open();
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
|
||||
context.Database.EnsureCreated();
|
||||
TrackRepository sut = new(context);
|
||||
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
AlbumEntity album = await SeedAlbumAsync(context, libraryId);
|
||||
TrackEntity track = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/the-prophet-song.flac", includeMetadata: false);
|
||||
track.DurationInSeconds = 367;
|
||||
context.Tracks.Add(track);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
Result<PaginatedResultDto<TrackLiteRow>> result = await sut.GetTracksLiteByAlbumIdAsync(album.Id, null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
TrackLiteRow row = Assert.Single(result.Value.Data);
|
||||
Assert.Equal(367, row.DurationInSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds an artist and the album that owns the tracks of the library identified by <paramref name="libraryId"/>, so that the required foreign keys of a track are satisfied.
|
||||
/// </summary>
|
||||
|
||||
+1
@@ -77,6 +77,7 @@ public class GetAlbumTracksLiteEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
Assert.Equal(1, tracks!.Count);
|
||||
TrackLiteResponse track = Assert.Single(tracks.Data);
|
||||
Assert.Equal("Bohemian Rhapsody", track.Title);
|
||||
Assert.True(track.DurationInSeconds > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+5
-1
@@ -18,6 +18,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
@@ -33,7 +34,8 @@ public class GetArtistAlbumsLiteEndpointTests : IClassFixture<AuthenticatedLumin
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
@@ -79,6 +81,8 @@ public class GetArtistAlbumsLiteEndpointTests : IClassFixture<AuthenticatedLumin
|
||||
Assert.Equal(2, albums.Data.Count);
|
||||
Assert.Contains(albums.Data, album => album.Title == "A Night at the Opera");
|
||||
Assert.Contains(albums.Data, album => album.Title == "News of the World");
|
||||
// The release types and the release year are exposed by the read model, so the lite listing can group and order the releases of an artist.
|
||||
Assert.All(albums.Data, album => Assert.NotEmpty(album.ReleaseTypes!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+149
@@ -97,6 +97,155 @@ public class GetArtistsLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiF
|
||||
Assert.Equal(0, paginatedArtists.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyLetter_ShouldReturnOnlyArtistsStartingWithThatLetter()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "Queen");
|
||||
await SeedArtistAsync(libraryId, "The Queen");
|
||||
await SeedArtistAsync(libraryId, "Radiohead");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=q");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
ArtistLiteResponse artist = Assert.Single(paginatedArtists!.Data);
|
||||
Assert.Equal("Queen", artist.Name);
|
||||
Assert.Equal(1, paginatedArtists.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyLetterAndIgnoreThePrefix_ShouldIncludeThePrefixedNames()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "Queen");
|
||||
await SeedArtistAsync(libraryId, "The Queen");
|
||||
await SeedArtistAsync(libraryId, "Radiohead");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=q&shouldIgnoreThePrefixForAlphaPicker=true");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Equal(2, paginatedArtists!.Count);
|
||||
Assert.Contains(paginatedArtists.Data, artist => artist.Name == "Queen");
|
||||
Assert.Contains(paginatedArtists.Data, artist => artist.Name == "The Queen");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyNumber_ShouldReturnOnlyArtistsStartingWithADigit()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "1984");
|
||||
await SeedArtistAsync(libraryId, "7th Sense");
|
||||
await SeedArtistAsync(libraryId, "Adele");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=%23");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Equal(2, paginatedArtists!.Count);
|
||||
Assert.Contains(paginatedArtists.Data, artist => artist.Name == "1984");
|
||||
Assert.Contains(paginatedArtists.Data, artist => artist.Name == "7th Sense");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeySymbol_ShouldReturnOnlyArtistsStartingWithASymbol()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "!Important");
|
||||
await SeedArtistAsync(libraryId, "1984");
|
||||
await SeedArtistAsync(libraryId, "Adele");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=%2A");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
ArtistLiteResponse artist = Assert.Single(paginatedArtists!.Data);
|
||||
Assert.Equal("!Important", artist.Name);
|
||||
Assert.Equal(1, paginatedArtists.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithSearchTermAndFilterAlphaKey_ShouldReturnOnlyArtistsSatisfyingBothFilters()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
// The search term matches only one artist, while the alpha key matches only the other, so no artist satisfies both filters at once.
|
||||
await SeedArtistAsync(libraryId, "The Fellowship Band");
|
||||
await SeedArtistAsync(libraryId, "Zoo");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?searchTerm={Uri.EscapeDataString("Fellowship")}&filterAlphaKey=z");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Empty(paginatedArtists!.Data);
|
||||
Assert.Equal(0, paginatedArtists.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenSortedByNameAscending_ShouldReturnArtistsInAscendingOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "Zulu");
|
||||
await SeedArtistAsync(libraryId, "Mike");
|
||||
await SeedArtistAsync(libraryId, "Alpha");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?sortBy=name&sortOrder=Ascending");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Equal(new[] { "Alpha", "Mike", "Zulu" }, paginatedArtists!.Data.Select(artist => artist.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenSortedByNameDescending_ShouldReturnArtistsInDescendingOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
await SeedArtistAsync(libraryId, "Zulu");
|
||||
await SeedArtistAsync(libraryId, "Mike");
|
||||
await SeedArtistAsync(libraryId, "Alpha");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?sortBy=name&sortOrder=Descending");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Equal(new[] { "Zulu", "Mike", "Alpha" }, paginatedArtists!.Data.Select(artist => artist.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenLibraryBelongsToAnotherUser_ShouldReturnForbidden()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user