Summary
Replace NSubstitute with TUnit.Mocks as the mocking library used across the test suite.
We already use TUnit as the test framework across the test projects. NSubstitute is currently referenced in three test projects:
NetEvolve.Http.Correlation.Abstractions.Tests.Unit
NetEvolve.Http.Correlation.Azure.Functions.Tests.Unit
NetEvolve.Http.Correlation.Azure.Functions.Tests.Integration
and used in 2 files for creating mocks/substitutes:
TestBase.cs (Azure.Functions.Tests.Integration)
FunctionsWorkerApplicationBuilderExtensionsTests.cs (Azure.Functions.Tests.Unit)
Motivation / Benefits
- One framework instead of two:
TUnit.Mocks is part of the TUnit ecosystem we already depend on for the test runner, assertions, and data-driven tests. Consolidating removes a second, independently-versioned dependency (NSubstitute + Castle.Core).
- Source-generated mocks, no runtime proxying: NSubstitute relies on Castle DynamicProxy to generate proxy types at runtime via reflection/IL emission.
TUnit.Mocks generates mock implementations at compile time via a Roslyn source generator, giving faster test startup and compile-time errors instead of runtime failures.
- Full AOT/trimming compatibility.
- Smaller dependency surface: drops the transitive dependency on Castle.Core.
Scope
- Add
TUnit.Mocks package reference to the affected test project(s) listed above.
- Migrate the
Substitute.For<T>() usages in the 2 files above to the equivalent TUnit.Mocks API.
- Remove the
NSubstitute package reference from all three projects once migration is complete.
Reference
See dailydevops/healthchecks#2049 for the equivalent migration in that repository, including the rationale for this org-wide change.
Summary
Replace NSubstitute with
TUnit.Mocksas the mocking library used across the test suite.We already use TUnit as the test framework across the test projects. NSubstitute is currently referenced in three test projects:
NetEvolve.Http.Correlation.Abstractions.Tests.UnitNetEvolve.Http.Correlation.Azure.Functions.Tests.UnitNetEvolve.Http.Correlation.Azure.Functions.Tests.Integrationand used in 2 files for creating mocks/substitutes:
TestBase.cs(Azure.Functions.Tests.Integration)FunctionsWorkerApplicationBuilderExtensionsTests.cs(Azure.Functions.Tests.Unit)Motivation / Benefits
TUnit.Mocksis part of the TUnit ecosystem we already depend on for the test runner, assertions, and data-driven tests. Consolidating removes a second, independently-versioned dependency (NSubstitute + Castle.Core).TUnit.Mocksgenerates mock implementations at compile time via a Roslyn source generator, giving faster test startup and compile-time errors instead of runtime failures.Scope
TUnit.Mockspackage reference to the affected test project(s) listed above.Substitute.For<T>()usages in the 2 files above to the equivalentTUnit.MocksAPI.NSubstitutepackage reference from all three projects once migration is complete.Reference
See dailydevops/healthchecks#2049 for the equivalent migration in that repository, including the rationale for this org-wide change.