Skip to content

Latest commit

 

History

History
54 lines (47 loc) · 9.1 KB

File metadata and controls

54 lines (47 loc) · 9.1 KB

Diagnostics / rules

ID Category Title Implementation File
Moq1000 Usage Sealed classes cannot be mocked NoSealedClassMocksAnalyzer.cs
Moq1001 Usage Mocked interfaces cannot have constructor parameters ConstructorArgumentsShouldMatchAnalyzer.cs
Moq1002 Usage Parameters provided into mock do not match any existing constructors ConstructorArgumentsShouldMatchAnalyzer.cs
Moq1003 Usage Internal type requires InternalsVisibleTo for DynamicProxy InternalTypeMustHaveInternalsVisibleToAnalyzer.cs
Moq1004 Usage ILogger should not be mocked NoMockOfLoggerAnalyzer.cs
Moq1100 Correctness Callback signature must match the signature of the mocked method CallbackSignatureShouldMatchMockedMethodAnalyzer.cs
Moq1101 Correctness SetupGet/SetupSet/SetupProperty should be used for properties, not for methods NoMethodsInPropertySetupAnalyzer.cs
Moq1200 Correctness Setup should be used only for overridable members SetupShouldBeUsedOnlyForOverridableMembersAnalyzer.cs
Moq1201 Correctness Setup of async methods should use .ReturnsAsync instance instead of .Result SetupShouldNotIncludeAsyncResultAnalyzer.cs
Moq1202 Correctness Raise event arguments should match the event delegate signature RaiseEventArgumentsShouldMatchEventSignatureAnalyzer.cs
Moq1203 Correctness Method setup should specify a return value MethodSetupShouldSpecifyReturnValueAnalyzer.cs
Moq1204 Correctness Raises event arguments should match event signature RaisesEventArgumentsShouldMatchEventSignatureAnalyzer.cs
Moq1205 Correctness Event setup handler type should match event delegate type EventSetupHandlerShouldMatchEventTypeAnalyzer.cs
Moq1206 Correctness Async method setups should use ReturnsAsync instead of Returns with async lambda ReturnsAsyncShouldBeUsedForAsyncMethodsAnalyzer.cs
Moq1207 Correctness SetupSequence should be used only for overridable members SetupSequenceShouldBeUsedOnlyForOverridableMembersAnalyzer.cs
Moq1208 Correctness Returns() delegate type mismatch on async method setup ReturnsDelegateShouldReturnTaskAnalyzer.cs
Moq1210 Correctness Verify should be used only for overridable members VerifyShouldBeUsedOnlyForOverridableMembersAnalyzer.cs
Moq1300 Usage Mock.As() should take interfaces only AsShouldBeUsedOnlyForInterfaceAnalyzer.cs
Moq1301 Usage Mock.Get() should not take literals MockGetShouldNotTakeLiteralsAnalyzer.cs
Moq1302 Usage LINQ to Mocks expression should be valid LinqToMocksExpressionShouldBeValidAnalyzer.cs
Moq1400 Best Practice Explicitly choose a mocking behavior instead of relying on the default (Loose) behavior SetExplicitMockBehaviorAnalyzer.cs
Moq1410 Best Practice Explicitly set the Strict mocking behavior SetStrictMockBehaviorAnalyzer.cs
Moq1420 Usage Redundant Times.AtLeastOnce() specification can be removed RedundantTimesSpecificationAnalyzer.cs
Moq1500 Best Practice MockRepository.Verify() should be called MockRepositoryVerifyAnalyzer.cs
Moq1600 Usage Protected setup should use ItExpr matchers ProtectedSetupShouldUseItExprAnalyzer.cs

Guidance for Future Rules

Categories

  • Usage: Rules that guide correct use of Moq APIs (e.g., not mocking sealed classes, correct use of As, etc.)
  • Correctness: Rules that prevent bugs or incorrect test logic (e.g., callback signatures, constructor arguments).
  • Best Practice: Rules that encourage maintainable, robust, or idiomatic Moq usage (e.g., explicit/strict behavior).

Diagnostic ID Ranges

Range Category Description / Example Rules
Moq1000-1099 Usage Prohibits sealed class mocks, restricts As to interfaces
Moq1100-1199 Correctness Ensures callback signatures match, setup is valid
Moq1200-1299 Correctness Prevents async result setups, checks constructor args
Moq1300-1399 Usage Restricts use of literals, enforces API usage patterns
Moq1400-1499 Best Practice Encourages explicit/strict mock behavior
Moq1500-1599 Best Practice Repository and verification patterns
Moq1600-1699 Usage Protected member setup and verification patterns
Moq1700-1999 Reserved Reserved for future rules
  • When adding new rules, assign the next available ID in the appropriate category range.
  • Document new rules in this table, including their category, a concise title, and links to both documentation and implementation.
  • For more, see the root README.md.