Skip to content

Replace NSubstitute with TUnit.Mocks #574

Description

@samtrion

Summary

Replace NSubstitute with TUnit.Mocks as the mocking library used in NetEvolve.Extensions.Hosting.WinForms.Tests.Unit.

We already use TUnit as the test framework across the test projects. NSubstitute is currently referenced only in NetEvolve.Extensions.Hosting.WinForms.Tests.Unit and used in 1 file for creating mocks/substitutes:

  • IHostBuilderExtensionsTests.cs

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 tests/NetEvolve.Extensions.Hosting.WinForms.Tests.Unit/NetEvolve.Extensions.Hosting.WinForms.Tests.Unit.csproj.
  • Migrate the Substitute.For<T>() usage in IHostBuilderExtensionsTests.cs to the equivalent TUnit.Mocks API.
  • Remove the NSubstitute package reference once migration is complete.

Reference

See dailydevops/healthchecks#2049 for the equivalent migration in that repository, including the rationale for this org-wide change.

Metadata

Metadata

Assignees

Labels

type:techdebtIndicates an issue or pull request that address technical debt.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions