mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 03:11:10 +00:00
Moves media library scanning to domain layer
This commit is contained in:
1 parent
8b51abe0b2
commit
c4246d2e69
209 files changed
+3793
-641
No files matched your search
+1
-1
@@ -196,7 +196,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.GetTempPath();
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string originalPath = System.IO.Path.GetTempPath();
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.GetTempPath();
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
using CancellationTokenSource cts = new();
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
string testPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "testDirectory");
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
int quality = 80;
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCancelled_ShouldThrowTaskCanceledException()
|
||||
public async Task ExecuteAsync_WhenCancellationTokenIsCanceled_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
using CancellationTokenSource cts = new();
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -35,7 +36,8 @@ public class LibraryEntityMappingTests
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
UpdatedBy = null,
|
||||
LibraryScans = []
|
||||
};
|
||||
|
||||
// Act
|
||||
|
||||
+51
-11
@@ -6,7 +6,8 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -25,7 +26,7 @@ public class LibraryMappingTests
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
["C:/Books", "D:/Media/Books"],
|
||||
@@ -33,7 +34,8 @@ public class LibraryMappingTests
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
[ScanId.CreateUnique()]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -54,6 +56,7 @@ public class LibraryMappingTests
|
||||
Assert.False(result.IsLocked);
|
||||
Assert.True(result.DownloadMedatadaFromWeb);
|
||||
Assert.False(result.SaveMetadataInMediaDirectories);
|
||||
Assert.Equal(library.ScanIds.Select(scanId => scanId.Value), result.LibraryScans.Select(libraryScan => libraryScan.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +64,7 @@ public class LibraryMappingTests
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
"Empty Library",
|
||||
LibraryType.Book,
|
||||
[],
|
||||
@@ -69,7 +72,8 @@ public class LibraryMappingTests
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
[ScanId.CreateUnique()]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -91,7 +95,7 @@ public class LibraryMappingTests
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
"Test Library",
|
||||
libraryType,
|
||||
["C:/Media"],
|
||||
@@ -99,7 +103,8 @@ public class LibraryMappingTests
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
[ScanId.CreateUnique()]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -129,7 +134,7 @@ public class LibraryMappingTests
|
||||
];
|
||||
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations,
|
||||
@@ -137,7 +142,8 @@ public class LibraryMappingTests
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
[ScanId.CreateUnique()]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -161,7 +167,7 @@ public class LibraryMappingTests
|
||||
];
|
||||
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations,
|
||||
@@ -169,7 +175,8 @@ public class LibraryMappingTests
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
[ScanId.CreateUnique()]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -181,4 +188,37 @@ public class LibraryMappingTests
|
||||
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
|
||||
Assert.Null(result.CoverImage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingEmptyScanList_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<string> contentLocations =
|
||||
[
|
||||
"C:/Media/Books",
|
||||
"D:/Books"
|
||||
];
|
||||
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
UserId.CreateUnique(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations,
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
[]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(library.ScanIds);
|
||||
Assert.NotNull(result.LibraryScans);
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -4,6 +4,8 @@ using ErrorOr;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -44,7 +46,7 @@ public class DomainLibraryFixture
|
||||
];
|
||||
|
||||
ErrorOr<Library> library = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
UserId.CreateUnique(),
|
||||
_faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
_faker.PickRandom<LibraryType>(),
|
||||
validPaths.Take(_random.Next(1, validPaths.Count)),
|
||||
@@ -52,7 +54,8 @@ public class DomainLibraryFixture
|
||||
_faker.Random.Bool(),
|
||||
_faker.Random.Bool(),
|
||||
_faker.Random.Bool(),
|
||||
_faker.Random.Bool()
|
||||
_faker.Random.Bool(),
|
||||
[ScanId.CreateUnique(), ScanId.CreateUnique()]
|
||||
);
|
||||
|
||||
return library.Value;
|
||||
@@ -68,11 +71,12 @@ public class DomainLibraryFixture
|
||||
bool isEnabled = true,
|
||||
bool isLocked = false,
|
||||
bool downloadMedatadaFromWeb = true,
|
||||
bool saveMetadataInMediaDirectories = false)
|
||||
bool saveMetadataInMediaDirectories = false,
|
||||
IEnumerable<Guid>? scanIds = null)
|
||||
{
|
||||
ErrorOr<Library> library = id is null ?
|
||||
Library.Create(
|
||||
userId ?? Guid.NewGuid(),
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? LibraryType.Book,
|
||||
contentLocations ?? ["C:/Media"],
|
||||
@@ -80,11 +84,12 @@ public class DomainLibraryFixture
|
||||
isEnabled,
|
||||
isLocked,
|
||||
downloadMedatadaFromWeb,
|
||||
saveMetadataInMediaDirectories
|
||||
saveMetadataInMediaDirectories,
|
||||
scanIds?.Select(scanId => ScanId.Create(scanId)).ToList() ?? [ScanId.CreateUnique(), ScanId.CreateUnique()]
|
||||
) :
|
||||
Library.Create(
|
||||
LibraryId.Create(id.Value),
|
||||
userId ?? Guid.NewGuid(),
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? LibraryType.Book,
|
||||
contentLocations ?? ["C:/Media"],
|
||||
@@ -92,7 +97,8 @@ public class DomainLibraryFixture
|
||||
isEnabled,
|
||||
isLocked,
|
||||
downloadMedatadaFromWeb,
|
||||
saveMetadataInMediaDirectories
|
||||
saveMetadataInMediaDirectories,
|
||||
scanIds?.Select(scanId => ScanId.Create(scanId)).ToList() ?? [ScanId.CreateUnique(), ScanId.CreateUnique()]
|
||||
);
|
||||
|
||||
return library.Value;
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class UserEntityFixture
|
||||
/// Creates a valid collection of user libraries.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of user libraries to create.</param>
|
||||
/// <param name="userId">The Id of the user for whom to create the libraries.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to create the libraries.</param>
|
||||
/// <returns>A collection of <see cref="LibraryEntity"/>.</returns>
|
||||
private static List<LibraryEntity> CreateLibraries(int count, Guid userId)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user