test(azure-functions): replace NSubstitute with TUnit.Mocks in integration tests - #740
Conversation
…ation tests The feature collection was the last NSubstitute usage in the repository. It could not be migrated because `IInvocationFeatures.Get<T>()` was called on the interface type, where it resolves to the real method returning `T` and offers nothing to chain `.Returns()` onto (CS1061). Typing the parameter as `Mock<IInvocationFeatures>` routes the call through the generated mock instead. Bumps TUnit and TUnit.Mocks to 1.63.0, which is required rather than incidental: the middleware always calls `context.GetInvocationResult()`, which internally requests the internal Worker type `IFunctionBindingsFeature` via `Get<T>()`. Only from 1.63.0 on does the generated mock auto-stub a type argument this assembly cannot name; on 1.62.0 the call returns null and `GetRequired<T>()` throws "No feature is registered with the type ...". Removes the NSubstitute package reference and version entry. 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 #740 +/- ##
=======================================
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:
|
Summary
IInvocationFeaturesmock inNetEvolve.Http.Correlation.Azure.Functions.Tests.Integration— and drops the package entirely.TUnitandTUnit.Mocksto 1.63.0. This bump is part of the fix, not an incidental dependency update.Why it works now
Two separate blockers, both resolved:
SetupHttpRequestFeaturetook the feature collection asIInvocationFeatures. On the interface type,Get<T>()is the real method returningT, so there is nothing to chain.Returns()onto. Typing the parameter asMock<IInvocationFeatures>— matching the existingMock<FunctionContext>parameter — routes the call through the generated mock. Suggested by @thomhurst in [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.context.GetInvocationResult(), which internally requests theinternalWorker typeIFunctionBindingsFeatureviaGet<T>()— a type this assembly cannot name. Verified locally: on 1.62.0 that call returns null andGetRequired<T>()throwsInvalidOperationException: No feature is registered with the type Microsoft.Azure.Functions.Worker.Context.Features.IFunctionBindingsFeature. On 1.63.0 the generated mock auto-stubs it and the tests pass. Both conditions are required; either one alone fails.Both facts are recorded as comments in
TestBase.csso a future version pin or downgrade does not silently resurrect the failure.This supersedes the closed #738, which worked around the same problem with a hand-written
TestInvocationFeaturesplus aDispatchProxyfallback. Those two helper types are no longer needed.Test plan
dotnet test— 167/167 passing across net8.0/net9.0/net10.0Refs #723, thomhurst/TUnit#6514