mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Improves the plugin system documentation, tests and conventions
- Documents the book metadata DTOs and the Book aggregate constructor parameters - References ADR-0006 in the scan snapshot repository remarks, explaining the Dapper choice - Extracts shared plugin entity fixtures and uses them in the plugin and metadata provider tests - Moves PluginLoadResult to the Common DTO models, renaming it PluginLoadResultDto - Replaces the duplicate Contracts plugin setting type with the shared kernel enum - Removes the generated plugin view Designer file and its project wiring - Drops redundant braces in the plugin repositories
This commit is contained in:
1 parent
42566dcf06
commit
3653ff5bd7
25 files changed
+168
-321
No files matched your search
-1
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
using ContractsPluginSettingType = Lumina.Contracts.Responses.Plugins.PluginSettingType;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||
@@ -21,7 +21,7 @@ public static class PluginSettingDescriptorMapping
|
||||
return new PluginSettingDescriptorResponse(
|
||||
descriptor.Key,
|
||||
descriptor.Label,
|
||||
(ContractsPluginSettingType)(int)descriptor.Type,
|
||||
(PluginSettingType)(int)descriptor.Type,
|
||||
descriptor.DefaultValue,
|
||||
descriptor.AllowedValues
|
||||
);
|
||||
|
||||
+27
@@ -10,6 +10,33 @@ namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
/// <summary>
|
||||
/// Data transfer object for the metadata of a book returned by a metadata provider.
|
||||
/// </summary>
|
||||
/// <param name="Title">The title of the book.</param>
|
||||
/// <param name="OriginalTitle">The original title of the book, if different from the current title.</param>
|
||||
/// <param name="Description">A brief description or summary of the book.</param>
|
||||
/// <param name="ReleaseInfo">The release information, including release date and other relevant details.</param>
|
||||
/// <param name="Genres">The list of genres associated with the book.</param>
|
||||
/// <param name="Tags">The list of tags that further describe or categorize the book.</param>
|
||||
/// <param name="Language">The language in which the book is written.</param>
|
||||
/// <param name="OriginalLanguage">The original language of the book, if it has been translated.</param>
|
||||
/// <param name="Publisher">The name of the publisher of the book.</param>
|
||||
/// <param name="PageCount">The number of pages in the book.</param>
|
||||
/// <param name="Format">The format of the book (e.g., Hardcover, Paperback), if applicable.</param>
|
||||
/// <param name="Edition">The edition of the book, if applicable.</param>
|
||||
/// <param name="VolumeNumber">The volume or book number in the series, if applicable.</param>
|
||||
/// <param name="Series">The series name, if the book is part of a series.</param>
|
||||
/// <param name="ASIN">The ASIN (Amazon Standard Identification Number) of the book, if applicable.</param>
|
||||
/// <param name="GoodreadsId">The Goodreads ID of the book, if applicable.</param>
|
||||
/// <param name="LCCN">The Library of Congress Control Number (LCCN) of the book, if applicable.</param>
|
||||
/// <param name="OCLCNumber">The OCLC Number (WorldCat identifier) of the book, if applicable.</param>
|
||||
/// <param name="OpenLibraryId">The Open Library ID of the book, if applicable.</param>
|
||||
/// <param name="LibraryThingId">The LibraryThing ID of the book, if applicable.</param>
|
||||
/// <param name="GoogleBooksId">The Google Books ID of the book, if applicable.</param>
|
||||
/// <param name="BarnesAndNobleId">The Barnes & Noble ID of the book, if applicable.</param>
|
||||
/// <param name="AppleBooksId">The Apple Books ID of the book, if applicable.</param>
|
||||
/// <param name="Isbns">The list of ISBN (International Standard Book Number) of the book.</param>
|
||||
/// <param name="Contributors">The list of media contributors of the book.</param>
|
||||
/// <param name="Ratings">The list of ratings for the book.</param>
|
||||
/// <param name="CoverImageUrl">The URL of the cover image of the book, if applicable.</param>
|
||||
public sealed record BookMetadataDto(
|
||||
string? Title,
|
||||
string? OriginalTitle,
|
||||
|
||||
+7
-9
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
@@ -9,6 +8,13 @@ namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
/// <summary>
|
||||
/// Data transfer object for a book metadata lookup.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library the book belongs to.</param>
|
||||
/// <param name="Path">The file system path of the book.</param>
|
||||
/// <param name="Isbn">The ISBN (International Standard Book Number) of the book, if applicable.</param>
|
||||
/// <param name="OpenLibraryId">The Open Library ID of the book, if applicable.</param>
|
||||
/// <param name="Title">The title of the book, if applicable.</param>
|
||||
/// <param name="Author">The author of the book, if applicable.</param>
|
||||
/// <param name="LanguageCode">The language code of the book, if applicable.</param>
|
||||
public sealed record BookMetadataLookupDto(
|
||||
Guid LibraryId,
|
||||
string Path,
|
||||
@@ -17,12 +23,4 @@ public sealed record BookMetadataLookupDto(
|
||||
string? Title = null,
|
||||
string? Author = null,
|
||||
string? LanguageCode = null
|
||||
//string? Title,
|
||||
//string? OriginalTitle,
|
||||
//int? ReleaseYear,
|
||||
//string? LanguageCode,
|
||||
//IReadOnlyList<string>? Isbns,
|
||||
//string? GoodreadsId,
|
||||
//string? OpenLibraryId,
|
||||
//string? GoogleBooksId
|
||||
) : MetadataLookupDto;
|
||||
@@ -10,7 +10,7 @@ namespace Lumina.Contracts.Requests.Plugins;
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose metadata provider is enabled or disabled. Required.</param>
|
||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata. Required.</param>
|
||||
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library.</param>
|
||||
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library. Required.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
|
||||
public sealed record SetLibraryMetadataProviderEnabledRequest(
|
||||
Guid LibraryId,
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Lumina.Contracts.Requests.Plugins;
|
||||
/// Represents a request to update the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="PluginId">The unique identifier of the plugin. Required.</param>
|
||||
/// <param name="Settings">The settings of the plugin.</param>
|
||||
/// <param name="Settings">The settings of the plugin. Required.</param>
|
||||
[DebuggerDisplay("PluginId: {PluginId}")]
|
||||
public sealed record UpdatePluginSettingsRequest(
|
||||
Guid PluginId,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace Lumina.Contracts.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the types of a plugin setting.
|
||||
/// </summary>
|
||||
public enum PluginSettingType
|
||||
{
|
||||
/// <summary>
|
||||
/// A free-form single line text value.
|
||||
/// </summary>
|
||||
Text,
|
||||
|
||||
/// <summary>
|
||||
/// A numeric value.
|
||||
/// </summary>
|
||||
Number,
|
||||
|
||||
/// <summary>
|
||||
/// A boolean (true/false) value.
|
||||
/// </summary>
|
||||
Boolean,
|
||||
|
||||
/// <summary>
|
||||
/// A value selected from a list of allowed values.
|
||||
/// </summary>
|
||||
Select
|
||||
}
|
||||
@@ -18,6 +18,11 @@ namespace Lumina.DataAccess.Core.Repositories.Libraries;
|
||||
/// <summary>
|
||||
/// Repository for media library scan snapshots.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The bulk snapshot operations are executed with parameterized raw SQL through Dapper on a dedicated database connection, instead of Entity Framework Core,
|
||||
/// because the change tracker is not suited for the multi-row inserts, upserts, key-set paginated reads and bulk deletes that the media library scan pipeline performs at scale.
|
||||
/// See docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0006.md for details.
|
||||
/// </remarks>
|
||||
internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotRepository
|
||||
{
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
|
||||
-2
@@ -66,9 +66,7 @@ internal sealed class LibraryMetadataProviderConfigurationRepository : ILibraryM
|
||||
LibraryMetadataProviderConfigurationEntity? existingConfiguration = await _luminaDbContext.LibraryMetadataProviderConfigurations
|
||||
.FirstOrDefaultAsync(repositoryConfiguration => repositoryConfiguration.LibraryId == configuration.LibraryId && repositoryConfiguration.PluginId == configuration.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (existingConfiguration is null)
|
||||
{
|
||||
_luminaDbContext.LibraryMetadataProviderConfigurations.Add(configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
// update only the mutable fields, preserving the Id of the existing configuration
|
||||
|
||||
@@ -63,9 +63,7 @@ internal sealed class PluginRepository : IPluginRepository
|
||||
PluginEntity? existingPlugin = await _luminaDbContext.Plugins
|
||||
.FirstOrDefaultAsync(repositoryPlugin => repositoryPlugin.Id == plugin.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (existingPlugin is null)
|
||||
{
|
||||
_luminaDbContext.Plugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
// update only the detection fields, preserving the stored settings and creation date
|
||||
|
||||
+2
@@ -138,6 +138,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// Initializes a new instance of the <see cref="Book"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of the book.</param>
|
||||
/// <param name="libraryId">The Id of the media library this book belongs to.</param>
|
||||
/// <param name="path">The file system path of the book.</param>
|
||||
/// <param name="metadata">The metadata of the book.</param>
|
||||
/// <param name="format">The optional format of the book (e.g., Hardcover, Paperback).</param>
|
||||
/// <param name="edition">The optional edition of the book.</param>
|
||||
|
||||
@@ -14,6 +14,7 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Lumina.Infrastructure.Common.DomainEvents;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Lumina.Infrastructure.Core.Authentication;
|
||||
using Lumina.Infrastructure.Core.Authorization;
|
||||
using Lumina.Infrastructure.Core.Authorization.Policies.Common.Factory;
|
||||
@@ -89,7 +90,7 @@ public static class InfrastructureLayerServices
|
||||
// plugins: load the plugin assemblies from the plugins directory, register their services and provide the plugin manager
|
||||
string pluginsDirectorySetting = configuration.GetSection(PluginsSettingsDto.SECTION_NAME)["Directory"] ?? "plugins";
|
||||
string pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsDirectorySetting);
|
||||
PluginLoadResult pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
|
||||
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
|
||||
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins));
|
||||
services.AddScoped<IPluginSettingsStore, PluginSettingsStore>();
|
||||
services.AddSingleton(serviceProvider => new PluginDetectionSyncJob(
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Common.Models.DTO.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the result of loading the plugins from the plugins directory.
|
||||
/// </summary>
|
||||
/// <param name="Plugins">The plugins that were loaded successfully.</param>
|
||||
/// <param name="Errors">The errors that occurred while loading the plugins.</param>
|
||||
internal sealed record PluginLoadResultDto(IReadOnlyList<IPlugin> Plugins, IReadOnlyList<string> Errors);
|
||||
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
@@ -9,13 +10,6 @@ using System.Reflection;
|
||||
|
||||
namespace Lumina.Infrastructure.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Result of loading the plugins from the plugins directory.
|
||||
/// </summary>
|
||||
/// <param name="Plugins">The plugins that were loaded successfully.</param>
|
||||
/// <param name="Errors">The errors that occurred while loading the plugins.</param>
|
||||
internal sealed record PluginLoadResult(IReadOnlyList<IPlugin> Plugins, IReadOnlyList<string> Errors);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the plugins from the plugins directory, discovers their descriptors and registers their services.
|
||||
/// </summary>
|
||||
@@ -27,13 +21,13 @@ internal static class PluginLoader
|
||||
/// <param name="pluginsDirectory">The directory where the plugin assemblies are located.</param>
|
||||
/// <param name="services">The service collection to which the plugin services are added.</param>
|
||||
/// <returns>The result of loading the plugins.</returns>
|
||||
public static PluginLoadResult LoadPlugins(string pluginsDirectory, IServiceCollection services)
|
||||
public static PluginLoadResultDto LoadPlugins(string pluginsDirectory, IServiceCollection services)
|
||||
{
|
||||
List<IPlugin> plugins = [];
|
||||
List<string> errors = [];
|
||||
|
||||
if (!Directory.Exists(pluginsDirectory))
|
||||
return new PluginLoadResult(plugins, errors);
|
||||
return new PluginLoadResultDto(plugins, errors);
|
||||
|
||||
foreach (string assemblyPath in Directory.EnumerateFiles(pluginsDirectory, "*.dll"))
|
||||
{
|
||||
@@ -60,6 +54,6 @@ internal static class PluginLoader
|
||||
}
|
||||
}
|
||||
|
||||
return new PluginLoadResult(plugins, errors);
|
||||
return new PluginLoadResultDto(plugins, errors);
|
||||
}
|
||||
}
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
@@ -58,11 +58,6 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Item.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Resources\Views\Plugins\Index.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Index.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Lumina.Presentation.Web.Resources.Views.Plugins {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Index {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Index() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lumina.Presentation.Web.Resources.Views.Plugins.Index", typeof(Index).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Author.
|
||||
/// </summary>
|
||||
public static string Author {
|
||||
get {
|
||||
return ResourceManager.GetString("Author", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Description.
|
||||
/// </summary>
|
||||
public static string Description {
|
||||
get {
|
||||
return ResourceManager.GetString("Description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Failed to load.
|
||||
/// </summary>
|
||||
public static string FailedToLoad {
|
||||
get {
|
||||
return ResourceManager.GetString("FailedToLoad", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Loaded.
|
||||
/// </summary>
|
||||
public static string Loaded {
|
||||
get {
|
||||
return ResourceManager.GetString("Loaded", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Load error.
|
||||
/// </summary>
|
||||
public static string LoadError {
|
||||
get {
|
||||
return ResourceManager.GetString("LoadError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Load status.
|
||||
/// </summary>
|
||||
public static string LoadStatus {
|
||||
get {
|
||||
return ResourceManager.GetString("LoadStatus", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Name.
|
||||
/// </summary>
|
||||
public static string Name {
|
||||
get {
|
||||
return ResourceManager.GetString("Name", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No plugins have been detected..
|
||||
/// </summary>
|
||||
public static string NoPlugins {
|
||||
get {
|
||||
return ResourceManager.GetString("NoPlugins", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Plugins.
|
||||
/// </summary>
|
||||
public static string Plugins {
|
||||
get {
|
||||
return ResourceManager.GetString("Plugins", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Save.
|
||||
/// </summary>
|
||||
public static string Save {
|
||||
get {
|
||||
return ResourceManager.GetString("Save", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Settings.
|
||||
/// </summary>
|
||||
public static string Settings {
|
||||
get {
|
||||
return ResourceManager.GetString("Settings", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Settings saved.
|
||||
/// </summary>
|
||||
public static string SettingsSaved {
|
||||
get {
|
||||
return ResourceManager.GetString("SettingsSaved", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Version.
|
||||
/// </summary>
|
||||
public static string Version {
|
||||
get {
|
||||
return ResourceManager.GetString("Version", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-17
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -38,8 +39,9 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
LibraryMetadataProviderConfigurationEntity firstProvider = CreateConfiguration(libraryId, Guid.NewGuid(), 2);
|
||||
LibraryMetadataProviderConfigurationEntity secondProvider = CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntityFixture configurationFixture = new();
|
||||
LibraryMetadataProviderConfigurationEntity firstProvider = configurationFixture.CreateConfiguration(libraryId, Guid.NewGuid(), 2);
|
||||
LibraryMetadataProviderConfigurationEntity secondProvider = configurationFixture.CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
_mockConfigurationRepository.GetByLibraryIdAsync(libraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<LibraryMetadataProviderConfigurationEntity> { firstProvider, secondProvider });
|
||||
_mockConfigurationRepository.UpsertAsync(Arg.Any<LibraryMetadataProviderConfigurationEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -57,19 +59,4 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == firstProvider.PluginId && configuration.Rank == 2),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
private static LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
|
||||
{
|
||||
return new LibraryMetadataProviderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = true,
|
||||
Rank = rank,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
+3
-19
@@ -5,7 +5,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -39,7 +39,8 @@ public class GetPluginsQueryHandlerTests
|
||||
public async Task Handle_WhenCalled_ShouldReturnAllDetectedPlugins()
|
||||
{
|
||||
// Arrange
|
||||
List<PluginEntity> plugins = [CreatePluginEntity(), CreatePluginEntity()];
|
||||
PluginEntityFixture pluginFixture = new();
|
||||
List<PluginEntity> plugins = [pluginFixture.CreatePluginEntity(), pluginFixture.CreatePluginEntity()];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
|
||||
// Act
|
||||
@@ -65,21 +66,4 @@ public class GetPluginsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
}
|
||||
|
||||
private static PluginEntity CreatePluginEntity()
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "Test Plugin",
|
||||
Author = "Lumina",
|
||||
Version = "1.0.0",
|
||||
Description = "A test plugin.",
|
||||
LoadStatus = PluginLoadStatus.Loaded,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -40,5 +40,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Application\Lumina.Application.csproj" />
|
||||
<ProjectReference Include="..\Lumina.DataAccess.UnitTests\Lumina.DataAccess.UnitTests.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LibraryMetadataProviderConfigurationEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryMetadataProviderConfigurationEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryMetadataProviderConfigurationEntity"/> for the provided media library, plugin and rank.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the configuration belongs to.</param>
|
||||
/// <param name="pluginId">The Id of the plugin providing the metadata.</param>
|
||||
/// <param name="rank">The rank of the metadata provider, determining the order in which providers are tried.</param>
|
||||
/// <returns>The created <see cref="LibraryMetadataProviderConfigurationEntity"/>.</returns>
|
||||
public LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
|
||||
{
|
||||
return new Faker<LibraryMetadataProviderConfigurationEntity>()
|
||||
.RuleFor(configuration => configuration.Id, faker => faker.Random.Guid())
|
||||
.RuleFor(configuration => configuration.LibraryId, libraryId)
|
||||
.RuleFor(configuration => configuration.PluginId, pluginId)
|
||||
.RuleFor(configuration => configuration.IsEnabled, faker => faker.Random.Bool())
|
||||
.RuleFor(configuration => configuration.Rank, rank)
|
||||
.RuleFor(configuration => configuration.CreatedOnUtc, faker => faker.Date.Past())
|
||||
.RuleFor(configuration => configuration.CreatedBy, faker => faker.Random.Guid())
|
||||
.RuleFor(configuration => configuration.UpdatedOnUtc, faker => faker.Date.Recent())
|
||||
.RuleFor(configuration => configuration.UpdatedBy, faker => faker.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PluginEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PluginEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin, or <see langword="null"/> to generate a random one.</param>
|
||||
/// <returns>The created <see cref="PluginEntity"/>.</returns>
|
||||
public PluginEntity CreatePluginEntity(Guid? id = null)
|
||||
{
|
||||
return new Faker<PluginEntity>()
|
||||
.RuleFor(plugin => plugin.Id, faker => id ?? faker.Random.Guid())
|
||||
.RuleFor(plugin => plugin.Name, faker => faker.Company.CompanyName())
|
||||
.RuleFor(plugin => plugin.Author, faker => faker.Name.FullName())
|
||||
.RuleFor(plugin => plugin.Version, faker => faker.System.Semver())
|
||||
.RuleFor(plugin => plugin.Description, faker => faker.Lorem.Sentence())
|
||||
.RuleFor(plugin => plugin.LoadStatus, faker => faker.PickRandom<PluginLoadStatus>())
|
||||
.RuleFor(plugin => plugin.SettingsJson, faker => JsonSerializer.Serialize(new Dictionary<string, string> { [faker.Random.String2(1, 10)] = faker.Random.String2(1, 20) }))
|
||||
.RuleFor(plugin => plugin.CreatedOnUtc, faker => faker.Date.Past())
|
||||
.RuleFor(plugin => plugin.CreatedBy, faker => faker.Random.Guid())
|
||||
.RuleFor(plugin => plugin.UpdatedOnUtc, faker => faker.Date.Recent())
|
||||
.RuleFor(plugin => plugin.UpdatedBy, faker => faker.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
}
|
||||
+9
-21
@@ -4,6 +4,7 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -20,6 +21,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
{
|
||||
private readonly LuminaDbContext _mockContext;
|
||||
private readonly LibraryMetadataProviderConfigurationRepository _sut;
|
||||
private readonly LibraryMetadataProviderConfigurationEntityFixture _configurationFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryMetadataProviderConfigurationRepositoryTests"/> class.
|
||||
@@ -28,6 +30,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
{
|
||||
_mockContext = Create.MockedDbContextFor<LuminaDbContext>();
|
||||
_sut = new LibraryMetadataProviderConfigurationRepository(_mockContext);
|
||||
_configurationFixture = new LibraryMetadataProviderConfigurationEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -35,8 +38,8 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfLibrary = CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfAnotherLibrary = CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfLibrary = _configurationFixture.CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfAnotherLibrary = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.AddRange(configurationOfLibrary, configurationOfAnotherLibrary);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -53,7 +56,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task GetByLibraryAndPluginIdAsync_WhenConfigurationExists_ShouldReturnIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.Add(configuration);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -69,7 +72,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task UpsertAsync_WhenConfigurationDoesNotExist_ShouldInsertIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
|
||||
@@ -84,11 +87,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task UpsertAsync_WhenConfigurationExists_ShouldUpdateIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.Add(configuration);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity updatedConfiguration = CreateConfiguration(configuration.LibraryId, configuration.PluginId, 5);
|
||||
LibraryMetadataProviderConfigurationEntity updatedConfiguration = _configurationFixture.CreateConfiguration(configuration.LibraryId, configuration.PluginId, 5);
|
||||
updatedConfiguration.IsEnabled = true;
|
||||
|
||||
// Act
|
||||
@@ -101,19 +104,4 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
Assert.Equal(5, retrievedConfiguration.Rank);
|
||||
Assert.True(retrievedConfiguration.IsEnabled);
|
||||
}
|
||||
|
||||
private static LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
|
||||
{
|
||||
return new LibraryMetadataProviderConfigurationEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = libraryId,
|
||||
PluginId = pluginId,
|
||||
IsEnabled = false,
|
||||
Rank = rank,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
+8
-23
@@ -4,7 +4,7 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
@@ -22,6 +22,7 @@ public class PluginRepositoryTests
|
||||
{
|
||||
private readonly LuminaDbContext _mockContext;
|
||||
private readonly PluginRepository _sut;
|
||||
private readonly PluginEntityFixture _pluginFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginRepositoryTests"/> class.
|
||||
@@ -30,13 +31,14 @@ public class PluginRepositoryTests
|
||||
{
|
||||
_mockContext = Create.MockedDbContextFor<LuminaDbContext>();
|
||||
_sut = new PluginRepository(_mockContext);
|
||||
_pluginFixture = new PluginEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByIdAsync_WhenPluginExists_ShouldReturnIt()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -52,7 +54,7 @@ public class PluginRepositoryTests
|
||||
public async Task UpsertAsync_WhenPluginDoesNotExist_ShouldInsertIt()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
|
||||
@@ -67,12 +69,12 @@ public class PluginRepositoryTests
|
||||
public async Task UpsertAsync_WhenPluginExists_ShouldUpdateDetectionFieldsAndPreserveSettings()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
plugin.SettingsJson = """{"preferredLanguage":"en"}""";
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
PluginEntity updatedPlugin = CreatePluginEntity(plugin.Id);
|
||||
PluginEntity updatedPlugin = _pluginFixture.CreatePluginEntity(plugin.Id);
|
||||
updatedPlugin.Name = "Updated Name";
|
||||
updatedPlugin.SettingsJson = null; // the stored settings must be preserved
|
||||
|
||||
@@ -91,7 +93,7 @@ public class PluginRepositoryTests
|
||||
public async Task UpdateSettingsAsync_WhenPluginExists_ShouldUpdateItsSettings()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -114,21 +116,4 @@ public class PluginRepositoryTests
|
||||
Assert.True(result.IsError);
|
||||
Assert.Equal(Errors.Plugins.PluginNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
private static PluginEntity CreatePluginEntity(Guid? id = null)
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
Name = "Test Plugin",
|
||||
Author = "Lumina",
|
||||
Version = "1.0.0",
|
||||
Description = "A test plugin.",
|
||||
LoadStatus = PluginLoadStatus.Loaded,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = default,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user