chore(tests): replace NSubstitute with a DispatchProxy-based workaround - #738
chore(tests): replace NSubstitute with a DispatchProxy-based workaround#738samtrion wants to merge 1 commit into
Conversation
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
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Found the clean solution |
Summary
NetEvolve.Http.Correlation.Azure.Functions.Tests.Integration.TUnitandTUnit.Mocksto 1.63.0.TUnit.Mocks.TUnit.Mocksis 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 typeIFunctionBindingsFeature, which the SDK requests internally viaFunctionContext.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.TestInvocationFeatures, a small hand-writtenIInvocationFeatures, falls back toDispatchProxy.Create<T, NullReturningProxy>()for any unregistered interfaceT. SinceDispatchProxy.Createis invoked withTas 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, includingNetEvolve.Http.Correlation.Azure.Functions.Tests.Integrationon net8.0/net9.0/net10.0Refs #723, thomhurst/TUnit#6514