Skip to content

Add no-DB unit tests using pengdows.crud.fakeDb, reaching 92.1% Dapper.dll coverage - #2199

Open
alaricd wants to merge 1 commit into
DapperLib:mainfrom
pengdows:increase-unit-test-coverage
Open

Add no-DB unit tests using pengdows.crud.fakeDb, reaching 92.1% Dapper.dll coverage#2199
alaricd wants to merge 1 commit into
DapperLib:mainfrom
pengdows:increase-unit-test-coverage

Conversation

@alaricd

@alaricd alaricd commented Mar 22, 2026

Copy link
Copy Markdown

Introduces 859 pure unit tests that run without a live database connection,
using pengdows.crud.fakeDb v2.0.5 as a fake ADO.NET provider, alongside the
existing integration test suite.

Coverage (net8.0, this test set only), reproducible with:

dotnet-coverage collect --output coverage.xml --output-format cobertura \
  -- dotnet test tests/Dapper.Tests/Dapper.Tests.csproj -f net8.0 --filter "FullyQualifiedName~FakeDb"
reportgenerator -reports:coverage.xml -targetdir:covreport -reporttypes:TextSummary
  • Dapper.dll overall: 92.1%
  • SqlMapper.cs: 91.8%
  • CommandDefinition.cs, UdtTypeHandler.cs, SqlDataRecordHandler.cs, SqlDataRecordListTVPParameter.cs: 100%

Scope is limited to the fakeDb-based test substrate: no target-framework,
SDK, or unrelated dependency changes, and no production visibility changes.
(The PackListParameters/TypeHandler behavioral fix that was previously bundled
here has been split out to its own PR: #TBD.)

Key areas covered by new FakeDbTests.*.cs files:

  • All Query/Execute/QueryMultiple sync and async overloads
  • MultiMap (2–7 types), dynamic multimap, GridReader
  • DynamicParameters, TypeHandlers, TypeMapping, DefaultTypeMap
  • PassByPosition (?x? syntax), TryStringSplit (InListStringSplitCount), PadListExpansions, empty IN-list handling
  • Format() all TypeCode branches, ReplaceLiterals, ReadChar/ReadNullableChar
  • SanitizeParameterValue for all enum underlying types
  • CommandDefinition.GetInit() IL generation (BindByName, FetchSize, etc.)
  • StructuredHelper.ConfigureTVP/ConfigureUDT IL generation and cache
  • WrappedReader, WrappedBasicReader, DisposedReader, DbString, ValueTuples
  • Struct params, ctor-sort params, pipelined Execute, error paths

@alaricd

alaricd commented Mar 22, 2026

Copy link
Copy Markdown
Author

@mgravell — build is now green. 775 pure unit tests, no live database required, using pengdows.crud.fakeDb as a fake ADO.NET provider. Test-only dependency, zero production code changes. Happy to address any feedback.

@mgravell

Copy link
Copy Markdown
Member

this looks like a lot of useful work; there are currently merge conflicts - I can't resolve them without push access; can you either add external PR push access, or help me resolve them?

@alaricd

alaricd commented May 16, 2026

Copy link
Copy Markdown
Author

I will fix them

@alaricd

alaricd commented May 17, 2026

Copy link
Copy Markdown
Author

@mgravell all the merge conflicts are resolved.

@alaricd

alaricd commented Aug 23, 2026

Copy link
Copy Markdown
Author

@mgravell

Small correction to my earlier “zero production changes” statement: the added coverage exposed one real Dapper bug.

PackListParameters was calling LookupDbType(...) for expanded list parameters and receiving the registered ITypeHandler, but then discarding it and assigning each value through SanitizeParameterValue(...) instead.

The fix preserves the handler and calls handler.SetValue(...) for each expanded list item. This makes custom type handlers behave consistently between scalar parameters and IN @ids-style collection parameters.

I traced this path back to the August 5, 2015 commit that originally added type-map support for collection parameters; that implementation already retrieved the handler without using it. So this appears to be an approximately 11-year-old latent bug, not a recent regression.

The only other production-source change is changing DefaultTypeMap.GetSettableFields from private to internal for testability; its behavior is unchanged.

The new regression test specifically verifies that ITypeHandler.SetValue is invoked for every expanded collection element.

@alaricd alaricd changed the title Add no-DB unit tests using pengdows.crud.fakeDb, reaching 86% line coverage Add no-DB unit tests using pengdows.crud.fakeDb, reaching ~93% Dapper.dll coverage Aug 23, 2026
…r.dll coverage

Introduces 859 pure unit tests that run without a live database connection,
using pengdows.crud.fakeDb v2.0.5 as a fake ADO.NET provider, alongside the
existing integration test suite.

Coverage (net8.0, this test set only):
  dotnet-coverage collect --output coverage.xml --output-format cobertura \
    -- dotnet test tests/Dapper.Tests/Dapper.Tests.csproj -f net8.0 \
       --filter "FullyQualifiedName~FakeDb"
  reportgenerator -reports:coverage.xml -targetdir:covreport -reporttypes:TextSummary

  Dapper.dll overall: 92.1%
  Dapper.SqlMapper: 91.8%

Scope is intentionally limited to the fakeDb-based test substrate: no
target-framework, SDK, or unrelated dependency changes, and no production
visibility changes. DefaultTypeMap.GetSettableFields stays private; its
mapping behavior is exercised through the public Query<T> API instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGpTXegyVtX7cNR3vnuL1z
@alaricd
alaricd force-pushed the increase-unit-test-coverage branch from 5cdfe25 to 9efafaa Compare August 29, 2026 00:26
@alaricd alaricd changed the title Add no-DB unit tests using pengdows.crud.fakeDb, reaching ~93% Dapper.dll coverage Add no-DB unit tests using pengdows.crud.fakeDb, reaching 92.1% Dapper.dll coverage Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants