Renames project paths from Lumina to Nemera

This commit is contained in:
BinaryAlley committed 2026-11-27 15:34:43 +02:00
1 parent ce6fddb4c9
commit 0f659a4877
6450 files changed

No files matched your search

@@ -0,0 +1,335 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="AddMediaLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddMediaLibraryRequestMappingTests
{
private readonly AddLibraryRequestFixture _addLibraryRequestFixture = new();
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
private readonly LibraryPathTemplatePartRequestFixture _libraryPathTemplatePartRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
title: "My Library",
libraryType: "Book",
contentLocations: ["C:/Books", "D:/Media/Books"],
coverImage: "D:/poster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
shouldSkipHiddenFilesAndDirectoriesDuringScan: true,
isContentOnSsd: true,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 90
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result);
Assert.Equal(request.Title, result.Title);
Assert.Equal(request.LibraryType, result.LibraryType);
Assert.Equal(request.ContentLocations, result.ContentLocations);
Assert.Equal(request.CoverImage, result.CoverImage);
Assert.Equal(request.IsEnabled, result.IsEnabled);
Assert.Equal(request.IsLocked, result.IsLocked);
Assert.Equal(request.CanDownloadMetadataFromWeb, result.CanDownloadMetadataFromWeb);
Assert.Equal(request.ShouldSaveMetadataInMediaDirectories, result.ShouldSaveMetadataInMediaDirectories);
Assert.Equal(request.ShouldSkipHiddenFilesAndDirectoriesDuringScan, result.ShouldSkipHiddenFilesAndDirectoriesDuringScan);
Assert.Equal(request.IsContentOnSsd, result.IsContentOnSsd);
Assert.Equal(request.ShouldTrackConsumptionProgress, result.ShouldTrackConsumptionProgress);
Assert.Equal(request.CompletionThresholdPercentage, result.CompletionThresholdPercentage);
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
title: "My Library",
libraryType: libraryType.ToString(),
contentLocations: ["C:/Media"],
coverImage: "D:/poster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result);
Assert.Equal(request.Title, result.Title);
Assert.Equal(libraryType.ToString(), result.LibraryType);
Assert.Equal(request.ContentLocations, result.ContentLocations);
Assert.Equal(request.CoverImage, result.CoverImage);
Assert.Equal(request.IsEnabled, result.IsEnabled);
Assert.Equal(request.IsLocked, result.IsLocked);
Assert.Equal(request.CanDownloadMetadataFromWeb, result.CanDownloadMetadataFromWeb);
Assert.Equal(request.ShouldSaveMetadataInMediaDirectories, result.ShouldSaveMetadataInMediaDirectories);
}
[Fact]
public void ToCommand_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
string[] contentLocations =
[
"C:/Media/Books",
"D:/Books",
"E:/Digital Library/Books",
"F:/Reading Material"
];
AddLibraryRequest request = _addLibraryRequestFixture.Create(
title: "My Library",
libraryType: "Book",
contentLocations: contentLocations,
coverImage: "D:/poster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result);
Assert.Equal(contentLocations, result.ContentLocations);
}
[Fact]
public void ToCommand_WhenMappingWithNullCover_ShouldMapCorrectly()
{
// Arrange
string[] contentLocations =
[
"C:/Media/Books",
"D:/Books"
];
AddLibraryRequest request = _addLibraryRequestFixture.Create(
title: "My Library",
libraryType: "Book",
contentLocations: contentLocations,
coverImage: null,
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result);
Assert.Null(result.CoverImage);
}
[Fact]
public void ToCommand_WhenRequestHasPathTemplateParts_ShouldMapToDtoArray()
{
// Arrange
LibraryPathTemplatePartRequest literalPart = _libraryPathTemplatePartRequestFixture.Create(
kind: nameof(LibraryPathPartKind.Literal),
representation: "Various Artists",
isOptional: false);
LibraryPathTemplatePartRequest typedPart = _libraryPathTemplatePartRequestFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: "{0}",
isOptional: true);
AddLibraryRequest request = _addLibraryRequestFixture.Create(pathTemplateParts: [literalPart, typedPart]);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.PathTemplateParts);
Assert.Equal(2, result.PathTemplateParts.Length);
Assert.Equal(literalPart.Kind, result.PathTemplateParts[0].Kind);
Assert.Equal(literalPart.Representation, result.PathTemplateParts[0].Representation);
Assert.Equal(literalPart.IsOptional, result.PathTemplateParts[0].IsOptional);
Assert.Equal(typedPart.Kind, result.PathTemplateParts[1].Kind);
Assert.Equal(typedPart.Representation, result.PathTemplateParts[1].Representation);
Assert.Equal(typedPart.IsOptional, result.PathTemplateParts[1].IsOptional);
}
[Fact]
public void ToCommand_WhenPathTemplatePartsIsNull_ShouldMapToNull()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(pathTemplateParts: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.PathTemplateParts);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreSupplied_ShouldMapThem()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 75);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.True(result.ShouldTrackConsumptionProgress.Value);
Assert.Equal(75, result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreAbsent_ShouldPreserveThemAsNull()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: null,
completionThresholdPercentage: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProgressTrackingIsExplicitlyDisabled_ShouldPreserveTheDisabledFlagWithoutThreshold()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.False(result.ShouldTrackConsumptionProgress.Value);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProviderChoicesAreProvided_ShouldMapThemInOrder()
{
// Arrange
LibraryProviderSelectionRequest[] metadataProviders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: true), _libraryProviderSelectionRequestFixture.Create(isEnabled: false)];
LibraryProviderSelectionRequest[] artworkProviders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: false)];
LibraryProviderSelectionRequest[] bookReaders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: true)];
AddLibraryRequest request = _addLibraryRequestFixture.Create(metadataProviders: metadataProviders, artworkProviders: artworkProviders, bookReaders: bookReaders);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(metadataProviders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.MetadataProviders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
Assert.Equal(artworkProviders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.ArtworkProviders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
Assert.Equal(bookReaders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.BookReaders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
}
[Fact]
public void ToCommand_WhenProviderChoicesAreNotProvided_ShouldMapThemAsNull()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(metadataProviders: null, artworkProviders: null, bookReaders: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.MetadataProviders);
Assert.Null(result.ArtworkProviders);
Assert.Null(result.BookReaders);
}
[Fact]
public void ToCommand_WhenAProviderChoiceIsNull_ShouldMapItToAChoiceWithoutPluginId()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(metadataProviders: [null], artworkProviders: [null], bookReaders: [null]);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(Guid.Empty, Assert.Single(result.MetadataProviders!).PluginId);
Assert.Null(result.MetadataProviders![0].IsEnabled);
Assert.Equal(Guid.Empty, Assert.Single(result.ArtworkProviders!).PluginId);
Assert.Equal(Guid.Empty, Assert.Single(result.BookReaders!).PluginId);
}
[Fact]
public void ToCommand_WhenAPathTemplatePartIsNull_ShouldMapItToAPartWithoutKind()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(pathTemplateParts: [null]);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
LibraryPathTemplatePartDto part = Assert.Single(result.PathTemplateParts!);
Assert.Null(part.Kind);
Assert.Null(part.Representation);
Assert.False(part.IsOptional);
}
[Fact]
public void ToCommand_WhenAProviderChoiceHasNoEnabledState_ShouldMapTheStateAsNull()
{
// Arrange
LibraryProviderSelectionRequest choice = _libraryProviderSelectionRequestFixture.Create(includeIsEnabled: false);
AddLibraryRequest request = _addLibraryRequestFixture.Create(metadataProviders: [choice]);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
LibraryProviderSelectionDto mappedChoice = Assert.Single(result.MetadataProviders!);
Assert.Equal(choice.PluginId, mappedChoice.PluginId);
Assert.Null(mappedChoice.IsEnabled);
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="CancelLibraryScanRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CancelLibraryScanRequestMappingTests
{
private readonly CancelLibraryScanRequestFixture _cancelLibraryScanRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
CancelLibraryScanRequest request = _cancelLibraryScanRequestFixture.Create();
// Act
CancelLibraryScanCommand result = request.ToCommand();
// Assert
Assert.Equal(request.LibraryId, result.LibraryId);
Assert.Equal(request.ScanId, result.ScanId);
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="DeleteLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteLibraryRequestMappingTests
{
private readonly DeleteLibraryRequestFixture _deleteLibraryRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
Guid id = Guid.NewGuid();
DeleteLibraryRequest request = _deleteLibraryRequestFixture.Create(id);
// Act
DeleteLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(request.Id, result.Id);
}
}
@@ -0,0 +1,47 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="GetLibraryPathTemplatePartsRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryPathTemplatePartsRequestMappingTests
{
private readonly GetLibraryPathTemplatePartsRequestFixture _getLibraryPathTemplatePartsRequestFixture = new();
[Fact]
public void ToQuery_WhenMappingValidRequest_ShouldMapLibraryType()
{
// Arrange
GetLibraryPathTemplatePartsRequest request = _getLibraryPathTemplatePartsRequestFixture.Create(libraryType: "Book");
// Act
GetLibraryPathTemplatePartsQuery result = request.ToQuery();
// Assert
Assert.Equal("Book", result.LibraryType);
}
[Theory]
[InlineData("Book")] // A written content library type.
[InlineData("Movie")] // A video library type.
[InlineData("Music")] // An audio library type.
public void ToQuery_WhenMappingDifferentLibraryTypes_ShouldMapLibraryType(string libraryType)
{
// Arrange
GetLibraryPathTemplatePartsRequest request = _getLibraryPathTemplatePartsRequestFixture.Create(libraryType: libraryType);
// Act
GetLibraryPathTemplatePartsQuery result = request.ToQuery();
// Assert
Assert.Equal(libraryType, result.LibraryType);
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="GetLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryRequestMappingTests
{
private readonly GetLibraryRequestFixture _getLibraryRequestFixture = new();
[Fact]
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
Guid id = Guid.NewGuid();
GetLibraryRequest request = _getLibraryRequestFixture.Create(id);
// Act
GetLibraryQuery result = request.ToQuery();
// Assert
Assert.Equal(request.Id, result.Id);
}
}
@@ -0,0 +1,32 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="GetLibraryScanProgressRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryScanProgressRequestMappingTests
{
private readonly GetLibraryScanProgressRequestFixture _getLibraryScanProgressRequestFixture = new();
[Fact]
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
GetLibraryScanProgressRequest request = _getLibraryScanProgressRequestFixture.Create();
// Act
GetLibraryScanProgressQuery result = request.ToQuery();
// Assert
Assert.Equal(request.LibraryId, result.LibraryId);
Assert.Equal(request.ScanId, result.ScanId);
}
}
@@ -0,0 +1,406 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="LibraryEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryEntityMappingTests
{
private readonly LibraryEntityFixture _libraryEntityFixture = new();
private readonly LibraryPathTemplatePartEntityFixture _libraryPathTemplatePartEntityFixture = new();
[Fact]
public void ToResponse_WhenMappingValidLibraryEntity_ShouldMapCorrectly()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books", "D:/Media/Books"],
coverImage: "D:/myPoster.jpg",
shouldSkipHiddenFilesAndDirectoriesDuringScan: true,
isContentOnSsd: true);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Title, result.Title);
Assert.Equal(entity.LibraryType, result.LibraryType);
Assert.Equal(entity.ContentLocations.Select(l => l.Path), result.ContentLocations);
Assert.Equal(entity.CoverImage, result.CoverImage);
Assert.Equal(entity.ShouldSkipHiddenFilesAndDirectoriesDuringScan, result.ShouldSkipHiddenFilesAndDirectoriesDuringScan);
Assert.Equal(entity.IsContentOnSsd, result.IsContentOnSsd);
Assert.Equal(entity.ShouldTrackConsumptionProgress, result.ShouldTrackConsumptionProgress);
Assert.Equal(entity.CompletionThresholdPercentage, result.CompletionThresholdPercentage);
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToResponse_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: libraryType,
contentLocations: ["C:/Media"],
coverImage: "D:/myPoster.jpg");
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.NotNull(result);
Assert.Equal(libraryType, result.LibraryType);
}
[Fact]
public void ToResponse_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Media/Books", "D:/Books", "E:/Digital Library/Books", "F:/Reading Material"],
coverImage: "D:/myPoster.jpg");
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.NotNull(result);
Assert.Equal(entity.ContentLocations.Select(l => l.Path), result.ContentLocations);
}
[Fact]
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
{
// Arrange
DateTime updated = DateTime.UtcNow.AddDays(-1);
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
coverImage: "D:/myPoster.jpg");
entity.UpdatedOnUtc = updated;
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.NotNull(result);
Assert.Equal(updated, result.UpdatedOnUtc);
}
[Fact]
public void ToResponse_WhenMappingWithNullCoverImage_ShouldMapCorrectly()
{
// Arrange
DateTime updated = DateTime.UtcNow.AddDays(-1);
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"]);
entity.CoverImage = null;
entity.UpdatedOnUtc = updated;
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.NotNull(result);
Assert.Null(result.CoverImage);
}
[Fact]
public void ToResponse_WhenLibraryHasPathTemplateParts_ShouldOrderByPositionAndMapProperties()
{
// Arrange
LibraryPathTemplatePartEntity firstPart = _libraryPathTemplatePartEntityFixture.Create(
position: 2,
kind: LibraryPathPartKind.Artist,
representation: "{0}",
isOptional: true);
LibraryPathTemplatePartEntity secondPart = _libraryPathTemplatePartEntityFixture.Create(
position: 0,
kind: LibraryPathPartKind.Literal,
representation: "Various Artists");
LibraryPathTemplatePartEntity thirdPart = _libraryPathTemplatePartEntityFixture.Create(
position: 1,
kind: LibraryPathPartKind.Separator,
representation: string.Empty);
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
pathTemplateParts: [firstPart, secondPart, thirdPart]);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.Equal(3, result.PathTemplateParts.Count);
Assert.Equal(LibraryPathPartKind.Literal.ToString(), result.PathTemplateParts[0].Kind);
Assert.Equal("Various Artists", result.PathTemplateParts[0].Representation);
Assert.False(result.PathTemplateParts[0].IsOptional);
Assert.Equal(LibraryPathPartKind.Separator.ToString(), result.PathTemplateParts[1].Kind);
Assert.Equal(string.Empty, result.PathTemplateParts[1].Representation);
Assert.False(result.PathTemplateParts[1].IsOptional);
Assert.Equal(LibraryPathPartKind.Artist.ToString(), result.PathTemplateParts[2].Kind);
Assert.Equal("{0}", result.PathTemplateParts[2].Representation);
Assert.True(result.PathTemplateParts[2].IsOptional);
}
[Fact]
public void ToDomainEntity_WhenLibraryHasPathTemplateParts_ShouldBuildTemplateFromOrderedParts()
{
// Arrange
LibraryPathTemplatePartEntity firstPart = _libraryPathTemplatePartEntityFixture.Create(
position: 1,
kind: LibraryPathPartKind.Artist,
representation: "{0}",
isOptional: true);
LibraryPathTemplatePartEntity secondPart = _libraryPathTemplatePartEntityFixture.Create(
position: 0,
kind: LibraryPathPartKind.Literal,
representation: "Various Artists");
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
coverImage: "D:/cover.jpg",
shouldSkipHiddenFilesAndDirectoriesDuringScan: true,
isContentOnSsd: true,
pathTemplateParts: [firstPart, secondPart]);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.Equal(entity.Id, result.Value.Id.Value);
Assert.Equal(entity.UserId, result.Value.UserId.Value);
Assert.Equal(entity.Title, result.Value.Title);
Assert.Equal(entity.LibraryType, result.Value.LibraryType);
Assert.Equal("D:/cover.jpg", result.Value.CoverImage.Value);
Assert.Equal(entity.ShouldSkipHiddenFilesAndDirectoriesDuringScan, result.Value.ShouldSkipHiddenFilesAndDirectoriesDuringScan);
Assert.Equal(entity.IsContentOnSsd, result.Value.IsContentOnSsd);
Assert.Equal(entity.ShouldTrackConsumptionProgress, result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.Equal(entity.CompletionThresholdPercentage, result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue ? result.Value.ConsumptionSettings.CompletionThresholdPercentage.Value : null);
Assert.Equal(2, result.Value.PathTemplate.Parts.Count);
Assert.Equal(LibraryPathPartKind.Literal, result.Value.PathTemplate.Parts[0].Kind);
Assert.Equal("Various Artists", result.Value.PathTemplate.Parts[0].Representation);
Assert.False(result.Value.PathTemplate.Parts[0].IsOptional);
Assert.Equal(LibraryPathPartKind.Artist, result.Value.PathTemplate.Parts[1].Kind);
Assert.Equal("{0}", result.Value.PathTemplate.Parts[1].Representation);
Assert.True(result.Value.PathTemplate.Parts[1].IsOptional);
}
[Fact]
public void ToDomainEntity_WhenStoredTypedPartHasEmptyRepresentation_ShouldReturnPathTemplateLiteralCannotBeEmpty()
{
// Arrange
LibraryPathTemplatePartEntity invalidPart = _libraryPathTemplatePartEntityFixture.Create(
position: 0,
kind: LibraryPathPartKind.Artist,
representation: string.Empty);
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
pathTemplateParts: [invalidPart]);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateLiteralCannotBeEmpty, result.FirstError);
}
[Fact]
public void ToDomainEntity_WhenStoredTypedPartHasNoPlaceholder_ShouldReturnPathTemplateValuePartMustContainSinglePlaceholder()
{
// Arrange
LibraryPathTemplatePartEntity invalidPart = _libraryPathTemplatePartEntityFixture.Create(
position: 0,
kind: LibraryPathPartKind.TrackNumber,
representation: "Track");
LibraryEntity entity = _libraryEntityFixture.Create(
title: "My Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
pathTemplateParts: [invalidPart]);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateValuePartMustContainSinglePlaceholder, result.FirstError);
}
[Fact]
public void ToResponse_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.Equal(65, result.CompletionThresholdPercentage);
}
[Fact]
public void ToResponse_WhenProgressTrackingIsDisabled_ShouldMapTrackingOffWithoutThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsEnabled_ShouldMapConsumptionSettings()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.True(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
Assert.Equal(65, result.Value.ConsumptionSettings.CompletionThresholdPercentage.Value);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsEnabledWithoutThreshold_ShouldMapNoThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: null);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.False(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsDisabledButStoredThresholdExists_ShouldNotRetainThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 65);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.False(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.False(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.True(result.CompletionThresholdPercentage.HasValue);
Assert.Equal(65, result.CompletionThresholdPercentage.Value);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsDisabled_ShouldNotRetainThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 65);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.False(result.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsEnabledWithoutThreshold_ShouldMapNoThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: null);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.False(result.CompletionThresholdPercentage.HasValue);
}
}
@@ -0,0 +1,293 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="LibraryMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryMappingTests
{
private readonly LibraryFixture _libraryFixture = new();
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
private readonly LibraryConsumptionSettingsFixture _libraryConsumptionSettingsFixture = new();
[Fact]
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
{
// Arrange
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books", "D:/Media/Books"],
coverImage: "D:/myPoster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
shouldSkipHiddenFilesAndDirectoriesDuringScan: true,
scanIds: [Guid.NewGuid()]);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.Equal(library.Id.Value, result.Id);
Assert.Equal(library.UserId.Value, result.UserId);
Assert.Equal(library.Title, result.Title);
Assert.Equal(library.LibraryType, result.LibraryType);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Equal(library.CoverImage.HasValue ? library.CoverImage.Value : null, result.CoverImage);
Assert.Equal(default, result.CreatedOnUtc);
Assert.Null(result.UpdatedOnUtc);
Assert.True(result.IsEnabled);
Assert.False(result.IsLocked);
Assert.True(result.CanDownloadMetadataFromWeb);
Assert.False(result.ShouldSaveMetadataInMediaDirectories);
Assert.True(result.ShouldSkipHiddenFilesAndDirectoriesDuringScan);
Assert.Equal(library.IsContentOnSsd, result.IsContentOnSsd);
Assert.Equal(library.ConsumptionSettings.ShouldTrackConsumptionProgress, result.ShouldTrackConsumptionProgress);
Assert.Equal(library.ConsumptionSettings.CompletionThresholdPercentage.HasValue ? library.ConsumptionSettings.CompletionThresholdPercentage.Value : null, result.CompletionThresholdPercentage);
Assert.Equal(library.ScanIds.Select(scanId => scanId.Value), result.LibraryScans.Select(libraryScan => libraryScan.Id));
}
[Fact]
public void ToRepositoryEntity_WhenMappingLibraryWithEmptyContentLocations_ShouldMapCorrectly()
{
// Arrange
Library library = _libraryFixture.Create(
title: "Empty Library",
libraryType: LibraryType.Book,
contentLocations: [],
coverImage: "D:/myPoster.jpg");
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.Empty(result.ContentLocations);
Assert.Equal(library.CoverImage.HasValue ? library.CoverImage.Value : null, result.CoverImage);
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToRepositoryEntity_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: libraryType,
contentLocations: ["C:/Media"],
coverImage: "D:/myPoster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.Equal(libraryType, result.LibraryType);
Assert.Equal(library.CoverImage.HasValue ? library.CoverImage.Value : null, result.CoverImage);
Assert.True(result.IsEnabled);
Assert.False(result.IsLocked);
Assert.True(result.CanDownloadMetadataFromWeb);
Assert.False(result.ShouldSaveMetadataInMediaDirectories);
}
[Fact]
public void ToRepositoryEntity_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
List<string> contentLocations =
[
"C:/Media/Books",
"D:/Books",
"E:/Digital Library/Books",
"F:/Reading Material"
];
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
coverImage: "D:/myPoster.jpg");
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Equal(library.CoverImage.HasValue ? library.CoverImage.Value : null, result.CoverImage);
}
[Fact]
public void ToRepositoryEntity_WhenMappingNullCoverimage_ShouldMapCorrectly()
{
// Arrange
List<string> contentLocations =
[
"C:/Media/Books",
"D:/Books"
];
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
includeCoverImage: false);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Null(result.CoverImage);
}
[Fact]
public void ToRepositoryEntity_WhenMappingEmptyScanList_ShouldMapCorrectly()
{
// Arrange
List<string> contentLocations =
[
"C:/Media/Books",
"D:/Books"
];
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: contentLocations,
includeCoverImage: false,
scanIds: []);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.NotNull(result);
Assert.NotNull(library.ScanIds);
Assert.NotNull(result.LibraryScans);
}
[Fact]
public void ToRepositoryEntity_WhenLibraryHasPathTemplateParts_ShouldMapPartsWithSequentialPositions()
{
// Arrange
LibraryPathPart literalPart = _libraryPathPartFixture.Create(
kind: LibraryPathPartKind.Literal,
representation: "Various Artists",
isOptional: false);
LibraryPathPart typedPart = _libraryPathPartFixture.Create(
kind: LibraryPathPartKind.Artist,
representation: "{0}",
isOptional: true);
LibraryPathTemplate pathTemplate = _libraryPathTemplateFixture.Create(parts: [literalPart, typedPart]);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
pathTemplate: pathTemplate);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
List<LibraryPathTemplatePartEntity> parts = [.. result.PathTemplateParts.OrderBy(part => part.Position)];
Assert.Equal(2, parts.Count);
Assert.Equal(0, parts[0].Position);
Assert.Equal(LibraryPathPartKind.Literal, parts[0].Kind);
Assert.Equal("Various Artists", parts[0].Representation);
Assert.False(parts[0].IsOptional);
Assert.Equal(1, parts[1].Position);
Assert.Equal(LibraryPathPartKind.Artist, parts[1].Kind);
Assert.Equal("{0}", parts[1].Representation);
Assert.True(parts[1].IsOptional);
}
[Fact]
public void ToRepositoryEntity_WhenLibraryHasNoPathTemplateParts_ShouldMapEmptyCollection()
{
// Arrange
LibraryPathTemplate pathTemplate = _libraryPathTemplateFixture.Create(includeParts: false);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
pathTemplate: pathTemplate);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.Empty(result.PathTemplateParts);
}
[Fact]
public void ToRepositoryEntity_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryConsumptionSettings consumptionSettings = _libraryConsumptionSettingsFixture.Create(
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 70);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
consumptionSettings: consumptionSettings);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.Equal(70, result.CompletionThresholdPercentage);
}
[Fact]
public void ToRepositoryEntity_WhenProgressTrackingIsDisabled_ShouldMapTrackingOffWithoutThreshold()
{
// Arrange
LibraryConsumptionSettings consumptionSettings = _libraryConsumptionSettingsFixture.Create(
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 70);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
consumptionSettings: consumptionSettings);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
}
@@ -0,0 +1,204 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Fixtures.Common.DTO.MediaLibrary.Management;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="LibraryPathTemplatePartDtoMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryPathTemplatePartDtoMappingTests
{
private readonly LibraryPathTemplatePartDtoFixture _libraryPathTemplatePartDtoFixture = new();
[Fact]
public void ToDomainParts_WhenPartsIsNull_ShouldReturnEmptyList()
{
// Act
Result<IReadOnlyList<LibraryPathPart>> result = LibraryPathTemplatePartDtoMapping.ToDomainParts(null);
// Assert
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
}
[Fact]
public void ToDomainParts_WhenPartsIsEmpty_ShouldReturnEmptyList()
{
// Arrange
List<LibraryPathTemplatePartDto> parts = [];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
}
[Fact]
public void ToDomainParts_WhenPartsAreValid_ShouldMapKindRepresentationAndIsOptional()
{
// Arrange
LibraryPathTemplatePartDto literalPart = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Literal),
representation: "Various Artists",
isOptional: false);
LibraryPathTemplatePartDto typedPart = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: "{0}",
isOptional: true);
LibraryPathTemplatePartDto[] parts = [literalPart, typedPart];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count);
Assert.Equal(LibraryPathPartKind.Literal, result.Value[0].Kind);
Assert.Equal("Various Artists", result.Value[0].Representation);
Assert.False(result.Value[0].IsOptional);
Assert.Equal(LibraryPathPartKind.Artist, result.Value[1].Kind);
Assert.Equal("{0}", result.Value[1].Representation);
Assert.True(result.Value[1].IsOptional);
}
[Fact]
public void ToDomainParts_WhenPartIsSeparator_ShouldMapWithEmptyRepresentation()
{
// Arrange
LibraryPathTemplatePartDto separatorPart = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Separator),
representation: @"\",
isOptional: false);
LibraryPathTemplatePartDto[] parts = [separatorPart];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(LibraryPathPartKind.Separator, result.Value[0].Kind);
Assert.Equal(string.Empty, result.Value[0].Representation);
Assert.False(result.Value[0].IsOptional);
}
[Fact]
public void ToDomainParts_WhenKindIsUnknown_ShouldReturnPathTemplatePartKindNotSupportedForLibraryType()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create(kind: "NotARealLibraryPathPartKind");
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplatePartKindNotSupportedForLibraryType, result.FirstError);
}
[Fact]
public void ToDomainParts_WhenKindIsNull_ShouldReturnPathTemplatePartKindNotSupportedForLibraryType()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create() with { Kind = null };
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplatePartKindNotSupportedForLibraryType, result.FirstError);
}
[Fact]
public void ToDomainParts_WhenKindUsesDifferentCasing_ShouldMapKind()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create(
kind: "artist",
representation: "{0}",
isOptional: false);
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(LibraryPathPartKind.Artist, result.Value[0].Kind);
Assert.Equal("{0}", result.Value[0].Representation);
Assert.False(result.Value[0].IsOptional);
}
[Fact]
public void ToDomainParts_WhenTypedPartRepresentationIsEmpty_ShouldReturnPathTemplateLiteralCannotBeEmpty()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: string.Empty);
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateLiteralCannotBeEmpty, result.FirstError);
}
[Fact]
public void ToDomainParts_WhenTypedPartRepresentationHasNoPlaceholder_ShouldReturnPathTemplateValuePartMustContainSinglePlaceholder()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: "Artist Name");
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateValuePartMustContainSinglePlaceholder, result.FirstError);
}
[Fact]
public void ToDomainParts_WhenTypedPartRepresentationHasDuplicatePlaceholder_ShouldReturnPathTemplateValuePartMustContainSinglePlaceholder()
{
// Arrange
LibraryPathTemplatePartDto part = _libraryPathTemplatePartDtoFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: "{0} - {0}");
LibraryPathTemplatePartDto[] parts = [part];
// Act
Result<IReadOnlyList<LibraryPathPart>> result = parts.ToDomainParts();
// Assert
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateValuePartMustContainSinglePlaceholder, result.FirstError);
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="MediaLibraryScanJobProgressMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanJobProgressMappingTests
{
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
[Fact]
public void ToResponse_WhenMappingValidValueObject_ShouldMapCorrectly()
{
// Arrange
MediaLibraryScanJobProgress progress = _mediaLibraryScanJobProgressFixture.Create(
completedItems: 3,
totalItems: 10,
currentOperation: "Hashing files");
// Act
MediaLibraryScanJobProgressResponse result = progress.ToResponse();
// Assert
Assert.Equal(progress.CompletedItems, result.CompletedItems);
Assert.Equal(progress.TotalItems, result.TotalItems);
Assert.Equal(progress.CurrentOperation, result.CurrentOperation);
Assert.Equal(progress.ProgressPercentage, result.ProgressPercentage);
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="ScanLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ScanLibraryRequestMappingTests
{
private readonly ScanLibraryRequestFixture _scanLibraryRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
Guid id = Guid.NewGuid();
ScanLibraryRequest request = _scanLibraryRequestFixture.Create(id);
// Act
ScanLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(request.Id, result.Id);
}
}
@@ -0,0 +1,238 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="UpdateLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateLibraryRequestMappingTests
{
private readonly UpdateLibraryRequestFixture _updateLibraryRequestFixture = new();
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
private readonly LibraryPathTemplatePartRequestFixture _libraryPathTemplatePartRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
title: "My Library",
libraryType: "Book",
contentLocations: ["C:/Books", "D:/Media/Books"],
coverImage: "D:/poster.jpg",
isEnabled: true,
isLocked: false,
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
shouldSkipHiddenFilesAndDirectoriesDuringScan: true,
isContentOnSsd: true,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 90);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(request.Id, result.Id);
Assert.Equal(request.Title, result.Title);
Assert.Equal(request.LibraryType, result.LibraryType);
Assert.Equal(request.ContentLocations, result.ContentLocations);
Assert.Equal(request.CoverImage, result.CoverImage);
Assert.Equal(request.IsEnabled, result.IsEnabled);
Assert.Equal(request.IsLocked, result.IsLocked);
Assert.Equal(request.CanDownloadMetadataFromWeb, result.CanDownloadMetadataFromWeb);
Assert.Equal(request.ShouldSaveMetadataInMediaDirectories, result.ShouldSaveMetadataInMediaDirectories);
Assert.Equal(request.ShouldSkipUnchangedDirectoriesDuringScan, result.ShouldSkipUnchangedDirectoriesDuringScan);
Assert.Equal(request.ShouldSkipHiddenFilesAndDirectoriesDuringScan, result.ShouldSkipHiddenFilesAndDirectoriesDuringScan);
Assert.Equal(request.IsContentOnSsd, result.IsContentOnSsd);
Assert.Equal(request.ShouldTrackConsumptionProgress, result.ShouldTrackConsumptionProgress);
Assert.Equal(request.CompletionThresholdPercentage, result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenRequestHasPathTemplateParts_ShouldMapToDtoArray()
{
// Arrange
LibraryPathTemplatePartRequest literalPart = _libraryPathTemplatePartRequestFixture.Create(
kind: nameof(LibraryPathPartKind.Literal),
representation: "Various Artists",
isOptional: false);
LibraryPathTemplatePartRequest typedPart = _libraryPathTemplatePartRequestFixture.Create(
kind: nameof(LibraryPathPartKind.Artist),
representation: "{0}",
isOptional: true);
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(pathTemplateParts: [literalPart, typedPart]);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.PathTemplateParts);
Assert.Equal(2, result.PathTemplateParts.Length);
Assert.Equal(literalPart.Kind, result.PathTemplateParts[0].Kind);
Assert.Equal(literalPart.Representation, result.PathTemplateParts[0].Representation);
Assert.Equal(literalPart.IsOptional, result.PathTemplateParts[0].IsOptional);
Assert.Equal(typedPart.Kind, result.PathTemplateParts[1].Kind);
Assert.Equal(typedPart.Representation, result.PathTemplateParts[1].Representation);
Assert.Equal(typedPart.IsOptional, result.PathTemplateParts[1].IsOptional);
}
[Fact]
public void ToCommand_WhenPathTemplatePartsIsNull_ShouldMapToNull()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(pathTemplateParts: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.PathTemplateParts);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreSupplied_ShouldMapThem()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 75);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.True(result.ShouldTrackConsumptionProgress.Value);
Assert.Equal(75, result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreAbsent_ShouldPreserveThemAsNull()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: null,
completionThresholdPercentage: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProgressTrackingIsExplicitlyDisabled_ShouldPreserveTheDisabledFlagWithoutThreshold()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.False(result.ShouldTrackConsumptionProgress.Value);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProviderChoicesAreProvided_ShouldMapThemInOrder()
{
// Arrange
LibraryProviderSelectionRequest[] metadataProviders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: true), _libraryProviderSelectionRequestFixture.Create(isEnabled: false)];
LibraryProviderSelectionRequest[] artworkProviders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: false)];
LibraryProviderSelectionRequest[] bookReaders = [_libraryProviderSelectionRequestFixture.Create(isEnabled: true)];
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(metadataProviders: metadataProviders, artworkProviders: artworkProviders, bookReaders: bookReaders);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(metadataProviders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.MetadataProviders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
Assert.Equal(artworkProviders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.ArtworkProviders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
Assert.Equal(bookReaders.Select(selection => (selection.PluginId, selection.IsEnabled)), result.BookReaders!.Select(selection => (selection.PluginId, selection.IsEnabled)));
}
[Fact]
public void ToCommand_WhenProviderChoicesAreNotProvided_ShouldMapThemAsNull()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(metadataProviders: null, artworkProviders: null, bookReaders: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.MetadataProviders);
Assert.Null(result.ArtworkProviders);
Assert.Null(result.BookReaders);
}
[Fact]
public void ToCommand_WhenAProviderChoiceIsNull_ShouldMapItToAChoiceWithoutPluginId()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(metadataProviders: [null], artworkProviders: [null], bookReaders: [null]);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Equal(Guid.Empty, Assert.Single(result.MetadataProviders!).PluginId);
Assert.Null(result.MetadataProviders![0].IsEnabled);
Assert.Equal(Guid.Empty, Assert.Single(result.ArtworkProviders!).PluginId);
Assert.Equal(Guid.Empty, Assert.Single(result.BookReaders!).PluginId);
}
[Fact]
public void ToCommand_WhenAPathTemplatePartIsNull_ShouldMapItToAPartWithoutKind()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(pathTemplateParts: [null]);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
LibraryPathTemplatePartDto part = Assert.Single(result.PathTemplateParts!);
Assert.Null(part.Kind);
Assert.Null(part.Representation);
Assert.False(part.IsOptional);
}
[Fact]
public void ToCommand_WhenAProviderChoiceHasNoEnabledState_ShouldMapTheStateAsNull()
{
// Arrange
LibraryProviderSelectionRequest choice = _libraryProviderSelectionRequestFixture.Create(includeIsEnabled: false);
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(metadataProviders: [choice]);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
LibraryProviderSelectionDto mappedChoice = Assert.Single(result.MetadataProviders!);
Assert.Equal(choice.PluginId, mappedChoice.PluginId);
Assert.Null(mappedChoice.IsEnabled);
}
}