mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
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:
1 parent
48ad8692af
commit
64e5163229
127 files changed
+5541
-5296
No files matched your search
+554
-115
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Reading;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
@@ -19,6 +20,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Core.Plugins;
|
||||
@@ -173,7 +175,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenCalled_ShouldRemoveStaleConfigurationsAndAddTheSupportedOnes()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMade_ShouldRemoveStaleConfigurationsAndAddTheSupportedOnes()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -198,7 +200,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -339,7 +341,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenBookReaderSupportsTheLibraryType_ShouldAddDisabledConfiguration()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenABookReaderSupportsTheLibraryType_ShouldAddADisabledBookReaderConfiguration()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -353,17 +355,20 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == pluginId && !configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
// The reader is ensured exactly once, since a second ensure in the same scope would not see the staged row and would add a duplicate.
|
||||
await _mockBookReaderConfigurationRepository.Received(1).GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenConfigurationAlreadyExists_ShouldNotAddAnotherOne()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenTheBookReaderConfigurationAlreadyExists_ShouldNotAddAnotherBookReaderConfiguration()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -376,7 +381,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([existingConfiguration]));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -384,7 +389,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenNoBookReaderSupportsTheLibraryType_ShouldNotAddConfiguration()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenNoBookReaderSupportsTheLibraryType_ShouldNotAddABookReaderConfiguration()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -394,7 +399,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.Movie, ".epub")));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -403,7 +408,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenReaderDeclaresNoExtension_ShouldNotAddConfiguration()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenTheBookReaderDeclaresNoExtension_ShouldNotAddABookReaderConfiguration()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -413,7 +418,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.EBook, supportedExtension: null)));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -421,7 +426,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenReadingConfigurationsFails_ShouldReturnError()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenReadingBookReaderConfigurationsFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -433,14 +438,14 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to read configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureBookReaderConfigurationsAsync_WhenUpsertFails_ShouldReturnError()
|
||||
public async Task EnsureProviderConfigurationsAsync_WhenUpsertingBookReaderConfigurationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -454,14 +459,14 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to persist the configuration"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.EnsureBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.EnsureProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileBookReaderConfigurationsAsync_WhenCalled_ShouldRemoveStaleAndAddTheSupportedBookReaders()
|
||||
public async Task ConfigureProvidersAsync_WhenOmittedBookReadersAreReconciled_ShouldRemoveStaleAndAddTheSupportedBookReaders()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -474,6 +479,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
(alphaPluginId, null, null, CreateBookReader(LibraryType.Book, ".pdf")),
|
||||
(betaPluginId, null, null, CreateBookReader(LibraryType.EBook, ".epub")));
|
||||
LibraryBookReaderConfigurationEntity existingConfiguration = _libraryBookReaderConfigurationEntityFixture.Create(libraryId: libraryId, pluginId: alphaPluginId);
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
_mockBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([existingConfiguration]));
|
||||
_mockBookReaderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>())
|
||||
@@ -482,7 +488,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -493,10 +499,11 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.DidNotReceive().UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == alphaPluginId), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidateLibrary(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileBookReaderConfigurationsAsync_WhenReadingConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenReconcilingBookReadersFailsToReadTheirConfigurations_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -504,18 +511,19 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
IPlugin plugin = CreatePlugin(pluginId, "Reader Plugin");
|
||||
_mockPluginManager.GetPlugins().Returns([plugin]);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.EBook, ".epub")));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
_mockBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to read configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileBookReaderConfigurationsAsync_WhenDeletingStaleConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenReconcilingBookReadersFailsToDeleteStaleConfigurations_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -525,20 +533,21 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
_mockPluginManager.GetPlugins().Returns([plugin]);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.EBook, ".epub")));
|
||||
LibraryBookReaderConfigurationEntity staleConfiguration = _libraryBookReaderConfigurationEntityFixture.Create(libraryId: libraryId, pluginId: stalePluginId);
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
_mockBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([staleConfiguration]));
|
||||
_mockBookReaderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to delete the configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileBookReaderConfigurationsAsync_WhenUpsertFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenReconcilingBookReadersFailsToUpsertAConfiguration_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -546,90 +555,21 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
IPlugin plugin = CreatePlugin(pluginId, "Reader Plugin");
|
||||
_mockPluginManager.GetPlugins().Returns([plugin]);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.EBook, ".epub")));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
_mockBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([]));
|
||||
_mockBookReaderConfigurationRepository.UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to persist the configuration"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileBookReaderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBookReaderConfigurationsForLibraryAsync_WhenCalled_ShouldDeleteTheConfigurationsOfTheLibrary()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
_mockBookReaderConfigurationRepository.DeleteByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await sut.RemoveBookReaderConfigurationsForLibraryAsync(libraryId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).DeleteByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidateLibrary(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBookReaderConfigurationsForLibraryAsync_WhenDeletionFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
_mockBookReaderConfigurationRepository.DeleteByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to delete the configurations"));
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await sut.RemoveBookReaderConfigurationsForLibraryAsync(libraryId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
_mockEnablementCache.DidNotReceive().InvalidateLibrary(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBookReaderConfigurationsAsync_WhenCalled_ShouldDeleteTheConfigurationsOfThePlugin()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
_mockBookReaderConfigurationRepository.DeleteByPluginIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await sut.RemoveBookReaderConfigurationsAsync(pluginId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).DeleteByPluginIdAsync(pluginId, Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidatePlugin(pluginId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBookReaderConfigurationsAsync_WhenDeletionFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
_mockBookReaderConfigurationRepository.DeleteByPluginIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to delete the configurations"));
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await sut.RemoveBookReaderConfigurationsAsync(pluginId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
_mockEnablementCache.DidNotReceive().InvalidatePlugin(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenArtworkConfigurationsAreStale_ShouldDeleteAndAddThem()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndArtworkConfigurationsAreStale_ShouldDeleteAndAddThem()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -654,7 +594,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -666,7 +606,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenDeletingStaleArtworkConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndDeletingStaleArtworkConfigurationsFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -683,7 +623,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to delete the configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -780,7 +720,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenMetadataProviderIsAlreadyConfigured_ShouldKeepItWithoutUpserting()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndMetadataProviderIsAlreadyConfigured_ShouldKeepItWithoutUpserting()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -797,7 +737,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([]));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -806,7 +746,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenArtworkProviderIsAlreadyConfigured_ShouldKeepItWithoutUpserting()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndArtworkProviderIsAlreadyConfigured_ShouldKeepItWithoutUpserting()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -823,7 +763,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([]));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -832,7 +772,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenReadingMetadataConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndReadingMetadataConfigurationsFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -844,7 +784,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to read configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -853,7 +793,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenDeletingStaleMetadataConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndDeletingStaleMetadataConfigurationsFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -868,14 +808,14 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to delete the configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenUpsertingMetadataConfigurationFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndUpsertingMetadataConfigurationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -889,7 +829,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to persist the configuration"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -897,7 +837,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenReadingArtworkConfigurationsFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndReadingArtworkConfigurationsFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -911,7 +851,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to read configurations"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -919,7 +859,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileProviderConfigurationsAsync_WhenUpsertingArtworkConfigurationFails_ShouldReturnError()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndUpsertingArtworkConfigurationFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -935,7 +875,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Error.Failure(description: "Failed to persist the configuration"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -943,7 +883,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileBookReaderConfigurationsAsync_WhenConfigurationAlreadyExists_ShouldKeepItWithoutUpserting()
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndBookReaderConfigurationAlreadyExists_ShouldKeepItWithoutUpserting()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
@@ -960,7 +900,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryBookReaderConfigurationEntity>>([existingConfiguration]));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ReconcileProviderConfigurationsAsync(libraryId, LibraryType.EBook, CancellationToken.None);
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.EBook, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -1010,6 +950,505 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenMetadataProviderChoicesAreMade_ShouldApplyTheirOrderAndEnabledState()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid alphaPluginId = Guid.NewGuid();
|
||||
Guid betaPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(alphaPluginId, "Alpha"), CreatePlugin(betaPluginId, "Beta")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(alphaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(betaPluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
LibraryMetadataProviderConfigurationEntity alphaConfiguration = _libraryMetadataProviderConfigurationEntityFixture.Create(libraryId, alphaPluginId, 1, isEnabled: true);
|
||||
StubConfigurations(libraryId, [alphaConfiguration], [], []);
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(betaPluginId, IsEnabled: true), new(alphaPluginId, IsEnabled: false)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == betaPluginId && configuration.LibraryId == libraryId && configuration.Rank == 1 && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == alphaPluginId && configuration.Id == alphaConfiguration.Id && configuration.Rank == 2 && !configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().DeleteByLibraryIdAndPluginIdsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenASupportedMetadataProviderIsNotNamed_ShouldKeepItsStoredStateAfterTheNamedProviders()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid alphaPluginId = Guid.NewGuid();
|
||||
Guid betaPluginId = Guid.NewGuid();
|
||||
Guid gammaPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(alphaPluginId, "Alpha"), CreatePlugin(betaPluginId, "Beta"), CreatePlugin(gammaPluginId, "Gamma")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(alphaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(betaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(gammaPluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
LibraryMetadataProviderConfigurationEntity gammaConfiguration = _libraryMetadataProviderConfigurationEntityFixture.Create(libraryId, gammaPluginId, 1, isEnabled: true);
|
||||
StubConfigurations(libraryId, [gammaConfiguration], [], []);
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(betaPluginId, IsEnabled: false)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == betaPluginId && configuration.Rank == 1 && !configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == gammaPluginId && configuration.Rank == 2 && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == alphaPluginId && configuration.Rank == 3 && !configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenAMetadataProviderChoiceNamesAnUnsupportedPlugin_ShouldReturnErrorWithoutChangingConfigurations()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(Guid.NewGuid(), IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginNotSupportedForLibraryType, result.FirstError);
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenUpsertingAChosenMetadataProviderFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
_mockMetadataConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Upsert failed"));
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(pluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenArtworkProviderChoicesAreMadeAndStaleConfigurationsExist_ShouldDeleteTheStaleOnesAndApplyTheChoices()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid supportedPluginId = Guid.NewGuid();
|
||||
Guid stalePluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(supportedPluginId, "Alpha"), CreatePlugin(stalePluginId, "Beta")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(supportedPluginId, null, CreateArtworkProvider(LibraryType.Book), null),
|
||||
(stalePluginId, null, CreateArtworkProvider(LibraryType.Music), null));
|
||||
LibraryArtworkProviderConfigurationEntity staleConfiguration = _libraryArtworkProviderConfigurationEntityFixture.Create(libraryId, stalePluginId, 1);
|
||||
StubConfigurations(libraryId, [], [staleConfiguration], []);
|
||||
LibraryProviderSelectionDto[] artworkProviders = [new(supportedPluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, artworkProviders, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockArtworkConfigurationRepository.Received(1).DeleteByLibraryIdAndPluginIdsAsync(
|
||||
libraryId, Arg.Is<IEnumerable<Guid>>(pluginIds => pluginIds.SequenceEqual(new[] { stalePluginId })), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryArtworkProviderConfigurationEntity>(configuration => configuration.PluginId == supportedPluginId && configuration.Rank == 1 && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().UpsertAsync(
|
||||
Arg.Is<LibraryArtworkProviderConfigurationEntity>(configuration => configuration.PluginId == stalePluginId), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenAnArtworkProviderChoiceNamesAnUnsupportedPlugin_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, CreateArtworkProvider(LibraryType.Music), null));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] artworkProviders = [new(pluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, artworkProviders, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginNotSupportedForLibraryType, result.FirstError);
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryArtworkProviderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenBookReaderChoicesAreMade_ShouldApplyTheirEnabledStateAndInvalidateTheEnablementCache()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid epubPluginId = Guid.NewGuid();
|
||||
Guid pdfPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(epubPluginId, "EPUB Reader"), CreatePlugin(pdfPluginId, "PDF Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(epubPluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")),
|
||||
(pdfPluginId, null, null, CreateBookReader(LibraryType.Book, ".pdf")));
|
||||
LibraryBookReaderConfigurationEntity pdfConfiguration = _libraryBookReaderConfigurationEntityFixture.Create(libraryId: libraryId, pluginId: pdfPluginId, isEnabled: true);
|
||||
StubConfigurations(libraryId, [], [], [pdfConfiguration]);
|
||||
LibraryProviderSelectionDto[] bookReaders = [new(epubPluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, bookReaders, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == epubPluginId && configuration.LibraryId == libraryId && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == pdfPluginId && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidateLibrary(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenBookReaderChoicesAreMadeAndStaleConfigurationsExist_ShouldDeleteTheStaleOnesAndApplyTheChoices()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid supportedPluginId = Guid.NewGuid();
|
||||
Guid stalePluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(supportedPluginId, "EPUB Reader"), CreatePlugin(stalePluginId, "PDF Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(supportedPluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")),
|
||||
(stalePluginId, null, null, CreateBookReader(LibraryType.EBook, ".pdf")));
|
||||
LibraryBookReaderConfigurationEntity staleConfiguration = _libraryBookReaderConfigurationEntityFixture.Create(libraryId: libraryId, pluginId: stalePluginId, isEnabled: true);
|
||||
StubConfigurations(libraryId, [], [], [staleConfiguration]);
|
||||
LibraryProviderSelectionDto[] bookReaders = [new(supportedPluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, bookReaders, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).DeleteByLibraryIdAndPluginIdsAsync(
|
||||
libraryId, Arg.Is<IEnumerable<Guid>>(pluginIds => pluginIds.SequenceEqual(new[] { stalePluginId })), Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == supportedPluginId && configuration.LibraryId == libraryId && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.DidNotReceive().UpsertAsync(
|
||||
Arg.Is<LibraryBookReaderConfigurationEntity>(configuration => configuration.PluginId == stalePluginId), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidateLibrary(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenABookReaderChoiceNamesAnUnsupportedPlugin_ShouldReturnErrorWithoutInvalidatingTheEnablementCache()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "EPUB Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] bookReaders = [new(Guid.NewGuid(), IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, bookReaders, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginNotSupportedForLibraryType, result.FirstError);
|
||||
await _mockBookReaderConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.DidNotReceive().InvalidateLibrary(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenNoBookReaderChoicesAreMadeAndOmittedKindsAreNotReconciled_ShouldNotInvalidateTheEnablementCache()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
_mockEnablementCache.DidNotReceive().InvalidateLibrary(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenOmittedBookReadersAreReconciled_ShouldRemoveTheStaleReaderAndInvalidateTheEnablementCache()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid stalePluginId = Guid.NewGuid();
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
LibraryBookReaderConfigurationEntity staleConfiguration = _libraryBookReaderConfigurationEntityFixture.Create(libraryId: libraryId, pluginId: stalePluginId, isEnabled: true);
|
||||
StubConfigurations(libraryId, [], [], [staleConfiguration]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, null, shouldReconcileOmittedKinds: true, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).DeleteByLibraryIdAndPluginIdsAsync(
|
||||
libraryId, Arg.Is<IEnumerable<Guid>>(pluginIds => pluginIds.SequenceEqual(new[] { stalePluginId })), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.Received(1).InvalidateLibrary(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSupportedMetadataProviderPluginIds_WhenPluginsSupportTheLibraryType_ShouldReturnThemInAlphabeticalOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid alphaPluginId = Guid.NewGuid();
|
||||
Guid betaPluginId = Guid.NewGuid();
|
||||
Guid unsupportedPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(betaPluginId, "Beta"), CreatePlugin(unsupportedPluginId, "Gamma"), CreatePlugin(alphaPluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(alphaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(betaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(unsupportedPluginId, CreateMetadataProvider(LibraryType.Music), null, null));
|
||||
|
||||
// Act
|
||||
IReadOnlyList<Guid> result = sut.GetSupportedMetadataProviderPluginIds(LibraryType.Book);
|
||||
|
||||
// Assert
|
||||
Assert.Equal([alphaPluginId, betaPluginId], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSupportedArtworkProviderPluginIds_WhenPluginsSupportTheLibraryType_ShouldReturnThemInAlphabeticalOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid alphaPluginId = Guid.NewGuid();
|
||||
Guid betaPluginId = Guid.NewGuid();
|
||||
Guid metadataOnlyPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(betaPluginId, "Beta"), CreatePlugin(alphaPluginId, "Alpha"), CreatePlugin(metadataOnlyPluginId, "Delta")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(alphaPluginId, null, CreateArtworkProvider(LibraryType.Music), null),
|
||||
(betaPluginId, null, CreateArtworkProvider(LibraryType.Music), null),
|
||||
(metadataOnlyPluginId, CreateMetadataProvider(LibraryType.Music), null, null));
|
||||
|
||||
// Act
|
||||
IReadOnlyList<Guid> result = sut.GetSupportedArtworkProviderPluginIds(LibraryType.Music);
|
||||
|
||||
// Assert
|
||||
Assert.Equal([alphaPluginId, betaPluginId], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSupportedBookReaderPluginIds_WhenAReaderDeclaresNoFileExtension_ShouldLeaveItOut()
|
||||
{
|
||||
// Arrange
|
||||
Guid epubPluginId = Guid.NewGuid();
|
||||
Guid extensionlessPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(epubPluginId, "EPUB Reader"), CreatePlugin(extensionlessPluginId, "Empty Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(epubPluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")),
|
||||
(extensionlessPluginId, null, null, CreateBookReader(LibraryType.Book, null)));
|
||||
|
||||
// Act
|
||||
IReadOnlyList<Guid> result = sut.GetSupportedBookReaderPluginIds(LibraryType.Book);
|
||||
|
||||
// Assert
|
||||
Assert.Equal([epubPluginId], result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenOnlyBookReaderChoicesAreMadeAndOmittedKindsAreNotReconciled_ShouldLeaveTheProviderConfigurationsUntouched()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "EPUB Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] bookReaders = [new(pluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, bookReaders, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockBookReaderConfigurationRepository.Received(1).UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().DeleteByLibraryIdAndPluginIdsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().DeleteByLibraryIdAndPluginIdsAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenNoChoicesAreMadeAndOmittedKindsAreNotReconciled_ShouldNotTouchAnyConfiguration()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut();
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockBookReaderConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.DidNotReceive().InvalidateLibrary(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenAChoiceHasNoEnabledState_ShouldKeepTheStoredStateAndApplyTheOrder()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid alphaPluginId = Guid.NewGuid();
|
||||
Guid betaPluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(alphaPluginId, "Alpha"), CreatePlugin(betaPluginId, "Beta")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut(
|
||||
(alphaPluginId, CreateMetadataProvider(LibraryType.Book), null, null),
|
||||
(betaPluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
LibraryMetadataProviderConfigurationEntity alphaConfiguration = _libraryMetadataProviderConfigurationEntityFixture.Create(libraryId, alphaPluginId, 1, isEnabled: true);
|
||||
StubConfigurations(libraryId, [alphaConfiguration], [], []);
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(betaPluginId, IsEnabled: null), new(alphaPluginId, IsEnabled: null)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == betaPluginId && configuration.Rank == 1 && !configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockMetadataConfigurationRepository.Received(1).UpsertAsync(
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == alphaPluginId && configuration.Rank == 2 && configuration.IsEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenMetadataProviderChoicesAreDuplicated_ShouldReturnErrorWithoutChangingConfigurations()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, CreateMetadataProvider(LibraryType.Book), null, null));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] metadataProviders = [new(pluginId, IsEnabled: true), new(pluginId, IsEnabled: false)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, metadataProviders, null, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginIdsMustBeUnique, result.FirstError);
|
||||
await _mockMetadataConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenArtworkProviderChoicesAreDuplicated_ShouldReturnErrorWithoutChangingConfigurations()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "Alpha")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, CreateArtworkProvider(LibraryType.Book), null));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] artworkProviders = [new(pluginId, IsEnabled: true), new(pluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, artworkProviders, null, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginIdsMustBeUnique, result.FirstError);
|
||||
await _mockArtworkConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryArtworkProviderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfigureProvidersAsync_WhenBookReaderChoicesAreDuplicated_ShouldReturnErrorWithoutChangingConfigurations()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
IPlugin[] plugins = [CreatePlugin(pluginId, "EPUB Reader")];
|
||||
_mockPluginManager.GetPlugins().Returns(plugins);
|
||||
MediaLibraryProviderConfigurationStore sut = CreateSut((pluginId, null, null, CreateBookReader(LibraryType.Book, ".epub")));
|
||||
StubConfigurations(libraryId, [], [], []);
|
||||
LibraryProviderSelectionDto[] bookReaders = [new(pluginId, IsEnabled: false), new(pluginId, IsEnabled: true)];
|
||||
|
||||
// Act
|
||||
Result<Success> result = await sut.ConfigureProvidersAsync(libraryId, LibraryType.Book, null, null, bookReaders, shouldReconcileOmittedKinds: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginIdsMustBeUnique, result.FirstError);
|
||||
await _mockBookReaderConfigurationRepository.DidNotReceive().UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>());
|
||||
_mockEnablementCache.DidNotReceive().InvalidateLibrary(Arg.Any<Guid>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stubs the stored configurations of a media library, and lets every write to the configuration repositories succeed.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose configurations are stubbed.</param>
|
||||
/// <param name="metadataConfigurations">The stored metadata provider configurations.</param>
|
||||
/// <param name="artworkConfigurations">The stored artwork provider configurations.</param>
|
||||
/// <param name="bookReaderConfigurations">The stored book reader configurations.</param>
|
||||
private void StubConfigurations(
|
||||
Guid libraryId,
|
||||
IReadOnlyList<LibraryMetadataProviderConfigurationEntity> metadataConfigurations,
|
||||
IReadOnlyList<LibraryArtworkProviderConfigurationEntity> artworkConfigurations,
|
||||
IReadOnlyList<LibraryBookReaderConfigurationEntity> bookReaderConfigurations)
|
||||
{
|
||||
_mockMetadataConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>()).Returns(Result.From(metadataConfigurations));
|
||||
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>()).Returns(Result.From(artworkConfigurations));
|
||||
_mockBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>()).Returns(Result.From(bookReaderConfigurations));
|
||||
_mockMetadataConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockArtworkConfigurationRepository.UpsertAsync(Arg.Any<LibraryArtworkProviderConfigurationEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockBookReaderConfigurationRepository.UpsertAsync(Arg.Any<LibraryBookReaderConfigurationEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockMetadataConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
|
||||
_mockArtworkConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
|
||||
_mockBookReaderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, Arg.Any<IEnumerable<Guid>>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the store under test wired to the mocked dependencies, optionally registering the providers and book readers of the loaded plugins.
|
||||
/// </summary>
|
||||
@@ -1021,11 +1460,11 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
foreach ((Guid pluginId, IMetadataProvider? metadataProvider, IArtworkProvider? artworkProvider, IBookReader? bookReader) in pluginServices)
|
||||
{
|
||||
if (metadataProvider is not null)
|
||||
services.AddKeyedSingleton<IMetadataProvider>(pluginId, (_, _) => metadataProvider);
|
||||
services.AddKeyedSingleton(pluginId, (_, _) => metadataProvider);
|
||||
if (artworkProvider is not null)
|
||||
services.AddKeyedSingleton<IArtworkProvider>(pluginId, (_, _) => artworkProvider);
|
||||
services.AddKeyedSingleton(pluginId, (_, _) => artworkProvider);
|
||||
if (bookReader is not null)
|
||||
services.AddKeyedSingleton<IBookReader>(pluginId, (_, _) => bookReader);
|
||||
services.AddKeyedSingleton(pluginId, (_, _) => bookReader);
|
||||
}
|
||||
return new MediaLibraryProviderConfigurationStore(_mockUnitOfWork, _mockPluginManager, services.BuildServiceProvider(), _mockEnablementCache);
|
||||
}
|
||||
|
||||
+2
-4
@@ -77,8 +77,6 @@ public class PluginDetectionSyncJobTests
|
||||
.Returns(Result.Deleted);
|
||||
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
_mockProviderConfigurationStore.EnsureBookReaderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
|
||||
_mockServiceProvider.GetService(typeof(IMediaLibraryProviderConfigurationStore)).Returns(_mockProviderConfigurationStore);
|
||||
|
||||
@@ -229,8 +227,8 @@ public class PluginDetectionSyncJobTests
|
||||
await StartAndWaitForExecutionAsync(sut);
|
||||
|
||||
// Assert
|
||||
// A single ensure covers the metadata, artwork and book reader configurations, since a second one before the save would stage duplicates.
|
||||
await _mockProviderConfigurationStore.Received(1).EnsureProviderConfigurationsAsync(bookLibrary.Id, LibraryType.Book, Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.Received(1).EnsureBookReaderConfigurationsAsync(bookLibrary.Id, LibraryType.Book, Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -239,7 +237,7 @@ public class PluginDetectionSyncJobTests
|
||||
{
|
||||
// Arrange
|
||||
IPlugin previouslyLoadedPlugin = CreatePlugin(Guid.NewGuid(), "My Plugin", new Version(1, 0, 0));
|
||||
_mockPluginManager.GetPlugins().Returns([]); // the plugin assembly now fails to load
|
||||
_mockPluginManager.GetPlugins().Returns([]); // The plugin assembly now fails to load.
|
||||
_mockPluginRepository.UpsertAsync(Arg.Any<PluginEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Updated));
|
||||
PluginLoadErrorDto loadError = _pluginLoadErrorDtoFixture.Create(
|
||||
|
||||
Reference in new issue
Block a user