Skip to content

rjmurillo/moq.analyzers

Folders and files

NameName
Last commit message
Last commit date
Feb 10, 2025
Jan 30, 2025
Feb 25, 2025
Jan 22, 2025
Feb 4, 2025
Feb 4, 2025
Dec 19, 2024
Jun 3, 2024
Oct 22, 2024
Oct 8, 2024
Jul 14, 2024
Jun 10, 2024
Aug 29, 2024
Aug 1, 2024
Jun 6, 2024
Jun 6, 2024
Feb 20, 2025
Oct 8, 2024
Jul 14, 2024
Feb 4, 2025
Jul 14, 2024
Jun 25, 2024
Jan 22, 2025
Jan 13, 2025
Jun 25, 2024
Dec 25, 2024

Moq.Analyzers

NuGet Version NuGet Downloads Main build Codacy Grade Badge Codacy Coverage Badge

Moq.Analyzers is a Roslyn analyzer that helps you to write unit tests using the popular Moq framework. Moq.Analyzers protects you from common mistakes and warns you if something is wrong with your Moq configuration.

Analyzer rules

  • 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
  • Moq1400: Explicitly choose a mocking behavior instead of relying on the default (Loose) behavior
  • Moq1410: Explicitly set the Strict mocking behavior

See docs/rules for full documentation.

Getting started

Moq.Analyzers is installed from NuGet. Run this command for your test project(s):

dotnet add package Moq.Analyzers

NOTE: You must use a supported version of the .NET SDK (i.e. 6.0 or later).

Configuring rules

Moq.Analyzers follows existing conventions for enabling, disabling, or suppressing rules. See Suppress code analysis warnings - .NET | Microsoft Learn for documentation on how to configure rules for your project.

Contributions welcome

Moq.Analyzers continues to evolve and add new features. Any help will be appreciated. You can report issues, develop new features, improve the documentation, or do other cool stuff. See CONTRIBUTING.md.