Moq.Analyzers is a Roslyn analyzer that helps to write unit tests using the popular and friend Moq library. Moq.Analyzers protects you from popular mistakes and warns you if something is wrong with your Moq configuration:
- Moq1000 = Sealed classes cannot be mocked.
- Moq1001 = Mocked interfaces cannot have constructor parameters.
- Moq1002 = Parameters provided into mock do not match any existing constructors.
- Moq1100 = Callback signature must match the signature of the mocked method.
- Moq1101 = SetupGet/SetupSet should be used for properties, not for methods.
- Moq1200 = Setup should be used only for overridable members.
- Moq1201 = Setup of async methods should use
.ReturnsAsync
instance instead of.Result
. - Moq1300 = Mock.As() should take interfaces.
Install "Moq.Analyzers" NuGet package into test projects using Moq.
Moq.Analyzers continues to evolve and add new features. Any help will be appreciated. You can report issues, develop new features, improve the documention, or do other cool stuff.
If you want to contribute to existing issues, check the help wanted or good first issue items in the backlog. If you have new ideas or want to complain about bugs, feel free to create a new issue.
This project has adopted the code of conduct defined by the Contributor Covenant to set expectations for behavior in our communication. For more information, see the .NET Foundation's Contributor Convenant Code of Conduct