Skip to content

chore(tests): replace NSubstitute with a DispatchProxy-based workaround - #738

Closed
samtrion wants to merge 1 commit into
mainfrom
chore/replace-nsubstitute-with-dispatchproxy
Closed

chore(tests): replace NSubstitute with a DispatchProxy-based workaround#738
samtrion wants to merge 1 commit into
mainfrom
chore/replace-nsubstitute-with-dispatchproxy

Conversation

@samtrion

Copy link
Copy Markdown
Contributor

Summary

  • Removes the NSubstitute dependency from NetEvolve.Http.Correlation.Azure.Functions.Tests.Integration.
  • Bumps TUnit and TUnit.Mocks to 1.63.0.
  • This is a workaround, not a full migration to TUnit.Mocks. TUnit.Mocks is a compile-time source generator, so it cannot configure a mock's generic method for a type argument this assembly can't name — in this case the internal Azure Functions Worker type IFunctionBindingsFeature, which the SDK requests internally via FunctionContext.GetInvocationResult(). See [TUnit.Mocks] Get<T>() can't be configured for T inaccessible to the calling assembly (unlike NSubstitute's runtime-proxy auto-recursion) thomhurst/TUnit#6514 for the upstream discussion; confirmed against 1.63.0 that the gap still exists.
  • The workaround: TestInvocationFeatures, a small hand-written IInvocationFeatures, falls back to DispatchProxy.Create<T, NullReturningProxy>() for any unregistered interface T. Since DispatchProxy.Create is invoked with T as a generic parameter resolved at the call site via reflection, it works even for types this assembly has no visibility into.

Test plan

  • dotnet test — 167/167 passing, including NetEvolve.Http.Correlation.Azure.Functions.Tests.Integration on net8.0/net9.0/net10.0

Refs #723, thomhurst/TUnit#6514

TUnit.Mocks 1.63.0 still can't intercept an unconfigured Get<T>() call
for a T this assembly cannot name (thomhurst/TUnit#6514). This is a
workaround, not a full migration: a hand-written IInvocationFeatures
falls back to DispatchProxy.Create<T, NullReturningProxy>() for any
unregistered interface T, which resolves purely from the runtime Type
object and works even for internal SDK types. Also bumps TUnit and
TUnit.Mocks to 1.63.0.

Refs #723, thomhurst/TUnit#6514
@samtrion
samtrion requested a review from a team as a code owner July 30, 2026 18:35
@samtrion
samtrion requested review from benwirren and removed request for a team July 30, 2026 18:35
@coderabbitai

coderabbitai Bot commented Jul 30, 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: 7c514197-3968-493a-8f8b-f686c04762e4

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.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.71%. Comparing base (1e56c99) to head (5756406).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #738   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files          20       20           
  Lines         175      175           
  Branches       22       22           
=======================================
  Hits          171      171           
  Misses          2        2           
  Partials        2        2           

☔ 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

Copy link
Copy Markdown
Contributor Author

Found the clean solution

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.

1 participant