Skip to content

test: add direct unit tests for MockBehaviorDiagnosticAnalyzerBase#1038

Merged
rjmurillo merged 6 commits intomainfrom
test/926-mock-behavior-base-tests
Mar 8, 2026
Merged

test: add direct unit tests for MockBehaviorDiagnosticAnalyzerBase#1038
rjmurillo merged 6 commits intomainfrom
test/926-mock-behavior-base-tests

Conversation

@rjmurillo-bot
Copy link
Copy Markdown
Collaborator

@rjmurillo-bot rjmurillo-bot commented Mar 7, 2026

Summary

  • Adds 18 tests for MockBehaviorDiagnosticAnalyzerBase shared logic, exercised through both concrete subclasses (SetExplicitMockBehaviorAnalyzer and SetStrictMockBehaviorAnalyzer)
  • Tests cover base class branches not previously exercised: IsMockReferenced() early return, AnalyzeObjectCreation type guards, and AnalyzeInvocation method guards
  • Documents the untestable MockBehavior is null branch (requires Moq.Mock without Moq.MockBehavior, which cannot occur with any real Moq assembly)

Closes #926

Test plan

  • All 18 new tests pass
  • Full test suite passes (2919 tests, 0 failures)
  • No build warnings

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • Tests
    • Added tests covering analyzer base behavior to ensure no reports for various non-mock creation and invocation scenarios.
    • Added coverage across multiple Moq/reference variants.
    • Introduced a shared helper to run and verify both analyzer modes (Explicit and Strict) across inputs.

)

Add 18 tests exercising MockBehaviorDiagnosticAnalyzerBase shared logic
through both concrete subclasses (SetExplicitMockBehaviorAnalyzer and
SetStrictMockBehaviorAnalyzer). Tests cover:

- IsMockReferenced() early return when Moq is not referenced
- AnalyzeObjectCreation type guard for non-Mock types
- AnalyzeInvocation method guard for non-Mock.Of invocations
- Non-mock object creation with Moq referenced
- Moq method invocations that are not Mock.Of

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rjmurillo-bot rjmurillo-bot requested a review from rjmurillo as a code owner March 7, 2026 22:39
@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 suite by introducing new unit tests for the core logic of MockBehaviorDiagnosticAnalyzerBase. These tests ensure the robustness and correctness of the diagnostic analyzers by validating their behavior across various scenarios, including critical guard clauses and edge cases, thereby improving the overall reliability of the Moq analyzers.

Highlights

  • New Unit Tests: Added 18 new unit tests for the shared logic of MockBehaviorDiagnosticAnalyzerBase, covering both SetExplicitMockBehaviorAnalyzer and SetStrictMockBehaviorAnalyzer.
  • Improved Test Coverage: Expanded test coverage to previously unexercised base class branches, including IsMockReferenced() early return, AnalyzeObjectCreation type guards, and AnalyzeInvocation method guards.
  • Untestable Scenario Documented: Documented the MockBehavior is null branch as untestable due to its reliance on an impossible scenario with real Moq assemblies.
Changelog
  • tests/Moq.Analyzers.Test/MockBehaviorDiagnosticAnalyzerBaseTests.cs
    • Added comprehensive unit tests for the shared logic of MockBehaviorDiagnosticAnalyzerBase.
    • Included tests for IsMockReferenced() early return, AnalyzeObjectCreation type guards, and AnalyzeInvocation method guards.
Activity
  • All 18 newly added tests have passed successfully.
  • The full test suite, comprising 2919 tests, passed with no failures.
  • The project builds without any warnings.
  • The pull request was generated with the assistance of Claude Code and co-authored by Claude Opus 4.6.
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

Warning

Rate limit exceeded

@rjmurillo-bot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7d45a83a-22aa-4be7-b4da-d48af8b97280

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea2dd1 and 50b49bc.

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

Walkthrough

Adds a new test file that directly exercises MockBehaviorDiagnosticAnalyzerBase via both explicit and strict analyzers, introducing data providers and multiple non-mock/no-Moq scenarios to validate diagnostic suppression paths.

Changes

Cohort / File(s) Summary
New Tests
tests/Moq.Analyzers.Test/MockBehaviorDiagnosticAnalyzerBaseTests.cs
Adds a test class with MoqReferenceAssemblyGroups data provider, six tests covering no-Moq and non-mock scenarios, and helper methods to run both Explicit and Strict analyzers across reference-assembly variants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • MattKotsenas
  • rjmurillo
🚥 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 'test: add direct unit tests for MockBehaviorDiagnosticAnalyzerBase' clearly and concisely summarizes the main change: adding a new test file with unit tests for the base class.
Linked Issues check ✅ Passed The pull request creates MockBehaviorDiagnosticAnalyzerBaseTests.cs with comprehensive tests covering conditional branches in the base class including IsMockReferenced early return, AnalyzeObjectCreation type guards, and AnalyzeInvocation guards as required by #926.
Out of Scope Changes check ✅ Passed All changes are scoped to adding a new test file with unit tests for MockBehaviorDiagnosticAnalyzerBase, directly addressing the requirements in linked issue #926 without introducing unrelated modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/926-mock-behavior-base-tests

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 08986de...50b49bc 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 in test methods
    • Test methods returning Task repeatedly lack the Async suffix because existing test code/templates omitted it; update test templates and apply the IDE/codefix rename to restore the naming convention and stop manual drift.
  • Analyzers or EditorConfig not applied to test project
    • Identical violations across a file suggest the analyzer/editorconfig isn't active for that project; include the analyzer package or enable the rule (warning/error) in the test project's config so the build enforces the convention.
  • Copy-paste scaffolding propagates the same mistake
    • Multiple occurrences look like cloned test scaffolds carrying the same naming omission; fix the scaffold/template and add a small generation-time check to prevent future copies from repeating the error.

Code Review Summary

Analyzer Status Updated (UTC) Details
C# Mar 8, 2026 1:16a.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 a comprehensive set of unit tests for the shared logic in MockBehaviorDiagnosticAnalyzerBase. The tests are well-structured and cover important edge cases and guard conditions in the base analyzer. My main feedback is to reduce code duplication by combining the tests for the explicit and strict analyzers using a local helper method, which I've detailed in a specific comment. Overall, this is a valuable addition that improves test coverage.

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Mar 7, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.51% (target: -1.00%) (target: 95.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (06b2fe4) 2507 2249 89.71%
Head commit (50b49bc) 2495 (-12) 2251 (+2) 90.22% (+0.51%)

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 (#1038) 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 and others added 2 commits March 7, 2026 14:58
…d helper

Introduce VerifyBothAnalyzersAsync helper to eliminate 5 pairs of
duplicate test methods, reducing them to 5 single methods that verify
both analyzers concurrently via Task.WhenAll.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nalyzersAsync

Task.WhenAll masks the second failure when both tasks fail, reporting
only the first exception. Sequential awaits ensure each failure is
reported independently, improving debuggability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai coderabbitai bot requested a review from MattKotsenas March 7, 2026 23:56
@coderabbitai coderabbitai bot added housekeeping analyzers Change that impacts an analyzer behavior labels Mar 8, 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: 1

🤖 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/MockBehaviorDiagnosticAnalyzerBaseTests.cs`:
- Around line 91-103: Remove the unused ISample interface declaration from the
test source: locate the string constant named source that contains "public
interface ISample { }" and delete that interface declaration so the test only
includes the necessary UnitTest class and its Test method creating new object();
ensure no other references to ISample remain in the file (e.g., in
MockBehaviorDiagnosticAnalyzerBaseTests) before committing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ba76e2af-ce73-496e-bfd7-92f0f541102a

📥 Commits

Reviewing files that changed from the base of the PR and between 08986de and 2f8d304.

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 8, 2026
…haviorDiagnosticAnalyzerBaseTests

Add ConfigureAwait(false) to all await calls in the test file to
resolve MA0004 build warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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: 1

🤖 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/MockBehaviorDiagnosticAnalyzerBaseTests.cs`:
- Line 44: Test methods call await
VerifyBothAnalyzersAsync(...).ConfigureAwait(false) which triggers xUnit1030;
remove the ConfigureAwait(false) suffix from each await in the test methods (the
calls in MockBehaviorDiagnosticAnalyzerBaseTests that invoke
VerifyBothAnalyzersAsync) so they read simply await
VerifyBothAnalyzersAsync(...). The helper VerifyBothAnalyzersAsync may keep
ConfigureAwait(false) if needed; only update the test method call sites to
eliminate ConfigureAwait(false).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 776fc797-bf31-4cc7-b5f3-15812d8c32b0

📥 Commits

Reviewing files that changed from the base of the PR and between 9195c08 and 5ea2dd1.

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

…t1030

xUnit1030 prohibits ConfigureAwait(false) in test methods because it
bypasses xUnit's parallelization limits. Kept ConfigureAwait(false) in
the private helper method VerifyBothAnalyzersAsync where MA0004 still
requires it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rjmurillo rjmurillo merged commit 50b64b4 into main Mar 8, 2026
43 of 46 checks passed
@rjmurillo rjmurillo deleted the test/926-mock-behavior-base-tests branch March 8, 2026 17:48
@rjmurillo rjmurillo added this to the vNext milestone Mar 8, 2026
rjmurillo-bot added a commit that referenced this pull request Mar 8, 2026
…1038)

## Summary

- Adds 18 tests for `MockBehaviorDiagnosticAnalyzerBase` shared logic,
exercised through both concrete subclasses
(`SetExplicitMockBehaviorAnalyzer` and `SetStrictMockBehaviorAnalyzer`)
- Tests cover base class branches not previously exercised:
`IsMockReferenced()` early return, `AnalyzeObjectCreation` type guards,
and `AnalyzeInvocation` method guards
- Documents the untestable `MockBehavior is null` branch (requires
Moq.Mock without Moq.MockBehavior, which cannot occur with any real Moq
assembly)

Closes #926

## Test plan

- [x] All 18 new tests pass
- [x] Full test suite passes (2919 tests, 0 failures)
- [x] No build warnings

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

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

* **Tests**
* Added tests covering analyzer base behavior to ensure no reports for
various non-mock creation and invocation scenarios.
  * Added coverage across multiple Moq/reference variants.
* Introduced a shared helper to run and verify both analyzer modes
(Explicit and Strict) across inputs.
<!-- 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.

test: add direct unit tests for MockBehaviorDiagnosticAnalyzerBase

2 participants