Updates the provider configuration and ownership tests

Covers the provider and reader choices saved with a library, the reconciliation and stale configuration deletion in the provider store, the library type lookups, the ownership and permission checks for update and delete, and the validator behavior for enum names.
This commit is contained in:
BinaryAlley committed 2026-11-03 10:00:00 +02:00
1 parent 48ad8692af
commit 64e5163229
127 files changed
+5541 -5296

No files matched your search

@@ -1,10 +1,13 @@
#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;
@@ -16,6 +19,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
public class AddMediaLibraryRequestMappingTests
{
private readonly AddLibraryRequestFixture _addLibraryRequestFixture = new();
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
private readonly LibraryPathTemplatePartRequestFixture _libraryPathTemplatePartRequestFixture = new();
[Fact]
@@ -245,4 +249,85 @@ public class AddMediaLibraryRequestMappingTests
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);
}
}
@@ -1,10 +1,13 @@
#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;
@@ -16,6 +19,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
public class UpdateLibraryRequestMappingTests
{
private readonly UpdateLibraryRequestFixture _updateLibraryRequestFixture = new();
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
private readonly LibraryPathTemplatePartRequestFixture _libraryPathTemplatePartRequestFixture = new();
[Fact]
@@ -148,4 +152,85 @@ public class UpdateLibraryRequestMappingTests
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);
}
}