Skip to content

test: add Moq1203 semantic variation tests for variable mocks and custom types#905

Merged
rjmurillo merged 1 commit intomainfrom
test/moq1203-semantic-variations
Feb 19, 2026
Merged

test: add Moq1203 semantic variation tests for variable mocks and custom types#905
rjmurillo merged 1 commit intomainfrom
test/moq1203-semantic-variations

Conversation

@rjmurillo
Copy link
Copy Markdown
Owner

@rjmurillo rjmurillo commented Feb 18, 2026

Summary

  • Add 50 new test permutations for Moq1203 covering variable-based mock construction, MockBehavior parameters, variable arguments, and callback chains
  • Add custom record type reproduction tests matching the exact pattern from issue Incorrect detection/flagging of rule Moq1203 after upgrading to v0.4.0 #849 (Task<MyValue> with ReturnsAsync)
  • Existing tests only exercised inline new Mock<IFoo>() with primitive Task<int> and literal arguments, which 100% line/branch coverage could not distinguish from the failing pattern

Test plan

Refs: #849, #904

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for Moq setup analysis scenarios, including semantic variations, custom return types, and callback configurations across multiple reference assembly groups.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @rjmurillo, 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 suite for the Moq1203 analyzer, ensuring its robustness across a wider range of Moq usage patterns. The added tests cover complex scenarios like variable-based mock setups and custom return types, which were previously not fully validated. This expansion aims to prevent regressions and improve the accuracy of the analyzer's diagnostics for common Moq configurations.

Highlights

  • Expanded Moq1203 Test Coverage: Added 50 new test permutations for the Moq1203 analyzer, specifically targeting variable-based mock construction, MockBehavior parameters, variable arguments, and callback chains. This ensures the analyzer correctly identifies issues in more complex and varied usage patterns.
  • Custom Type Reproduction Tests: Included new tests that reproduce the exact pattern from issue Incorrect detection/flagging of rule Moq1203 after upgrading to v0.4.0 #849, involving Task<MyValue> with ReturnsAsync. These tests confirm that the analyzer correctly handles custom record types, preventing false positives or missed diagnostics.
  • Improved Analyzer Robustness: The new tests address scenarios where existing 100% line/branch coverage might not have distinguished failing patterns from inline literal arguments and primitive types, thereby enhancing the analyzer's reliability across diverse code structures.
Changelog
  • tests/Moq.Analyzers.Test/MethodSetupShouldSpecifyReturnValueAnalyzerTests.cs
    • Added VariableBasedSetupTestData method to introduce new test cases for Moq1203, covering variable mock construction, MockBehavior parameters, variable arguments, and callback chains.
    • Introduced VariableBasedCallbackOnlyTestData method for specific callback-only setups on variable mocks, expecting diagnostics.
    • Implemented ShouldAnalyzeVariableBasedMockSetups test method to run the new variable-based setup test data.
    • Added ShouldFlagVariableBasedCallbackOnlySetup test method to validate callback-only setups.
    • Created ShouldNotFlagSetupWithCustomReturnType test method to verify the analyzer correctly handles ReturnsAsync with custom record types, addressing issue Incorrect detection/flagging of rule Moq1203 after upgrading to v0.4.0 #849.
    • Included ShouldFlagSetupWithCustomReturnTypeMissingReturnValue test method to ensure Moq1203 flags missing return values for custom types.
Activity
  • The pull request author, rjmurillo, created this PR to add comprehensive test coverage for the Moq1203 analyzer, addressing semantic variations and a specific issue related to custom types.
  • The PR description includes a detailed summary of changes and a test plan, indicating that all new tests pass and the custom-type fix for Incorrect detection/flagging of rule Moq1203 after upgrading to v0.4.0 #849 is confirmed.
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 Feb 18, 2026

📝 Walkthrough

Walkthrough

Added comprehensive test data and test methods to the MethodSetupShouldSpecifyReturnValueAnalyzerTests to validate the analyzer's behavior with semantic variations in Moq setups and custom return types, including scenarios with variable mocks, MockBehavior parameters, and custom record types.

Changes

Cohort / File(s) Summary
Test Coverage Expansion
tests/Moq.Analyzers.Test/MethodSetupShouldSpecifyReturnValueAnalyzerTests.cs
Added test data for semantic variations (SemanticVariationSetupTestData, SemanticVariationSetupWithDiagnosticTestData), custom return types (CustomReturnTypeTestData, CustomReturnTypeMissingReturnValueTestData), helper methods (BuildCustomSource, VerifyCustomSourceMockAsync), and four new test methods covering scenarios with variable mocks, custom record return types, and callback-only setups.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

housekeeping, analyzers

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 semantic variation tests for Moq1203 with focus on variable mocks and custom types, matching the substantial test additions in the changeset.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/moq1203-semantic-variations

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

@coderabbitai coderabbitai bot requested a review from MattKotsenas February 18, 2026 16:35
@deepsource-io
Copy link
Copy Markdown

deepsource-io bot commented Feb 18, 2026

DeepSource Code Review

DeepSource reviewed changes in the commit range bae5141..46e17b2 on this pull request. Below is the summary for the review, and you can see the individual issues we found as review comments.

For detailed review results, please see the PR on DeepSource ↗

PR Report Card

Security × 0 issues Overall PR Quality   

Focus Area: Hygiene

Guidance
4 high-severity naming convention violations for `Task` return type in `tests/Moq.Analyzers.Test/MethodSetupShouldSpecifyReturnValueAnalyzerTests.cs`.
Reliability × 0 issues
Complexity × 0 issues
Hygiene × 4 issues

Code Review Summary

Analyzer Status Summary Details
C# 4 new issues detected. Review ↗
How are these analyzer statuses calculated?

Administrators can configure which issue categories are reported and cause analysis to be marked as failed when detected. This helps prevent bad and insecure code from being introduced in the codebase. If you're an administrator, you can modify this in the repository's settings.

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 introduces new test cases for the Moq1203 analyzer, covering variable-based mock construction, MockBehavior parameters, variable arguments, callback chains, and custom record types. The changes aim to improve the analyzer's ability to detect missing return value specifications in various scenarios. The existing review comment addresses a potential issue and has been retained.

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Feb 18, 2026

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 (bae5141) 2049 1825 89.07%
Head commit (46e17b2) 2049 (+0) 1825 (+0) 89.07% (+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 (#905) 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 rjmurillo force-pushed the test/moq1203-semantic-variations branch from fbecc1d to 85a99fe Compare February 18, 2026 16:42
@rjmurillo rjmurillo changed the title Add Moq1203 semantic variation tests for variable mocks and custom types test: add Moq1203 semantic variation tests for variable mocks and custom types Feb 18, 2026
@rjmurillo rjmurillo force-pushed the test/moq1203-semantic-variations branch 2 times, most recently from ba2f064 to 6040d3c Compare February 18, 2026 17:16
…tom types

Existing Moq1203 tests exercised a single semantic profile: inline
new Mock<IFoo>(), primitive Task<int>, and literal arguments. Line/branch
coverage at 100% could not detect this gap because the analyzer traverses
identical code paths regardless of mock construction form or return type.

Add variable-based mock tests (variable construction, MockBehavior params,
variable arguments, callback chains) and custom record type reproduction
tests matching the exact pattern from issue #849 (Task<MyValue> with
ReturnsAsync). Adds 50 new test permutations across both Moq versions.

Refs: #849, #904

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rjmurillo rjmurillo force-pushed the test/moq1203-semantic-variations branch from 6040d3c to 46e17b2 Compare February 18, 2026 17:37
@coderabbitai coderabbitai bot added analyzers Change that impacts an analyzer behavior housekeeping labels Feb 18, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@tests/Moq.Analyzers.Test/MethodSetupShouldSpecifyReturnValueAnalyzerTests.cs`:
- Around line 452-471: Tests marked as "no diagnostics"
(ShouldNotFlagSemanticVariationSetups and
ShouldNotFlagSetupWithCustomReturnType) currently call VerifyMockAsync /
VerifyCustomSourceMockAsync which run only the single analyzer; replace those
calls so the tests use AllAnalyzersVerifier.VerifyAllAnalyzersAsync to ensure no
other Moq analyzers produce diagnostics. Specifically, change the body of
ShouldNotFlagSemanticVariationSetups to call
AllAnalyzersVerifier.VerifyAllAnalyzersAsync with the same parameters
(referenceAssemblyGroup, `@namespace`, mock), and change
ShouldNotFlagSetupWithCustomReturnType to call
AllAnalyzersVerifier.VerifyAllAnalyzersAsync passing referenceAssemblyGroup,
`@namespace`, mock, recordDeclaration, interfaceMethod (or the appropriate
overload) instead of VerifyCustomSourceMockAsync.
- Around line 334-392: Add ValueTask variants mirroring the existing
Task<MyValue> cases in both CustomReturnTypeTestData and
CustomReturnTypeMissingReturnValueTestData: for each Task entry duplicate it but
change the method signature string from "Task<MyValue> ..." to
"ValueTask<MyValue> ...", keep the same setup code but use
ReturnsAsync(expectedValue) (and ThrowsAsync for the throws case) for the
positive cases, and duplicate the missing-return cases with "ValueTask<MyValue>"
signatures so the {|Moq1203:...|} diagnostics are exercised for ValueTask as
well; update entries that reference MockBehavior.Loose and the parameterless
record reproduction similarly so CustomReturnTypeTestData and
CustomReturnTypeMissingReturnValueTestData both include Task and ValueTask
variants.

@rjmurillo rjmurillo merged commit 24c275a into main Feb 19, 2026
35 of 37 checks passed
@rjmurillo rjmurillo deleted the test/moq1203-semantic-variations branch February 19, 2026 01:41
rjmurillo added a commit that referenced this pull request Feb 19, 2026
…tom types (#905)

## Summary
- Add 50 new test permutations for Moq1203 covering variable-based mock
construction, `MockBehavior` parameters, variable arguments, and
callback chains
- Add custom record type reproduction tests matching the exact pattern
from issue #849 (`Task<MyValue>` with `ReturnsAsync`)
- Existing tests only exercised inline `new Mock<IFoo>()` with primitive
`Task<int>` and literal arguments, which 100% line/branch coverage could
not distinguish from the failing pattern

## Test plan
- [x] `dotnet build tests/Moq.Analyzers.Test` compiles successfully
- [x] All 216 tests pass (50 new permutations added)
- [x] Custom-type test (`ShouldNotFlagSetupWithCustomReturnType`)
confirms the #849 fix works for `Task<MyValue>`

Refs: #849, #904

🤖 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 for Moq setup analysis scenarios, including
semantic variations, custom return types, and callback configurations
across multiple reference assembly groups.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant