Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Make it possible to moq concrete classes #1421

Closed
Thullner opened this issue Sep 10, 2023 · 1 comment
Closed

[Feature Request] Make it possible to moq concrete classes #1421

Thullner opened this issue Sep 10, 2023 · 1 comment
Labels

Comments

@Thullner
Copy link

Can concrete (and sealed) classes be made mockable (without virtual methods)? Because this would save a lot of frustrations with duplicate code, caused by useless interfaces.

@stakx stakx added the question label Sep 10, 2023
@stakx
Copy link
Contributor

stakx commented Sep 10, 2023

Concrete classes: perhaps. But otherwise, the answer is a definite no. Moq cannot create mocks for non-inheritable (e.g. sealed or static) types. And it cannot setup non-overridable (e.g. sealed, static or non-virtual) methods. As a general rule, if you could not do something manually, then Moq likely cannot do it either.

In fact, there are few mocking libraries that can do what you're asking for. TypeMock or JustMock are perhaps the best-known, I am not sure if there are any others. (Microsoft Fakes, perhaps?)

@stakx stakx closed this as completed Sep 10, 2023
@devlooped devlooped locked and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants