mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Adds metadata and artwork provider configuration seeding
Seeds a disabled provider configuration for every loaded plugin supporting a library type, so that libraries list the metadata and artwork providers they can use. Configurations are seeded on startup, on library creation, and reconciled when the library type changes, and are removed only when a library or a plugin is deleted. Reads the library metadata providers through the new provider configuration store.
This commit is contained in:
1 parent
9ae8c0c394
commit
00dcf3d471
20 files changed
+1139
-27
No files matched your search
+26
-2
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
@@ -14,6 +15,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -39,6 +41,7 @@ public class AddLibraryCommandHandlerTests
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly IEnvironmentContext _mockEnvironmentContext;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
|
||||
private readonly IValidator<AddLibraryCommand> _mockValidator;
|
||||
private readonly AddLibraryCommandHandler _sut;
|
||||
private readonly AddLibraryCommandFixture _addLibraryCommandFixture = new();
|
||||
@@ -57,19 +60,22 @@ public class AddLibraryCommandHandlerTests
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
_mockEnvironmentContext = Substitute.For<IEnvironmentContext>();
|
||||
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
|
||||
_mockValidator = Substitute.For<IValidator<AddLibraryCommand>>();
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
// default stubs: the current user is authenticated, is an admin, and the cover image is a valid image
|
||||
// default stubs: the current user is authenticated, is an admin, the cover image is a valid image, and the provider configurations are seeded successfully
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(true);
|
||||
_mockEnvironmentContext.FileTypeService.GetImageTypeAsync(Arg.Any<FileSystemPathId>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(ImageType.PNG));
|
||||
_mockLibraryRepository.InsertAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
_mockValidator.Validate(Arg.Any<AddLibraryCommand>()).Returns([]);
|
||||
|
||||
_sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockUnitOfWork, _mockValidator);
|
||||
_sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -88,10 +94,28 @@ public class AddLibraryCommandHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(persistedLibrary.Id, result.Value.Id);
|
||||
await _mockLibraryRepository.Received(1).InsertAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.Received(1).EnsureProviderConfigurationsAsync(
|
||||
Arg.Any<Guid>(), Arg.Is<LibraryType>(libraryType => libraryType == Enum.Parse<LibraryType>(command.LibraryType)), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
_mockDomainEventsQueue.Received(1).Enqueue(Arg.Any<LibrarySavedDomainEvent>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenProviderConfigurationSeedingFails_ShouldReturnErrorWithoutSaving()
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryCommand command = _addLibraryCommandFixture.Create();
|
||||
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to seed provider configurations"));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCoverImageIsNull_ShouldSkipImageTypeCheck()
|
||||
{
|
||||
|
||||
+28
-2
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
@@ -36,6 +37,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
private readonly IAuthorizationService _mockAuthorizationService;
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
|
||||
private readonly IValidator<DeleteLibraryCommand> _mockValidator;
|
||||
private readonly DeleteLibraryCommandHandler _sut;
|
||||
private readonly DeleteLibraryCommandFixture _deleteLibraryCommandFixture = new();
|
||||
@@ -53,18 +55,21 @@ public class DeleteLibraryCommandHandlerTests
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
|
||||
_mockValidator = Substitute.For<IValidator<DeleteLibraryCommand>>();
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
// default stubs: the current user is authenticated and the ownership policy allows the deletion
|
||||
// default stubs: the current user is authenticated, the ownership policy allows the deletion, and the provider configurations are removed successfully
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockProviderConfigurationStore.RemoveProviderConfigurationsForLibraryAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
_mockLibraryRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
_mockValidator.Validate(Arg.Any<DeleteLibraryCommand>()).Returns([]);
|
||||
|
||||
_sut = new DeleteLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockUnitOfWork, _mockValidator);
|
||||
_sut = new DeleteLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,11 +87,32 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
await _mockProviderConfigurationStore.Received(1).RemoveProviderConfigurationsForLibraryAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(1).DeleteByIdAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
_mockDomainEventsQueue.Received(1).Enqueue(Arg.Any<LibraryDeletedDomainEvent>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenProviderConfigurationRemovalFails_ShouldReturnErrorWithoutSaving()
|
||||
{
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockProviderConfigurationStore.RemoveProviderConfigurationsForLibraryAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to remove provider configurations"));
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockLibraryRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenLibraryDoesNotExist_ShouldReturnNotFoundError()
|
||||
{
|
||||
|
||||
+51
-2
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
@@ -16,6 +17,7 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -41,6 +43,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly IEnvironmentContext _mockEnvironmentContext;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
|
||||
private readonly IValidator<UpdateLibraryCommand> _mockValidator;
|
||||
private readonly UpdateLibraryCommandHandler _sut;
|
||||
private readonly UpdateLibraryCommandFixture _updateLibraryCommandFixture = new();
|
||||
@@ -59,10 +62,11 @@ public class UpdateLibraryCommandHandlerTests
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
_mockEnvironmentContext = Substitute.For<IEnvironmentContext>();
|
||||
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
|
||||
_mockValidator = Substitute.For<IValidator<UpdateLibraryCommand>>();
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
// default stubs: the current user is authenticated, has the manage permission, and the cover image is a valid image
|
||||
// default stubs: the current user is authenticated, has the manage permission, the cover image is a valid image, and the provider configurations are reconciled successfully
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockAuthorizationService.HasPermissionAsync(_userId, Arg.Any<AuthorizationPermission>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
@@ -70,9 +74,11 @@ public class UpdateLibraryCommandHandlerTests
|
||||
.Returns(Result.From(ImageType.PNG));
|
||||
_mockLibraryRepository.UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
_mockProviderConfigurationStore.ReconcileProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
_mockValidator.Validate(Arg.Any<UpdateLibraryCommand>()).Returns([]);
|
||||
|
||||
_sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockUnitOfWork, _mockValidator);
|
||||
_sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,7 +86,9 @@ public class UpdateLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryType commandLibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = commandLibraryType == LibraryType.Book ? LibraryType.EBook : LibraryType.Book;
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
@@ -91,10 +99,51 @@ public class UpdateLibraryCommandHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(existingLibrary.Id, result.Value.Id);
|
||||
await _mockLibraryRepository.Received(1).UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.Received(1).ReconcileProviderConfigurationsAsync(
|
||||
command.Id, Arg.Is<LibraryType>(libraryType => libraryType == commandLibraryType), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
_mockDomainEventsQueue.Received(1).Enqueue(Arg.Any<LibrarySavedDomainEvent>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenLibraryTypeIsUnchanged_ShouldNotReconcileProviderConfigurations()
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockProviderConfigurationStore.DidNotReceive().ReconcileProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenProviderConfigurationReconciliationFails_ShouldReturnErrorWithoutSaving()
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryType commandLibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = commandLibraryType == LibraryType.Book ? LibraryType.EBook : LibraryType.Book;
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockProviderConfigurationStore.ReconcileProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to reconcile provider configurations"));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCoverImageIsNull_ShouldSkipImageTypeCheck()
|
||||
{
|
||||
|
||||
+12
-12
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
@@ -30,10 +31,10 @@ namespace Lumina.Application.UnitTests.Core.Plugins.Queries.GetLibraryMetadataPr
|
||||
public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
{
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly ILibraryMetadataProviderConfigurationRepository _mockLibraryMetadataProviderConfigurationRepository;
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly IAuthorizationService _mockAuthorizationService;
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
|
||||
private readonly IValidator<GetLibraryMetadataProvidersQuery> _mockValidator;
|
||||
private readonly GetLibraryMetadataProvidersQueryHandler _sut;
|
||||
private readonly GetLibraryMetadataProvidersQueryFixture _getLibraryMetadataProvidersQueryFixture = new();
|
||||
@@ -47,12 +48,11 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
public GetLibraryMetadataProvidersQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockLibraryMetadataProviderConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.LibraryMetadataProviderConfigurationRepository.Returns(_mockLibraryMetadataProviderConfigurationRepository);
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
|
||||
_mockValidator = Substitute.For<IValidator<GetLibraryMetadataProvidersQuery>>();
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
.Returns(true);
|
||||
_mockValidator.Validate(Arg.Any<GetLibraryMetadataProvidersQuery>()).Returns([]);
|
||||
|
||||
_sut = new GetLibraryMetadataProvidersQueryHandler(_mockAuthorizationService, _mockCurrentUserService, _mockUnitOfWork, _mockValidator);
|
||||
_sut = new GetLibraryMetadataProvidersQueryHandler(_mockAuthorizationService, _mockCurrentUserService, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -78,7 +78,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Plugins.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryMetadataProviderConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.DidNotReceive().GetConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,7 +93,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
_configurationEntityFixture.Create(query.LibraryId, secondPluginId, 2),
|
||||
_configurationEntityFixture.Create(query.LibraryId, firstPluginId, 1)
|
||||
];
|
||||
_mockLibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>(configurations));
|
||||
List<PluginEntity> plugins =
|
||||
[
|
||||
@@ -125,7 +125,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
[
|
||||
_configurationEntityFixture.Create(query.LibraryId, unknownPluginId, 1)
|
||||
];
|
||||
_mockLibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>(configurations));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([_pluginEntityFixture.Create()]));
|
||||
@@ -145,7 +145,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryMetadataProvidersQuery query = _getLibraryMetadataProvidersQueryFixture.Create();
|
||||
_mockLibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([]));
|
||||
@@ -164,7 +164,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
// Arrange
|
||||
GetLibraryMetadataProvidersQuery query = _getLibraryMetadataProvidersQueryFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get configurations");
|
||||
_mockLibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -180,7 +180,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryMetadataProvidersQuery query = _getLibraryMetadataProvidersQueryFixture.Create();
|
||||
_mockLibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
@@ -208,7 +208,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.Received(1).EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
_userId, Arg.Is<LibraryOwnershipPolicyContext>(context => context.LibraryId == query.LibraryId), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryMetadataProviderConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.DidNotReceive().GetConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -226,6 +226,6 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryMetadataProviderConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.DidNotReceive().GetConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user