mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 04:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+300
@@ -0,0 +1,300 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Core;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Core.Settings;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Fixtures.Common.Models.DTO.Settings;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.IntegrationTests.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="LocalMusicAlbumArtworkProvider"/> class, reading real image and audio files from the file system.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LocalMusicAlbumArtworkProviderTests : IDisposable
|
||||
{
|
||||
private static readonly byte[] s_embeddedCoverBytes = [0xFF, 0xD8, 0xFF, 0xE0, 0x01, 0x02, 0x03, 0xFF, 0xD9];
|
||||
|
||||
private readonly AlbumMetadataLookupDtoFixture _albumMetadataLookupDtoFixture = new();
|
||||
private readonly LocalMusicArtworkSettingsDtoFixture _localMusicArtworkSettingsDtoFixture = new();
|
||||
private readonly string _temporaryDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalMusicAlbumArtworkProviderTests"/> class.
|
||||
/// </summary>
|
||||
public LocalMusicAlbumArtworkProviderTests()
|
||||
{
|
||||
_temporaryDirectory = Path.Combine(Path.GetTempPath(), $"lumina-local-music-album-artwork-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_temporaryDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_WhenCalled_ShouldReturnTheProviderDisplayName()
|
||||
{
|
||||
// Arrange
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
|
||||
// Act
|
||||
string result = sut.Name;
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Local Music Artwork", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryTypes_WhenCalled_ShouldReturnMusic()
|
||||
{
|
||||
// Arrange
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<LibraryType> result = sut.SupportedLibraryTypes;
|
||||
|
||||
// Assert
|
||||
Assert.Equal([LibraryType.Music], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequiresWebAccess_WhenCalled_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
|
||||
// Act
|
||||
bool result = sut.RequiresWebAccess;
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasDiskImages_ShouldReturnTheDiskArtwork()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestAudioFileFactory.CreateWav(Path.Combine(albumDirectory, "track.wav"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(albumDirectory, "cover.jpg"), null),
|
||||
new(ArtworkType.Back, 0, Path.Combine(albumDirectory, "back.png"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasACoverOnDisk_ShouldNotExtractTheEmbeddedCover()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(Path.Combine(albumDirectory, "track.wav"), s_embeddedCoverBytes);
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "cover.jpg"), artwork.LocalPath);
|
||||
Assert.Null(artwork.RemoteUrl);
|
||||
Assert.False(artwork.IsTemporary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasNoCoverOnDiskAndExtractionIsEnabled_ShouldReturnTheEmbeddedCover()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(Path.Combine(albumDirectory, "track.wav"), s_embeddedCoverBytes);
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, result.Count);
|
||||
Assert.Equal(ArtworkType.Back, result[0].Type);
|
||||
Assert.Equal(0, result[0].Ordinal);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "back.png"), result[0].LocalPath);
|
||||
Assert.Null(result[0].RemoteUrl);
|
||||
Assert.False(result[0].IsTemporary);
|
||||
Assert.Equal(ArtworkType.Cover, result[1].Type);
|
||||
Assert.Equal(0, result[1].Ordinal);
|
||||
Assert.NotNull(result[1].LocalPath);
|
||||
Assert.EndsWith(".jpg", result[1].LocalPath);
|
||||
Assert.True(File.Exists(result[1].LocalPath));
|
||||
Assert.Equal(s_embeddedCoverBytes, File.ReadAllBytes(result[1].LocalPath!));
|
||||
Assert.Null(result[1].RemoteUrl);
|
||||
Assert.True(result[1].IsTemporary);
|
||||
File.Delete(result[1].LocalPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasNoCoverOnDiskAndExtractionIsDisabled_ShouldReturnOnlyTheDiskArtwork()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(Path.Combine(albumDirectory, "track.wav"), s_embeddedCoverBytes);
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: false);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Back, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "back.png"), artwork.LocalPath);
|
||||
Assert.Null(artwork.RemoteUrl);
|
||||
Assert.False(artwork.IsTemporary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasNoCoverOnDiskAndTheTrackHasNoEmbeddedCover_ShouldReturnOnlyTheDiskArtwork()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestAudioFileFactory.CreateWav(Path.Combine(albumDirectory, "track.wav"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Back, artwork.Type);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "back.png"), artwork.LocalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheTrackHasNoImagesAtAll_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestAudioFileFactory.CreateWav(Path.Combine(albumDirectory, "track.wav"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A null path contributes no artwork.
|
||||
[InlineData("")] // An empty path contributes no artwork.
|
||||
[InlineData(" ")] // A white space path contributes no artwork.
|
||||
[InlineData("track.flac")] // A path without a directory part contributes no artwork.
|
||||
public async Task GetArtworkAsync_WhenTheTrackPathDoesNotPointToADirectory_ShouldReturnEmpty(string? trackPath)
|
||||
{
|
||||
// Arrange
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheTrackDirectoryDoesNotExist_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "Missing", "Album", "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheAlbumHasNoCoverOnDiskAndTheCancellationTokenIsAlreadyCancelled_ShouldCancelTheOperation()
|
||||
{
|
||||
// Arrange
|
||||
using (CancellationTokenSource cancellationTokenSource = new())
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestAudioFileFactory.CreateWav(Path.Combine(albumDirectory, "track.wav"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.wav");
|
||||
LocalMusicAlbumArtworkProvider sut = CreateProvider(shouldExtractEmbeddedCover: true);
|
||||
AlbumMetadataLookupDto lookup = _albumMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
Task Act()
|
||||
{
|
||||
return sut.GetArtworkAsync(lookup, cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(Act);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalMusicAlbumArtworkProvider"/> whose settings provider carries the provided embedded cover extraction setting.
|
||||
/// </summary>
|
||||
/// <param name="shouldExtractEmbeddedCover">Whether the cover embedded in the audio files is extracted when the album has no cover image on disk.</param>
|
||||
/// <returns>The created provider.</returns>
|
||||
private LocalMusicAlbumArtworkProvider CreateProvider(bool shouldExtractEmbeddedCover)
|
||||
{
|
||||
LocalMusicArtworkSettingsProvider settingsProvider = new(
|
||||
null,
|
||||
Guid.NewGuid(),
|
||||
_localMusicArtworkSettingsDtoFixture.Create(shouldExtractEmbeddedCover: shouldExtractEmbeddedCover));
|
||||
return new LocalMusicAlbumArtworkProvider(settingsProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary directory created for the test.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_temporaryDirectory))
|
||||
Directory.Delete(_temporaryDirectory, recursive: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Core;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.IntegrationTests.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="LocalMusicArtistArtworkProvider"/> class, reading real image files from the file system.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LocalMusicArtistArtworkProviderTests : IDisposable
|
||||
{
|
||||
private readonly ArtistMetadataLookupDtoFixture _artistMetadataLookupDtoFixture = new();
|
||||
private readonly LocalMusicArtistArtworkProvider _sut = new();
|
||||
private readonly string _temporaryDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalMusicArtistArtworkProviderTests"/> class.
|
||||
/// </summary>
|
||||
public LocalMusicArtistArtworkProviderTests()
|
||||
{
|
||||
_temporaryDirectory = Path.Combine(Path.GetTempPath(), $"lumina-local-music-artist-artwork-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_temporaryDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_WhenCalled_ShouldReturnTheProviderDisplayName()
|
||||
{
|
||||
// Act
|
||||
string result = _sut.Name;
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Local Music Artwork", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryTypes_WhenCalled_ShouldReturnMusic()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryType> result = _sut.SupportedLibraryTypes;
|
||||
|
||||
// Assert
|
||||
Assert.Equal([LibraryType.Music], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequiresWebAccess_WhenCalled_ShouldReturnFalse()
|
||||
{
|
||||
// Act
|
||||
bool result = _sut.RequiresWebAccess;
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheArtistDirectoryCarriesImages_ShouldReturnTheArtistArtwork()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "folder.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(artistDirectory, "banner.png"));
|
||||
TestImageFileFactory.CreateWebp(Path.Combine(artistDirectory, "logo.webp"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
ArtistMetadataLookupDto lookup = _artistMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await _sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(artistDirectory, "folder.jpg"), null),
|
||||
new(ArtworkType.Banner, 0, Path.Combine(artistDirectory, "banner.png"), null),
|
||||
new(ArtworkType.Logo, 0, Path.Combine(artistDirectory, "logo.webp"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenNoArtistImagesExist_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "back.jpg"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
ArtistMetadataLookupDto lookup = _artistMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await _sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A null path contributes no artwork.
|
||||
[InlineData("")] // An empty path contributes no artwork.
|
||||
[InlineData(" ")] // A white space path contributes no artwork.
|
||||
[InlineData("track.flac")] // A path without a directory part contributes no artwork.
|
||||
public async Task GetArtworkAsync_WhenTheTrackPathDoesNotPointToADirectory_ShouldReturnEmpty(string? trackPath)
|
||||
{
|
||||
// Arrange
|
||||
ArtistMetadataLookupDto lookup = _artistMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await _sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheTrackDirectoryDoesNotExist_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "Missing", "Artist", "track.flac");
|
||||
ArtistMetadataLookupDto lookup = _artistMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await _sut.GetArtworkAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtworkAsync_WhenTheCancellationTokenIsAlreadyCancelled_ShouldStillReturnTheDiskArtwork()
|
||||
{
|
||||
// Arrange
|
||||
using (CancellationTokenSource cancellationTokenSource = new())
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "folder.jpg"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
ArtistMetadataLookupDto lookup = _artistMetadataLookupDtoFixture.Create(path: trackPath);
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = await _sut.GetArtworkAsync(lookup, cancellationTokenSource.Token);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(Path.Combine(artistDirectory, "folder.jpg"), artwork.LocalPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary directory created for the test.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_temporaryDirectory))
|
||||
Directory.Delete(_temporaryDirectory, recursive: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Core;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.IntegrationTests.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="LocalMusicArtworkEmbeddedCoverExtractor"/> class, reading real audio containers that carry embedded pictures.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LocalMusicArtworkEmbeddedCoverExtractorTests : IDisposable
|
||||
{
|
||||
private static readonly byte[] s_coverBytes = [0xFF, 0xD8, 0xFF, 0xE0, 0x11, 0x22, 0x33, 0xFF, 0xD9];
|
||||
|
||||
private readonly string _temporaryDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalMusicArtworkEmbeddedCoverExtractorTests"/> class.
|
||||
/// </summary>
|
||||
public LocalMusicArtworkEmbeddedCoverExtractorTests()
|
||||
{
|
||||
_temporaryDirectory = Path.Combine(Path.GetTempPath(), $"lumina-local-music-embedded-cover-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_temporaryDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheTrackCarriesAnEmbeddedCover_ShouldReturnATemporaryCoverArtwork()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.wav");
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(trackPath, s_coverBytes, "image/jpeg");
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(ArtworkType.Cover, result.Type);
|
||||
Assert.Equal(0, result.Ordinal);
|
||||
Assert.NotNull(result.LocalPath);
|
||||
Assert.StartsWith(Path.GetTempPath(), result.LocalPath);
|
||||
Assert.EndsWith(".jpg", result.LocalPath);
|
||||
Assert.True(File.Exists(result.LocalPath));
|
||||
Assert.Equal(s_coverBytes, File.ReadAllBytes(result.LocalPath!));
|
||||
Assert.Null(result.RemoteUrl);
|
||||
Assert.True(result.IsTemporary);
|
||||
File.Delete(result.LocalPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheTrackHasNoEmbeddedCover_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.wav");
|
||||
TestAudioFileFactory.CreateWav(trackPath);
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A null path contributes no cover.
|
||||
[InlineData("")] // An empty path contributes no cover.
|
||||
[InlineData(" ")] // A white space path contributes no cover.
|
||||
public void Extract_WhenTheTrackPathIsNullOrEmpty_ShouldReturnNull(string? trackPath)
|
||||
{
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheTrackFileDoesNotExist_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "missing.wav");
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("image/jpeg", ".jpg")]
|
||||
[InlineData("image/png", ".png")]
|
||||
[InlineData("image/webp", ".webp")]
|
||||
[InlineData("image/bmp", ".bmp")]
|
||||
[InlineData("image/x-ms-bmp", ".bmp")]
|
||||
[InlineData("image/gif", ".gif")]
|
||||
[InlineData("image/tiff", ".tiff")]
|
||||
[InlineData("IMAGE/PNG", ".png")] // The MIME type is matched without regard to casing.
|
||||
[InlineData(" image/png ", ".png")] // The MIME type is trimmed before it is matched.
|
||||
[InlineData("application/octet-stream", ".jpg")] // An unknown MIME type falls back to the JPEG extension.
|
||||
[InlineData("", ".jpg")] // An empty MIME type falls back to the JPEG extension.
|
||||
[InlineData(null, ".jpg")] // A missing MIME type falls back to the JPEG extension.
|
||||
public void Extract_WhenTheMimeTypeIsProvided_ShouldUseTheMatchingFileExtension(string? mimeType, string expectedExtension)
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.wav");
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(trackPath, s_coverBytes, mimeType);
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.LocalPath);
|
||||
Assert.EndsWith(expectedExtension, result.LocalPath);
|
||||
Assert.Equal(s_coverBytes, File.ReadAllBytes(result.LocalPath!));
|
||||
Assert.True(result.IsTemporary);
|
||||
File.Delete(result.LocalPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheEmbeddedCoverIsExactlyTheMaximumSize_ShouldReturnTheCover()
|
||||
{
|
||||
// Arrange
|
||||
byte[] maximumCover = new byte[10 * 1024 * 1024];
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.wav");
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(trackPath, maximumCover, "image/jpeg");
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.LocalPath);
|
||||
Assert.Equal(maximumCover, File.ReadAllBytes(result.LocalPath!));
|
||||
Assert.True(result.IsTemporary);
|
||||
File.Delete(result.LocalPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheEmbeddedCoverIsLargerThanTheMaximumSize_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
byte[] oversizedCover = new byte[10 * 1024 * 1024 + 1];
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.wav");
|
||||
TestAudioFileFactory.CreateWavWithEmbeddedCover(trackPath, oversizedCover, "image/jpeg");
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheTrackIsNotAnAudioFile_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.txt");
|
||||
TestAudioFileFactory.CreateUnsupportedFile(trackPath);
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extract_WhenTheAudioFileIsCorrupt_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "track.mp3");
|
||||
TestAudioFileFactory.CreateUnsupportedFile(trackPath);
|
||||
|
||||
// Act
|
||||
ArtworkDto? result = LocalMusicArtworkEmbeddedCoverExtractor.Extract(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary directory created for the test.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_temporaryDirectory))
|
||||
Directory.Delete(_temporaryDirectory, recursive: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
+487
@@ -0,0 +1,487 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Core;
|
||||
using Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.IntegrationTests.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="LocalMusicArtworkScanner"/> class, scanning real image files on the file system.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LocalMusicArtworkScannerTests : IDisposable
|
||||
{
|
||||
private readonly string _temporaryDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalMusicArtworkScannerTests"/> class.
|
||||
/// </summary>
|
||||
public LocalMusicArtworkScannerTests()
|
||||
{
|
||||
_temporaryDirectory = Path.Combine(Path.GetTempPath(), $"lumina-local-music-artwork-scanner-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_temporaryDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheAlbumDirectoryCarriesTheStandardImages_ShouldReturnEachArtworkType()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Artist", "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "front.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "back.png"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet1.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "booklet2.png"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "disk.png"));
|
||||
TestImageFileFactory.CreateGif(Path.Combine(albumDirectory, "tray.gif"));
|
||||
TestImageFileFactory.CreateTiff(Path.Combine(albumDirectory, "spine.tiff"));
|
||||
TestImageFileFactory.CreateBmp(Path.Combine(albumDirectory, "obi.bmp"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "sticker.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(albumDirectory, "poster.png"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "liner.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(albumDirectory, "cover.jpg"), null),
|
||||
new(ArtworkType.Front, 0, Path.Combine(albumDirectory, "front.jpg"), null),
|
||||
new(ArtworkType.Back, 0, Path.Combine(albumDirectory, "back.png"), null),
|
||||
new(ArtworkType.Booklet, 1, Path.Combine(albumDirectory, "booklet1.jpg"), null),
|
||||
new(ArtworkType.Booklet, 2, Path.Combine(albumDirectory, "booklet2.png"), null),
|
||||
new(ArtworkType.Medium, 0, Path.Combine(albumDirectory, "disk.png"), null),
|
||||
new(ArtworkType.Tray, 0, Path.Combine(albumDirectory, "tray.gif"), null),
|
||||
new(ArtworkType.Spine, 0, Path.Combine(albumDirectory, "spine.tiff"), null),
|
||||
new(ArtworkType.Obi, 0, Path.Combine(albumDirectory, "obi.bmp"), null),
|
||||
new(ArtworkType.Sticker, 0, Path.Combine(albumDirectory, "sticker.jpg"), null),
|
||||
new(ArtworkType.Poster, 0, Path.Combine(albumDirectory, "poster.png"), null),
|
||||
new(ArtworkType.Liner, 0, Path.Combine(albumDirectory, "liner.jpg"), null)
|
||||
];
|
||||
Assert.Equal(12, result.Count);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheStemCarriesANumber_ShouldUseItAsTheOrdinal()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet1.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet2.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "disk1.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "disk2.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Booklet, 0, Path.Combine(albumDirectory, "booklet.jpg"), null),
|
||||
new(ArtworkType.Booklet, 1, Path.Combine(albumDirectory, "booklet1.jpg"), null),
|
||||
new(ArtworkType.Booklet, 2, Path.Combine(albumDirectory, "booklet2.jpg"), null),
|
||||
new(ArtworkType.Medium, 1, Path.Combine(albumDirectory, "disk1.jpg"), null),
|
||||
new(ArtworkType.Medium, 2, Path.Combine(albumDirectory, "disk2.jpg"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheStemHasAHyphenOrUnderscoreBeforeTheNumber_ShouldTrimTheSeparator()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet - 1.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "booklet_2.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Booklet, 1, Path.Combine(albumDirectory, "booklet - 1.jpg"), null),
|
||||
new(ArtworkType.Booklet, 2, Path.Combine(albumDirectory, "booklet_2.jpg"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenBothCoverAndFrontExist_ShouldReturnThemAsDistinctArtworks()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "front.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(albumDirectory, "cover.jpg"), null),
|
||||
new(ArtworkType.Front, 0, Path.Combine(albumDirectory, "front.jpg"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenSeveralNamesMapToTheSameTypeAndOrdinal_ShouldKeepOnlyThePreferredFile()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "disk.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "disc.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
// Both file names describe the medium of the album, and the one that sorts first by name wins, so that a single image is stored per type and ordinal.
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Medium, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "disc.jpg"), artwork.LocalPath);
|
||||
Assert.Null(artwork.RemoteUrl);
|
||||
Assert.False(artwork.IsTemporary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenAFileIsNotAnImage_ShouldIgnoreIt()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateTextFile(Path.Combine(albumDirectory, "notes.txt"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "cover.jpg"), artwork.LocalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheImageExtensionIsUppercase_ShouldIgnoreIt()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.JPG"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "back.JPEG"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheImageNameHasDifferentCasing_ShouldIgnoreIt()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "Cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "BACK.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheImageNameIsNotRecognized_ShouldIgnoreIt()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "random.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "folder.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "backdrop.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheAlbumIsMultiDiscAndTheParentDirectoryCarriesTheArtwork_ShouldFindIt()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
string discDirectory = Path.Combine(albumDirectory, "CD1");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "back.jpg"));
|
||||
Directory.CreateDirectory(discDirectory);
|
||||
string trackPath = Path.Combine(discDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(albumDirectory, "cover.jpg"), null),
|
||||
new(ArtworkType.Back, 0, Path.Combine(albumDirectory, "back.jpg"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenBothTheDiscAndTheParentDirectoryCarryTheSameArtwork_ShouldPreferTheNearest()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
string discDirectory = Path.Combine(albumDirectory, "CD1");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(discDirectory, "cover.jpg"));
|
||||
string trackPath = Path.Combine(discDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(discDirectory, "cover.jpg"), artwork.LocalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheDiscAndTheParentDirectoryCarryDifferentArtworks_ShouldReturnBoth()
|
||||
{
|
||||
// Arrange
|
||||
string albumDirectory = Path.Combine(_temporaryDirectory, "Album");
|
||||
string discDirectory = Path.Combine(albumDirectory, "CD1");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(discDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "back.jpg"));
|
||||
string trackPath = Path.Combine(discDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(discDirectory, "cover.jpg"), null),
|
||||
new(ArtworkType.Back, 0, Path.Combine(albumDirectory, "back.jpg"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheArtworkIsMoreThanTwoLevelsAboveTheTrack_ShouldNotFindIt()
|
||||
{
|
||||
// Arrange
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(_temporaryDirectory, "cover.jpg"));
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "Album", "CD1", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A null path contributes no artwork.
|
||||
[InlineData("")] // An empty path contributes no artwork.
|
||||
[InlineData(" ")] // A white space path contributes no artwork.
|
||||
[InlineData("track.flac")] // A path without a directory part contributes no artwork.
|
||||
public void ScanAlbumArtwork_WhenTheTrackPathDoesNotPointToADirectory_ShouldReturnEmpty(string? trackPath)
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanAlbumArtwork_WhenTheAlbumDirectoryDoesNotExist_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "Missing", "Album", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanAlbumArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheArtistDirectoryCarriesTheStandardImages_ShouldReturnEachArtworkType()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "folder.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "backdrop.jpg"));
|
||||
TestImageFileFactory.CreatePng(Path.Combine(artistDirectory, "banner.png"));
|
||||
TestImageFileFactory.CreateWebp(Path.Combine(artistDirectory, "logo.webp"));
|
||||
TestImageFileFactory.CreateGif(Path.Combine(artistDirectory, "thumb.gif"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
List<ArtworkDto> expected =
|
||||
[
|
||||
new(ArtworkType.Cover, 0, Path.Combine(artistDirectory, "folder.jpg"), null),
|
||||
new(ArtworkType.Backdrop, 0, Path.Combine(artistDirectory, "backdrop.jpg"), null),
|
||||
new(ArtworkType.Banner, 0, Path.Combine(artistDirectory, "banner.png"), null),
|
||||
new(ArtworkType.Logo, 0, Path.Combine(artistDirectory, "logo.webp"), null),
|
||||
new(ArtworkType.Thumb, 0, Path.Combine(artistDirectory, "thumb.gif"), null)
|
||||
];
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheDirectoryCarriesOnlyAlbumImages_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "cover.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "back.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "disk.jpg"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheArtistImagesAreInAnAncestorDirectory_ShouldFindThem()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "folder.jpg"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "CD1", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(artistDirectory, "folder.jpg"), artwork.LocalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenSeveralAncestorDirectoriesCarryArtistImages_ShouldPreferTheNearest()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
string albumDirectory = Path.Combine(artistDirectory, "Album");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "backdrop.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "folder.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(albumDirectory, "cover.jpg"));
|
||||
string trackPath = Path.Combine(albumDirectory, "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
// The nearest ancestor that carries an artist image wins, and the album images of that directory are not part of the artist artwork.
|
||||
ArtworkDto artwork = Assert.Single(result);
|
||||
Assert.Equal(ArtworkType.Cover, artwork.Type);
|
||||
Assert.Equal(0, artwork.Ordinal);
|
||||
Assert.Equal(Path.Combine(albumDirectory, "folder.jpg"), artwork.LocalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheArtistImagesAreBeyondTheSearchDepth_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(_temporaryDirectory, "folder.jpg"));
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "A", "B", "C", "D", "E", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheImageNameHasDifferentCasing_ShouldIgnoreIt()
|
||||
{
|
||||
// Arrange
|
||||
string artistDirectory = Path.Combine(_temporaryDirectory, "Artist");
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "Folder.jpg"));
|
||||
TestImageFileFactory.CreateJpeg(Path.Combine(artistDirectory, "Backdrop.jpg"));
|
||||
string trackPath = Path.Combine(artistDirectory, "Album", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // A null path contributes no artwork.
|
||||
[InlineData("")] // An empty path contributes no artwork.
|
||||
[InlineData(" ")] // A white space path contributes no artwork.
|
||||
[InlineData("track.flac")] // A path without a directory part contributes no artwork.
|
||||
public void ScanArtistArtwork_WhenTheTrackPathDoesNotPointToADirectory_ShouldReturnEmpty(string? trackPath)
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScanArtistArtwork_WhenTheAncestorDirectoryDoesNotExist_ShouldReturnEmpty()
|
||||
{
|
||||
// Arrange
|
||||
string trackPath = Path.Combine(_temporaryDirectory, "Missing", "Artist", "track.flac");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<ArtworkDto> result = LocalMusicArtworkScanner.ScanArtistArtwork(trackPath);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary directory created for the test.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_temporaryDirectory))
|
||||
Directory.Delete(_temporaryDirectory, recursive: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="Xunit.CollectionBehaviorAttribute">
|
||||
<_Parameter1>DisableTestParallelization = true</_Parameter1>
|
||||
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" />
|
||||
<PackageReference Include="Bogus" />
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="NSubstitute" />
|
||||
<PackageReference Include="TagLibSharp" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\plugins\Lumina.Plugins.LocalMusicArtwork\Lumina.Plugins.LocalMusicArtwork.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Lumina.Plugins.LocalMusicArtwork.Fixtures\Lumina.Plugins.LocalMusicArtwork.Fixtures.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Lumina.Contracts.Fixtures\Lumina.Contracts.Fixtures.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user