Skip to content

Provide non-generic API to support runtime type mocking #887

@bclothier

Description

@bclothier

Normally, Moq uses generic APIs which is a great thing for ensure strong-typed, refactor-friendly mocking API. However, when the scenario is that we need to mock a runtime type, we can descend into a hell of Expressions trying to use the generic API.

The proposal is to open the non-generic methods as an API on an interface that is not easily accessible. In @stakx 's words:

Oh, I'd make sure that the low-level API is hidden and not something you'd casually stumble upon. Perhaps something similar to how .Protected() works; that is, you'd have to explicitly opt-into it via e.g.:

using Moq.Plumbing;

...
mock.DescendIntoDangerousPlumbingAPI()...

😆

The scenario for wanting to mock a runtime type is to provide support to other languages outside C#. In my case, it's VBA language and we have a prototype here which is for VBA language. The users would be able to write some mocks for the unit tests in VBA which would use Moq underneath.

While we could have made our own mocking framework, that would considerably enlarge our project's scope and we'd rather not have to get into whole journey of learning how to write a good mocking framework but rather ride the coattails of the developers who already invested so much into building an excellent mocking so that we can only focus on providing an effective implementation in our project.

Back this issue
Back this issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions