Skip to content

chore: Migrate NSubstitute to TUnit.Mocks in Tests.Unit - #563

Merged
samtrion merged 2 commits into
mainfrom
feature/tunit-mocks-migration
Jul 29, 2026
Merged

chore: Migrate NSubstitute to TUnit.Mocks in Tests.Unit#563
samtrion merged 2 commits into
mainfrom
feature/tunit-mocks-migration

Conversation

@samtrion

@samtrion samtrion commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Migrates IDataReaderExtensionsTests.cs and IDataRecordExtensionsTests.cs in NetEvolve.Extensions.Data.Tests.Unit from NSubstitute to TUnit.Mocks, consolidating onto the TUnit ecosystem already used as this project's test framework.
  • Closes Replace NSubstitute with TUnit.Mocks #555.

Scoped exception

DbDataReaderExtensionsTests.cs stays on NSubstitute. TUnit.Mocks 1.62.0 (currently the latest) generates a mock implementation for DbDataReader that fails to compile:

error CS0205: Cannot call an abstract base member: 'DbDataReader.this[int]'
error CS0205: Cannot call an abstract base member: 'DbDataReader.this[string]'

DbDataReader's indexers are abstract with no base implementation, so the generator's strategy of forwarding to base[...] doesn't compile. This is a source-generator limitation, not something fixable from test code — confirmed with a minimal, standalone repro, filed upstream as thomhurst/TUnit#6516. The NSubstitute package reference and comment in the csproj document this as a scoped, removable exception (linking that issue), mirroring the approach taken for similar generator limitations in dailydevops/healthchecks#2049 / #2051.

Also removes the unused NSubstitute package reference from NetEvolve.Extensions.Data.Tests.PublicApi.csproj (dead reference, no file in that project used it).

Test plan

  • dotnet build (whole solution, all TFMs) — 0 warnings, 0 errors
  • dotnet test for NetEvolve.Extensions.Data.Tests.Unit across net8.0/net9.0/net10.0 — 921/921 passed
  • Verified the migrated IDataRecordExtensionsTests.CreateTestRecord() helper's overlapping matcher setups (Any<int>() general fallback + exact-value/predicate overrides) preserve NSubstitute's "later matching setup wins" semantics — all edge-case theory tests (index 0, 1, negative) pass

🤖 Generated with Claude Code

Migrates IDataReaderExtensionsTests.cs and IDataRecordExtensionsTests.cs
to TUnit.Mocks, consolidating onto the TUnit ecosystem already used as
the test framework.

DbDataReaderExtensionsTests.cs stays on NSubstitute: TUnit.Mocks 1.62.0's
source generator emits CS0205 ("Cannot call an abstract base member")
when mocking DbDataReader, because its abstract this[int]/this[string]
indexers have no base implementation to forward to. This mirrors the
scoped-exception approach taken in dailydevops/healthchecks#2049 for
similar upstream generator limitations.

Also drops the unused NSubstitute reference from
NetEvolve.Extensions.Data.Tests.PublicApi.csproj.

Closes #555

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • state:ready for merge

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b781a50-bf33-45de-89b8-f68adfef0d1a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ception

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@samtrion samtrion changed the title Migrate NSubstitute to TUnit.Mocks in Tests.Unit chore: Migrate NSubstitute to TUnit.Mocks in Tests.Unit Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7376d84) to head (3a10fc9).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #563   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          114       114           
  Branches        28        28           
=========================================
  Hits           114       114           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtrion
samtrion merged commit 3852696 into main Jul 29, 2026
15 checks passed
@samtrion
samtrion deleted the feature/tunit-mocks-migration branch July 29, 2026 22:03
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.

Replace NSubstitute with TUnit.Mocks

1 participant