Hardens test assertions and adds missing test coverage.

This commit is contained in:
BinaryAlley committed 2026-08-18 08:28:16 -07:00
1 parent 6b86fd5805
commit 1189bbaf36
489 files changed
+39982 -512

No files matched your search

@@ -55,15 +55,15 @@ public class LibraryScanFailedDomainEventHandler : IDomainEventHandler<LibrarySc
public async ValueTask HandleAsync(LibraryScanFailedDomainEvent domainEvent, CancellationToken cancellationToken)
{
// get the library scan from the repository
Result<LibraryScanEntity?> getLibraryScansResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(
Result<LibraryScanEntity?> getLibraryScanResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(
domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsFailure)
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
if (getLibraryScansResult.Value is null)
if (getLibraryScanResult.IsFailure)
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
if (getLibraryScanResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository scan to a domain object
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
Result<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
@@ -1,17 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -50,8 +48,10 @@ public class LibraryScanQueuedDomainEventHandler : IDomainEventHandler<LibrarySc
{
// get the library scan that was queued, from the repository
Result<LibraryScanEntity?> getLibraryScanResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScanResult.IsFailure || getLibraryScanResult.Value is null)
if (getLibraryScanResult.IsFailure)
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
if (getLibraryScanResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository entity to a domain entity
Result<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
@@ -0,0 +1,19 @@
#region ========================================================================= USING =====================================================================================
using Dapper;
#endregion
namespace Lumina.DataAccess.Common.Dapper;
/// <summary>
/// Registers the Dapper type handlers used by the DataAccess layer.
/// </summary>
internal static class DapperTypeHandlers
{
/// <summary>
/// Registers all Dapper type handlers used by the DataAccess layer, and must run before any Dapper query executes.
/// </summary>
internal static void Register()
{
SqlMapper.AddTypeHandler(new SqliteGuidTypeHandler());
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Dapper;
using System;
using System.Data;
#endregion
namespace Lumina.DataAccess.Common.Dapper;
/// <summary>
/// Maps <see cref="Guid"/> values to and from the TEXT representation used by the SQLite provider.
/// </summary>
/// <remarks>
/// The SQLite provider stores <see cref="Guid"/> columns as TEXT, and Dapper falls back to Convert.ChangeType when materializing such
/// columns into <see cref="Guid"/> properties. <see cref="Guid"/> has no string <see cref="TypeConverter"/>, so that conversion throws
/// an <see cref="InvalidCastException"/>; this handler performs the conversion explicitly instead.
/// </remarks>
internal sealed class SqliteGuidTypeHandler : SqlMapper.TypeHandler<Guid>
{
/// <summary>
/// Sets the parameter value to the TEXT representation of the <see cref="Guid"/> value, keeping writes consistent with reads.
/// </summary>
/// <param name="parameter">The database parameter to set.</param>
/// <param name="value">The <see cref="Guid"/> value to store.</param>
public override void SetValue(IDbDataParameter parameter, Guid value)
{
parameter.Value = value.ToString();
}
/// <summary>
/// Parses the raw TEXT value read from the storage medium into a <see cref="Guid"/>.
/// </summary>
/// <param name="value">The raw value read from the storage medium.</param>
/// <returns>The parsed <see cref="Guid"/>.</returns>
public override Guid Parse(object value)
{
return value is Guid guid ? guid : Guid.Parse((string)value);
}
}
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Seed;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.DataAccess.Common.Dapper;
using Lumina.DataAccess.Common.Interceptors;
using Lumina.DataAccess.Core.Seed;
using Lumina.DataAccess.Core.UoW;
@@ -27,6 +28,9 @@ public static class DataAccessLayerServices
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static void AddDataAccessLayerServices(this IServiceCollection services)
{
// Type handlers are global static state, not DI services, and must be registered before any Dapper query executes;
// the composition root runs at startup, before any query, so this is the correct place for the application.
DapperTypeHandlers.Register();
string? basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!Directory.Exists(basePath))
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
+105
View File
@@ -232,6 +232,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Web.Int
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Web.SecurityTests", "..\tests\SecurityTests\Lumina.Presentation.Web.SecurityTests\Lumina.Presentation.Web.SecurityTests.csproj", "{3FE25467-CBC6-438F-BB96-6601AF56E937}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Contracts.UnitTests", "..\tests\UnitTests\Lumina.Contracts.UnitTests\Lumina.Contracts.UnitTests.csproj", "{8336763E-26CE-4598-8438-26C7FFD60A2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Domain.SharedKernel.UnitTests", "..\tests\UnitTests\Lumina.Domain.SharedKernel.UnitTests\Lumina.Domain.SharedKernel.UnitTests.csproj", "{B03AA3FE-4716-482C-8880-7BF3D9682A9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.Contracts.UnitTests", "..\tests\UnitTests\Lumina.Plugins.Contracts.UnitTests\Lumina.Plugins.Contracts.UnitTests.csproj", "{09F90296-A229-4CA2-8635-15B5893FE2EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.Contracts.Fixtures", "..\tests\Common\Lumina.Plugins.Contracts.Fixtures\Lumina.Plugins.Contracts.Fixtures.csproj", "{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.OpenLibrary.UnitTests", "..\tests\UnitTests\Lumina.Plugins.OpenLibrary.UnitTests\Lumina.Plugins.OpenLibrary.UnitTests.csproj", "{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.OpenLibrary.Fixtures", "..\tests\Common\Lumina.Plugins.OpenLibrary.Fixtures\Lumina.Plugins.OpenLibrary.Fixtures.csproj", "{16F65859-93AB-499F-A0BE-9EC05E20435F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.TestPlugin", "..\tests\Common\Lumina.TestPlugin\Lumina.TestPlugin.csproj", "{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -574,6 +588,90 @@ Global
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x64.Build.0 = Release|Any CPU
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x86.ActiveCfg = Release|Any CPU
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x86.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x64.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x64.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x86.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x86.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|Any CPU.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x64.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x64.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x86.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x86.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x64.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x86.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|Any CPU.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x64.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x64.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x86.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x86.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x64.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x64.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x86.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x86.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|Any CPU.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x64.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x64.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x86.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x86.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x64.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x64.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x86.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|Any CPU.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x64.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x64.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x86.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x86.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x64.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x64.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x86.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x86.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|Any CPU.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x64.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x64.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x86.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x86.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x64.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x64.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x86.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x86.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|Any CPU.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x64.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x64.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x86.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x86.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x64.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x64.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x86.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x86.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|Any CPU.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x64.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x64.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x86.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -631,6 +729,13 @@ Global
{697F6057-DBDC-40B9-A7E5-02F295BC18B3} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{4BE18EDC-02ED-47E2-A23A-3F6650ADAF0A} = {3F057926-562F-4EF4-BFC0-EE62372D4551}
{3FE25467-CBC6-438F-BB96-6601AF56E937} = {8B06B1D2-80B9-490C-9A36-C7748F58B705}
{8336763E-26CE-4598-8438-26C7FFD60A2E} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{B03AA3FE-4716-482C-8880-7BF3D9682A9F} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{09F90296-A229-4CA2-8635-15B5893FE2EA} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{16F65859-93AB-499F-A0BE-9EC05E20435F} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A55A28E-C657-4A0B-95EA-2931AE66004E}