Skip to content

test(Moq1302): comprehensive coverage for false positive fix (#1010)#1020

Merged
rjmurillo merged 1 commit intomainfrom
test/moq1302-comprehensive-coverage
Mar 7, 2026
Merged

test(Moq1302): comprehensive coverage for false positive fix (#1010)#1020
rjmurillo merged 1 commit intomainfrom
test/moq1302-comprehensive-coverage

Conversation

@rjmurillo
Copy link
Copy Markdown
Owner

@rjmurillo rjmurillo commented Mar 7, 2026

Summary

Adds 10 new test scenarios for Moq1302 (LinqToMocksExpressionShouldBeValid) to ensure the IsRootedInLambdaParameter guard from PR #1017 handles every common customer pattern. These tests run against both Moq 4.8.2 and 4.18.4.

New test scenarios

False positive prevention (should NOT flag):

  • Exact reporter pattern: nested Mock.Of inside method argument (False positive in Moq1302: Invalid member 'StatusCodes.Status202Accepted' in LINQ to Mocks expression  #1010)
  • static lambda with external constant (reporter's exact syntax)
  • Captured local variable as comparison value
  • Method parameter as comparison value
  • Instance field (this member) as comparison value
  • Inequality operator (!=) with external constant
  • Chained external instance property (multi-hop: settings.Service.DefaultName)
  • String concatenation on right side (Prefix.Value + "-default")
  • || with all external constants

True positive preservation (SHOULD flag):

  • Non-virtual method with external arguments still flagged

Test results

  • Before: 144 Moq1302 tests
  • After: 164 Moq1302 tests (+20, each runs against 2 Moq versions)
  • Full suite: 2892 tests, 0 failures

Test plan

  • All 164 Moq1302 tests pass
  • Full suite (2892 tests) passes
  • Build: 0 warnings, 0 errors

Closes #1010

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded test coverage with comprehensive scenarios for analyzer validation, including edge cases with external variables, method parameters, instance fields, static lambdas, chained properties, and comparison operations to improve reliability across complex patterns.

Add 10 new test scenarios covering real-world patterns that triggered
false positives in Moq1302 (LinqToMocksExpressionShouldBeValid):

- Exact reporter pattern: nested Mock.Of inside method argument
- Static lambda with external constant
- Captured local variable as comparison value
- Method parameter as comparison value
- Instance field (this member) as comparison value
- Inequality operators (!=) with external constants
- Chained external instance property (multi-hop)
- Non-virtual method with external arguments (true positive)
- String concatenation on right side of comparison
- || with all external constants (no false positives)

These complement the existing 22 tests from PR #1017 to ensure the
IsRootedInLambdaParameter guard handles every common customer pattern.

Closes #1010

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 7, 2026 06:50
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the test coverage for the Moq1302 analyzer, specifically targeting a fix for false positives introduced in a previous change. By adding a comprehensive set of new test cases, it validates that the analyzer accurately distinguishes between valid and invalid Moq expressions involving external constants, captured variables, and complex lambda structures, thereby improving the analyzer's reliability and preventing regressions.

Highlights

  • Enhanced Moq1302 Test Coverage: Added 10 new test scenarios for the LinqToMocksExpressionShouldBeValid analyzer (Moq1302) to ensure the IsRootedInLambdaParameter guard from PR fix: filter non-lambda-rooted members in Moq1302 to eliminate false positives #1017 correctly handles various customer patterns.
  • False Positive Prevention: Included new tests to prevent false positives for scenarios such as nested Mock.Of in method arguments, static lambdas with external constants, captured local variables, method parameters, instance fields, inequality operators, chained external instance properties, string concatenation on the right side, and || comparisons with all external constants.
  • True Positive Preservation: Ensured true positive preservation by adding a test case for non-virtual methods with external arguments, which should still be flagged by the analyzer.
  • Multi-Version Moq Testing: Confirmed that all new test cases run against both Moq 4.8.2 and 4.18.4 to ensure broad compatibility.
Changelog
  • tests/Moq.Analyzers.Test/LinqToMocksExpressionShouldBeValidAnalyzerTests.cs
    • Added ShouldNotFlagExactReporterScenarioNestedMockOfInMethodArg test case.
    • Added ShouldNotFlagStaticLambdaWithExternalConstant test case.
    • Added ShouldNotFlagCapturedLocalVariableAsComparisonValue test case.
    • Added ShouldNotFlagMethodParameterAsComparisonValue test case.
    • Added ShouldNotFlagInstanceFieldAsComparisonValue test case.
    • Added ShouldNotFlagInequalityComparisonWithExternalConstant test case.
    • Added ShouldNotFlagChainedExternalInstanceProperty test case.
    • Added ShouldFlagNonVirtualMethodWithExternalArguments test case.
    • Added ShouldNotFlagStringConcatenationOnRightSide test case.
    • Added ShouldNotFlagOrComparisonWithAllExternalConstants test case.
Activity
  • Added 10 new test scenarios for the Moq1302 analyzer, increasing the total Moq1302 tests from 144 to 164.
  • Verified that all 164 Moq1302 tests pass.
  • Confirmed that the full test suite of 2892 tests passes without failures.
  • Ensured the build completes with 0 warnings and 0 errors.
  • The pull request was generated using Claude Code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f46fdd21-2a80-49c2-aaf7-a7b109073d98

📥 Commits

Reviewing files that changed from the base of the PR and between 4b705e2 and 3e86e5d.

📒 Files selected for processing (1)
  • tests/Moq.Analyzers.Test/LinqToMocksExpressionShouldBeValidAnalyzerTests.cs

📝 Walkthrough

Walkthrough

This pull request adds ten new test cases to the LinqToMocksExpressionShouldBeValidAnalyzerTests class, expanding coverage for edge cases involving external constants, method parameters, instance fields, captured locals, and other non-parameter roots in LINQ to Mocks expressions.

Changes

Cohort / File(s) Summary
Test Coverage Expansion
tests/Moq.Analyzers.Test/LinqToMocksExpressionShouldBeValidAnalyzerTests.cs
Added ten Theory-based test methods covering scenarios where external constants, static lambdas, captured variables, method parameters, instance fields, and chained properties are used in Mock.Of expressions without triggering false-positive Moq1302 warnings. Includes validation for string concatenation, inequality comparisons, and OR expressions with external constants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #1017: Fixes the same analyzer behavior for false-positive cases around lambda-rooted member detection that these new tests validate.
  • PR #635: Adds edge-case unit tests to the same analyzer test suite for LINQ-to-Mocks expressions.

Suggested labels

analyzers, housekeeping, releasable

Suggested reviewers

  • MattKotsenas
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding comprehensive test coverage for the Moq1302 false positive fix, directly referencing the issue number #1010.
Linked Issues check ✅ Passed The PR adds 10 new test scenarios that comprehensively validate the Moq1302 analyzer correctly handles external constants and lambda parameters, directly addressing the false positive reported in issue #1010.
Out of Scope Changes check ✅ Passed All changes are within scope: 10 new test methods were added to verify the Moq1302 false positive fix handles various customer patterns, with no modifications to production code or unrelated test logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/moq1302-comprehensive-coverage

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io bot commented Mar 7, 2026

DeepSource Code Review

We reviewed changes in 4b705e2...3e86e5d on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade  

Focus Area: Hygiene
Security  

Reliability  

Complexity  

Hygiene  

Feedback

  • Missing Async suffix across many test methods
    • Task-returning tests repeatedly omit the Async suffix because tests were created or copied without following the naming convention; enforce a naming rule and apply a bulk rename/code-fix to stop future churn.
  • Analyzer flags but not enforced or auto-fixed
    • The analyzer reports the issue but is treated as a soft warning and lacks an automated fix; promote the rule to error in .editorconfig/CSProj and add a Roslyn CodeFix or “fix all” step to convert warnings into immediate, fixable failures.
  • Test scaffolding/templates propagate the problem
    • Generated test methods and templates produce nonconforming names, causing repeated occurrences; update templates/generators to append Async and include the naming rule in project templates so new code conforms by default.

Code Review Summary

Analyzer Status Updated (UTC) Details
C# Mar 7, 2026 6:50a.m. Review ↗

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds excellent, comprehensive test coverage for the Moq1302 false positive fix. The new scenarios cover a wide range of common patterns, which significantly strengthens the analyzer's robustness. My review includes one suggestion to consolidate a few similar tests to improve maintainability by reducing boilerplate code, with an added note to consider potential downsides of such refactoring in test files.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands the Moq1302 (LinqToMocksExpressionShouldBeValid) analyzer test suite to prevent regressions of the #1010 false-positive scenario by adding coverage for common “external member/constant” patterns, running each scenario against both supported Moq versions.

Changes:

  • Added 9 new “should not flag” regression tests covering external constants/values in various binary-expression shapes (static lambdas, captured locals, chained property access, !=, ||, string concatenation, nested Mock.Of in method args).
  • Added 1 new “should flag” regression test to ensure true positives remain (non-virtual method invocation rooted in the lambda parameter, even with external arguments).

@codacy-production
Copy link
Copy Markdown

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) (target: 95.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4b705e2) 2432 2175 89.43%
Head commit (3e86e5d) 2432 (+0) 2175 (+0) 89.43% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1020) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@rjmurillo
Copy link
Copy Markdown
Owner Author

Response to Gemini Review Thread

Re: suggestion to consolidate three tests into a single data-driven Theory.

These tests are intentionally separate rather than data-driven. Each exercises a distinct IOperation code path:

  1. ShouldNotFlagStaticLambdaWithExternalConstant - Tests static lambda syntax (different capture semantics)
  2. ShouldNotFlagInequalityComparisonWithExternalConstant - Tests the != operator (different IBinaryOperation kind)
  3. ShouldNotFlagOrComparisonWithAllExternalConstants - Tests || with interface members, exercising the IBinaryOperation decomposition path in AnalyzeLambdaBody

Consolidating them into a shared template would obscure which IOperation path is under test and make failures harder to diagnose.

@coderabbitai coderabbitai bot added housekeeping analyzers Change that impacts an analyzer behavior labels Mar 7, 2026
@rjmurillo rjmurillo merged commit 3399297 into main Mar 7, 2026
46 of 47 checks passed
@rjmurillo rjmurillo deleted the test/moq1302-comprehensive-coverage branch March 7, 2026 18:06
@rjmurillo rjmurillo added this to the vNext milestone Mar 7, 2026
rjmurillo added a commit that referenced this pull request Mar 7, 2026
…1020)

## Summary

Adds 10 new test scenarios for Moq1302
(`LinqToMocksExpressionShouldBeValid`) to ensure the
`IsRootedInLambdaParameter` guard from PR #1017 handles every common
customer pattern. These tests run against both Moq 4.8.2 and 4.18.4.

### New test scenarios

**False positive prevention (should NOT flag):**
- Exact reporter pattern: nested `Mock.Of` inside method argument
(#1010)
- `static` lambda with external constant (reporter's exact syntax)
- Captured local variable as comparison value
- Method parameter as comparison value
- Instance field (`this` member) as comparison value
- Inequality operator (`!=`) with external constant
- Chained external instance property (multi-hop:
`settings.Service.DefaultName`)
- String concatenation on right side (`Prefix.Value + "-default"`)
- `||` with all external constants

**True positive preservation (SHOULD flag):**
- Non-virtual method with external arguments still flagged

### Test results

- **Before**: 144 Moq1302 tests
- **After**: 164 Moq1302 tests (+20, each runs against 2 Moq versions)
- **Full suite**: 2892 tests, 0 failures

## Test plan

- [x] All 164 Moq1302 tests pass
- [x] Full suite (2892 tests) passes
- [x] Build: 0 warnings, 0 errors

Closes #1010

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Expanded test coverage with comprehensive scenarios for analyzer
validation, including edge cases with external variables, method
parameters, instance fields, static lambdas, chained properties, and
comparison operations to improve reliability across complex patterns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Richard Murillo <rjmurillo@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analyzers Change that impacts an analyzer behavior housekeeping releasable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive in Moq1302: Invalid member 'StatusCodes.Status202Accepted' in LINQ to Mocks expression

2 participants