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

@@ -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.");