Skip to content

Consider Replacing Moq with NSubstitute #399

Description

@rvanmaanen

Context

All test projects currently use Moq for mocking. TechHubApiClient is intentionally non-sealed to support Moq's proxy generation. Moq had the SponsorLink controversy and requires non-sealed classes.

NSubstitute has a cleaner API and works directly with interfaces (no need for non-sealed classes).

Target State

Replace Moq with NSubstitute across all test projects.

Implementation

  1. Replace Moq package with NSubstitute in Directory.Packages.props
  2. Rewrite mock setups — API comparison:
MoqNSubstitute
var mock = new Mock<IFoo>();var sub = Substitute.For<IFoo>();
mock.Setup(x => x.Method()).Returns(val)sub.Method().Returns(val)
mock.Objectsub (used directly)
mock.Verify(x => x.Method(), Times.Once)sub.Received(1).Method()
  1. TechHubApiClient can be sealed once Moq is removed (tests mock the interface, not the class)

Notes

  • Large refactor — consider doing incrementally: new tests use NSubstitute, migrate old tests over time
  • Low urgency; only do when there's a natural opportunity

Priority

Low (non-urgent)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions