From 15abd049dba4d26378546aaae821991d1eec8066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonatan=20Uusv=C3=A4li?= Date: Sat, 10 Oct 2026 17:34:58 +0300 Subject: [PATCH] Add test pinning RegisterUlid's Nullable handler registration --- .../DapperUlidTypeHandlerRegistrationTests.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Dapper.IntegrationTests/DapperUlidTypeHandlerRegistrationTests.cs diff --git a/src/Dapper.IntegrationTests/DapperUlidTypeHandlerRegistrationTests.cs b/src/Dapper.IntegrationTests/DapperUlidTypeHandlerRegistrationTests.cs new file mode 100644 index 0000000..21d5935 --- /dev/null +++ b/src/Dapper.IntegrationTests/DapperUlidTypeHandlerRegistrationTests.cs @@ -0,0 +1,43 @@ +using Microsoft.Data.Sqlite; +using Dapper; + +namespace ByteAether.Ulid.Dapper.IntegrationTests; + +public class DapperUlidTypeHandlerRegistrationTests : IDisposable +{ + private readonly SqliteConnection _connection; + + public DapperUlidTypeHandlerRegistrationTests() + { + _connection = new("Data Source=:memory:"); + _connection.Open(); + } + + [Fact] + public async Task RegisterUlid_ShouldRegisterHandler_ForNullableUlidParametersAndResults() + { + // Arrange + SqlMapper.ResetTypeHandlers(); + DapperUlid.RegisterUlid(UlidStorageFormat.String); + + Ulid? value = Ulid.New(); + + // Act - A bare scalar query exercises Dapper's parameter-building and result-materialization + // pipeline directly against a `Ulid?`-typed parameter/result, without going through an entity + // or a table. This pins that `RegisterUlid` makes `Nullable` resolve to the same + // type handler as `Ulid`, instead of relying on incidental coverage from the broader + // entity round-trip tests. + var roundTripped = await _connection.ExecuteScalarAsync("SELECT @Value AS Value", new { Value = value }); + var roundTrippedNull = await _connection.ExecuteScalarAsync("SELECT @Value AS Value", new { Value = (Ulid?)null }); + + // Assert + Assert.Equal(value, roundTripped); + Assert.Null(roundTrippedNull); + } + + public void Dispose() + { + _connection.Dispose(); + GC.SuppressFinalize(this); + } +}