Adds dynamic path templates for media libraries, so that the scanner can derive the meaning of each path part

This commit is contained in:
BinaryAlley committed 2026-10-05 18:42:00 +03:00
1 parent 62b0e9297a
commit ca4f308b0a
86 files changed
+7406 -151

No files matched your search

@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
@@ -27,6 +28,7 @@ public class AddLibraryCommandFixture
/// <param name="canDownloadMetadataFromWeb">Whether the media library should download metadata from the web or not.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Whether the metadata should be saved in the media directories or not.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <returns>The created command.</returns>
public AddLibraryCommand Create(
string? title = null,
@@ -37,7 +39,8 @@ public class AddLibraryCommandFixture
bool isLocked = false,
bool canDownloadMetadataFromWeb = true,
bool shouldSaveMetadataInMediaDirectories = true,
bool shouldSkipUnchangedDirectoriesDuringScan = false)
bool shouldSkipUnchangedDirectoriesDuringScan = false,
LibraryPathTemplatePartDto[]? pathTemplateParts = null)
{
return new Faker<AddLibraryCommand>()
.CustomInstantiator(f => new AddLibraryCommand(
@@ -49,7 +52,8 @@ public class AddLibraryCommandFixture
false,
true,
true,
false
false,
null
))
.RuleFor(x => x.Title, f => title ?? f.Lorem.Word())
.RuleFor(x => x.LibraryType, f => libraryType ?? f.Random.Enum<LibraryType>().ToString())
@@ -60,6 +64,7 @@ public class AddLibraryCommandFixture
.RuleFor(x => x.CanDownloadMetadataFromWeb, canDownloadMetadataFromWeb)
.RuleFor(x => x.ShouldSaveMetadataInMediaDirectories, shouldSaveMetadataInMediaDirectories)
.RuleFor(x => x.ShouldSkipUnchangedDirectoriesDuringScan, shouldSkipUnchangedDirectoriesDuringScan)
.RuleFor(x => x.PathTemplateParts, pathTemplateParts)
.Generate();
}
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
@@ -30,6 +31,7 @@ public class UpdateLibraryCommandFixture
/// <param name="canDownloadMetadataFromWeb">Whether the media library should download metadata from the web or not.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Whether the metadata should be saved in the media directories or not.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <returns>The created command.</returns>
public UpdateLibraryCommand Create(
Guid? id = null,
@@ -42,7 +44,8 @@ public class UpdateLibraryCommandFixture
bool isLocked = false,
bool canDownloadMetadataFromWeb = true,
bool shouldSaveMetadataInMediaDirectories = true,
bool shouldSkipUnchangedDirectoriesDuringScan = false)
bool shouldSkipUnchangedDirectoriesDuringScan = false,
LibraryPathTemplatePartDto[]? pathTemplateParts = null)
{
return new Faker<UpdateLibraryCommand>()
.CustomInstantiator(f => new UpdateLibraryCommand(
@@ -56,7 +59,8 @@ public class UpdateLibraryCommandFixture
false,
true,
true,
false
false,
null
))
.RuleFor(x => x.Id, id ?? Guid.NewGuid())
.RuleFor(x => x.OwnerId, ownerId ?? Guid.NewGuid())
@@ -69,6 +73,7 @@ public class UpdateLibraryCommandFixture
.RuleFor(x => x.CanDownloadMetadataFromWeb, canDownloadMetadataFromWeb)
.RuleFor(x => x.ShouldSaveMetadataInMediaDirectories, shouldSaveMetadataInMediaDirectories)
.RuleFor(x => x.ShouldSkipUnchangedDirectoriesDuringScan, shouldSkipUnchangedDirectoriesDuringScan)
.RuleFor(x => x.PathTemplateParts, pathTemplateParts)
.Generate();
}
@@ -28,6 +28,7 @@ public class AddLibraryRequestFixture
/// <param name="canDownloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <returns>The created <see cref="AddLibraryRequest"/>.</returns>
public AddLibraryRequest Create(
string? title = null,
@@ -38,7 +39,8 @@ public class AddLibraryRequestFixture
bool? isLocked = null,
bool? canDownloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null)
bool? shouldSkipUnchangedDirectoriesDuringScan = null,
LibraryPathTemplatePartRequest[]? pathTemplateParts = null)
{
return new AddLibraryRequest(
title ?? _faker.Commerce.Department(),
@@ -49,7 +51,8 @@ public class AddLibraryRequestFixture
isLocked ?? _faker.Random.Bool(),
canDownloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool()
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(),
pathTemplateParts
);
}
@@ -31,6 +31,7 @@ public class UpdateLibraryRequestFixture
/// <param name="canDownloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <returns>The created <see cref="UpdateLibraryRequest"/>.</returns>
public UpdateLibraryRequest Create(
Guid? id = null,
@@ -43,7 +44,8 @@ public class UpdateLibraryRequestFixture
bool? isLocked = null,
bool? canDownloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null)
bool? shouldSkipUnchangedDirectoriesDuringScan = null,
LibraryPathTemplatePartRequest[]? pathTemplateParts = null)
{
return new UpdateLibraryRequest(
id ?? _faker.Random.Guid(),
@@ -56,7 +58,8 @@ public class UpdateLibraryRequestFixture
isLocked ?? _faker.Random.Bool(),
canDownloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool()
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(),
pathTemplateParts
);
}
@@ -32,6 +32,7 @@ public class LibraryResponseFixture
/// <param name="canDownloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <param name="pathTemplateParts">Optional. The ordered parts of the path template of the media library.</param>
/// <param name="createdOnUtc">Optional. The date and time when the library was created.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the library was updated.</param>
/// <returns>The created <see cref="LibraryResponse"/>.</returns>
@@ -47,6 +48,7 @@ public class LibraryResponseFixture
bool? canDownloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null,
List<LibraryPathTemplatePartResponse>? pathTemplateParts = null,
DateTime? createdOnUtc = null,
DateTime? updatedOnUtc = null)
{
@@ -62,6 +64,7 @@ public class LibraryResponseFixture
canDownloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(),
pathTemplateParts ?? [],
createdOnUtc ?? _faker.Date.Past().ToUniversalTime(),
updatedOnUtc
);
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
@@ -42,6 +43,7 @@ public class LibraryFixture
/// <param name="shouldSaveMetadataInMediaDirectories">Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during scan.</param>
/// <param name="scanIds">Optional. The scan Ids associated with the library.</param>
/// <param name="pathTemplate">Optional. The path template of the library.</param>
/// <param name="includeCoverImage">Whether the cover image should be included, or left unset, meaning the library has no cover.</param>
/// <returns>The created <see cref="Library"/>.</returns>
public Library Create(
@@ -57,6 +59,7 @@ public class LibraryFixture
bool shouldSaveMetadataInMediaDirectories = false,
bool shouldSkipUnchangedDirectoriesDuringScan = false,
IEnumerable<Guid>? scanIds = null,
LibraryPathTemplate? pathTemplate = null,
bool includeCoverImage = true)
{
List<string> validPaths =
@@ -83,6 +86,7 @@ public class LibraryFixture
canDownloadMetadataFromWeb,
shouldSaveMetadataInMediaDirectories,
shouldSkipUnchangedDirectoriesDuringScan,
pathTemplate ?? LibraryPathTemplate.Empty(),
resolvedScanIds
) :
Library.Create(
@@ -97,6 +101,7 @@ public class LibraryFixture
canDownloadMetadataFromWeb,
shouldSaveMetadataInMediaDirectories,
shouldSkipUnchangedDirectoriesDuringScan,
pathTemplate ?? LibraryPathTemplate.Empty(),
resolvedScanIds
);
@@ -12,6 +12,8 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Manage
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate;
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;
@@ -42,6 +44,7 @@ public class AddLibraryCommandHandlerTests
private readonly IDomainEventsQueue _mockDomainEventsQueue;
private readonly IEnvironmentContext _mockEnvironmentContext;
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
private readonly ILibraryPathTemplateService _mockLibraryPathTemplateService;
private readonly IValidator<AddLibraryCommand> _mockValidator;
private readonly AddLibraryCommandHandler _sut;
private readonly AddLibraryCommandFixture _addLibraryCommandFixture = new();
@@ -62,6 +65,7 @@ public class AddLibraryCommandHandlerTests
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
_mockEnvironmentContext = Substitute.For<IEnvironmentContext>();
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
_mockLibraryPathTemplateService = Substitute.For<ILibraryPathTemplateService>();
_mockValidator = Substitute.For<IValidator<AddLibraryCommand>>();
_userId = Guid.NewGuid();
@@ -75,8 +79,10 @@ public class AddLibraryCommandHandlerTests
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
.Returns(Result.Success);
_mockValidator.Validate(Arg.Any<AddLibraryCommand>()).Returns([]);
_mockLibraryPathTemplateService.GetDefaultTemplate(Arg.Any<LibraryType>()).Returns(LibraryPathTemplate.Empty());
_mockLibraryPathTemplateService.Validate(Arg.Any<LibraryType>(), Arg.Any<LibraryPathTemplate>()).Returns(Result.Success);
_sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
_sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockLibraryPathTemplateService, _mockUnitOfWork, _mockValidator);
}
[Fact]
@@ -13,6 +13,8 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Manage
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate;
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;
@@ -44,6 +46,7 @@ public class UpdateLibraryCommandHandlerTests
private readonly IDomainEventsQueue _mockDomainEventsQueue;
private readonly IEnvironmentContext _mockEnvironmentContext;
private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore;
private readonly ILibraryPathTemplateService _mockLibraryPathTemplateService;
private readonly IValidator<UpdateLibraryCommand> _mockValidator;
private readonly UpdateLibraryCommandHandler _sut;
private readonly UpdateLibraryCommandFixture _updateLibraryCommandFixture = new();
@@ -64,6 +67,7 @@ public class UpdateLibraryCommandHandlerTests
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
_mockEnvironmentContext = Substitute.For<IEnvironmentContext>();
_mockProviderConfigurationStore = Substitute.For<IMediaLibraryProviderConfigurationStore>();
_mockLibraryPathTemplateService = Substitute.For<ILibraryPathTemplateService>();
_mockValidator = Substitute.For<IValidator<UpdateLibraryCommand>>();
_userId = Guid.NewGuid();
@@ -78,8 +82,10 @@ public class UpdateLibraryCommandHandlerTests
_mockProviderConfigurationStore.ReconcileProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
.Returns(Result.Success);
_mockValidator.Validate(Arg.Any<UpdateLibraryCommand>()).Returns([]);
_mockLibraryPathTemplateService.GetDefaultTemplate(Arg.Any<LibraryType>()).Returns(LibraryPathTemplate.Empty());
_mockLibraryPathTemplateService.Validate(Arg.Any<LibraryType>(), Arg.Any<LibraryPathTemplate>()).Returns(Result.Success);
_sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator);
_sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockLibraryPathTemplateService, _mockUnitOfWork, _mockValidator);
}
[Fact]
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
@@ -51,6 +52,7 @@ public class LibraryTests
canDownloadMetadataFromWeb: false,
shouldSaveMetadataInMediaDirectories: true,
shouldSkipUnchangedDirectoriesDuringScan: true,
LibraryPathTemplate.Empty(),
scanIds);
// Assert
@@ -89,6 +91,7 @@ public class LibraryTests
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
LibraryPathTemplate.Empty(),
scanIds);
// Assert
@@ -115,6 +118,7 @@ public class LibraryTests
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
LibraryPathTemplate.Empty(),
[]);
// Assert
@@ -150,6 +154,7 @@ public class LibraryTests
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
LibraryPathTemplate.Empty(),
[]);
// Assert
@@ -177,6 +182,7 @@ public class LibraryTests
canDownloadMetadataFromWeb: true,
shouldSaveMetadataInMediaDirectories: false,
shouldSkipUnchangedDirectoriesDuringScan: false,
LibraryPathTemplate.Empty(),
[]);
// Assert