Skip to content

test: add unit tests for 16 untested Common extension methods#898

Merged
rjmurillo merged 3 commits intomainfrom
test/897-untested-common-methods
Feb 17, 2026
Merged

test: add unit tests for 16 untested Common extension methods#898
rjmurillo merged 3 commits intomainfrom
test/897-untested-common-methods

Conversation

@rjmurillo
Copy link
Copy Markdown
Owner

@rjmurillo rjmurillo commented Feb 17, 2026

Summary

  • Add 53 new unit tests covering 16 previously untested methods across 8 Common extension classes
  • New test files for IMethodSymbolExtensions, ITypeSymbolExtensions, MoqKnownSymbolExtensions, SyntaxNodeExtensions, InvocationExpressionSyntaxExtensions
  • Expanded existing tests for ISymbolExtensions, MoqVerificationHelpers, SemanticModelExtensions
  • All tests use Roslyn compilation for accurate semantic analysis

Test plan

  • CI pedantic build passes (0 warnings, 0 errors)
  • All 2328 tests pass locally (60 new tests)
  • CI pipeline passes all checks

Closes #897

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded unit test coverage across symbol, type, invocation, syntax and verification helpers, adding numerous new scenarios for overloads, parameter/type matching, raises/verify behaviors and Moq-specific detection.
  • Chores
    • Centralized and simplified test compilation/setup helpers to streamline in-memory compilations, LINQ and Moq-enabled test flows.

Add comprehensive unit tests covering previously untested methods
across Common extension classes. All tests use Roslyn compilation
for accurate semantic analysis.

New test files:
- IMethodSymbolExtensionsTests: Overloads, TryGetOverloadWithParameterOfType,
  TryGetParameterOfType (12 tests)
- ITypeSymbolExtensionsTests: GetBaseTypesAndThis (3 tests)
- MoqKnownSymbolExtensionsTests: IsMockReferenced (2 tests)
- SyntaxNodeExtensionsTests: FindLocation, GetParentSkippingParentheses (6 tests)
- InvocationExpressionSyntaxExtensionsTests: FindMockedMethodInvocationFromSetupMethod,
  FindMockedMemberExpressionFromSetupMethod, IsRaisesMethodCall (11 tests)

Expanded existing test files:
- ISymbolExtensionsTests: branch coverage for IsMoqReturnValueSpecificationMethod
  and IsMoqVerificationMethod (4 tests)
- MoqVerificationHelpersTests: TryGetMockedMemberSymbol,
  TryGetMockedMemberSyntax with method/property lambda (2 tests)
- SemanticModelExtensionsTests: FindSetupMethodFromCallbackInvocation,
  GetAllMatchingMockedMethodSymbolsFromSetupMethodInvocation,
  IsCallbackOrReturnInvocation, IsRaisesInvocation (13 tests)

Closes #897

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rjmurillo rjmurillo added this to the v0.4.1 milestone Feb 17, 2026
@rjmurillo rjmurillo enabled auto-merge (squash) February 17, 2026 01:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Adds a centralized test compilation helper and a large set of unit tests for Common extension methods (IMethodSymbol, ISymbol, ITypeSymbol, invocation/syntax/semantic helpers, Moq-known symbols, and verification helpers). Many existing tests were refactored to use the new CompilationHelper and Moq-aware compilation helpers.

Changes

Cohort / File(s) Summary
Compilation helper
tests/Moq.Analyzers.Test/Helpers/CompilationHelper.cs
New internal helper centralizing metadata references and providing CreateCompilation, CreateMoqCompilationAsync and GetMoqReferencesAsync for tests. Targets: unify Roslyn/Moq compilation setup.
IMethodSymbol tests
tests/Moq.Analyzers.Test/Common/IMethodSymbolExtensionsTests.cs
New test class (12 tests) covering Overloads, TryGetOverloadWithParameterOfType, TryGetParameterOfType including null, comparer, cancellation and convenience-overload cases.
ISymbol tests (updates + additions)
tests/Moq.Analyzers.Test/Common/ISymbolExtensionsTests.cs
Refactors to use CompilationHelper; adds tests for IsMoqReturnValueSpecificationMethod (Throws/ReturnsAsync/ThrowsAsync) and IsMoqVerificationMethod (VerifySet).
ITypeSymbol tests
tests/Moq.Analyzers.Test/Common/ITypeSymbolExtensionsTests.cs
New test class (3 tests) for GetBaseTypesAndThis covering class/object, inheritance chains, and interface-only scenarios.
InvocationExpression syntax tests
tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
New test class (≈10 tests) for finding mocked method/member expressions from Setup lambdas and IsRaisesMethodCall edge cases (nulls, non-lambdas, property access).
MoqKnownSymbols tests
tests/Moq.Analyzers.Test/Common/MoqKnownSymbolExtensionsTests.cs
New tests validating MoqKnownSymbols.IsMockReferenced with and without Moq references; includes helpers to build Moq and non-Moq symbol sets.
Moq verification helpers tests (refactor + additions)
tests/Moq.Analyzers.Test/Common/MoqVerificationHelpersTests.cs
Refactored to use CompilationHelper/async Moq compilation helpers; adds tests for VerifySet lambda property extraction and TryGetMockedMember symbol/syntax scenarios.
SemanticModel tests (refactor + additions)
tests/Moq.Analyzers.Test/Common/SemanticModelExtensionsTests.cs
Refactored to use CompilationHelper; adds/extends tests for FindSetupMethodFromCallbackInvocation, mocked method symbol retrieval, callback/return/raises detection, lambda/event extraction.
SyntaxNode tests
tests/Moq.Analyzers.Test/Common/SyntaxNodeExtensionsTests.cs
New test class (7 tests) for FindLocation and GetParentSkippingParentheses across various nesting/edge cases.
Diagnostic & Event & IOperation test updates
tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs, tests/Moq.Analyzers.Test/Common/EventSyntaxExtensionsTests.cs, tests/Moq.Analyzers.Test/Common/IOperationExtensionsTests.cs, tests/Moq.Analyzers.Test/Common/MoqKnownSymbolsTests.cs
Multiple test files refactored to remove inline CoreReferences and use CompilationHelper/CoreReferencesWithLinq or CoreReferencesWithTasks; removed local static reference setup and replaced CreateCompilation usages with helper calls. Attention: metadata reference changes and async Moq reference resolution.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

releasable, feature

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main objective: adding unit tests for 16 untested Common extension methods.
Linked Issues check ✅ Passed The PR comprehensively addresses all 16 untested methods listed in issue #897 with new unit tests covering the previously untested branches and edge cases.
Out of Scope Changes check ✅ Passed All changes are directly related to adding unit test coverage for the 16 untested Common extension methods, plus a refactor of shared test compilation boilerplate into CompilationHelper.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ 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/897-untested-common-methods

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

@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 Moq.Analyzers.Common extension methods. By introducing a substantial number of new unit tests and expanding existing ones, it aims to ensure the reliability and correctness of these foundational utility methods, which are critical for the overall functionality of the Moq analyzers. The focus is on comprehensive coverage to prevent regressions and validate expected behavior under various scenarios.

Highlights

  • New Unit Tests: Added 53 new unit tests to cover 16 previously untested methods across 8 Common extension classes.
  • Expanded Test Coverage: Created new test files for IMethodSymbolExtensions, ITypeSymbolExtensions, MoqKnownSymbolExtensions, SyntaxNodeExtensions, and InvocationExpressionSyntaxExtensions.
  • Existing Test Enhancements: Expanded existing test files for ISymbolExtensions, MoqVerificationHelpers, and SemanticModelExtensions to improve coverage.
  • Roslyn Compilation: All new and expanded tests utilize Roslyn compilation for accurate semantic analysis, ensuring robust testing.
Changelog
  • tests/Moq.Analyzers.Test/Common/IMethodSymbolExtensionsTests.cs
    • Added new unit tests for IMethodSymbolExtensions covering method overloads and parameter type retrieval.
  • tests/Moq.Analyzers.Test/Common/ISymbolExtensionsTests.cs
    • Expanded unit tests for ISymbolExtensions to include IsMoqReturnValueSpecificationMethod for Throws, ReturnsAsync, ThrowsAsync and IsMoqVerificationMethod for VerifySet.
  • tests/Moq.Analyzers.Test/Common/ITypeSymbolExtensionsTests.cs
    • Added new unit tests for ITypeSymbolExtensions covering base type retrieval for classes and interfaces.
  • tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
    • Added new unit tests for InvocationExpressionSyntaxExtensions covering mocked method/member expression finding and IsRaisesMethodCall.
  • tests/Moq.Analyzers.Test/Common/MoqKnownSymbolExtensionsTests.cs
    • Added new unit tests for MoqKnownSymbolExtensions to verify IsMockReferenced behavior with and without Moq compilation.
  • tests/Moq.Analyzers.Test/Common/MoqVerificationHelpersTests.cs
    • Updated existing tests and added new tests for MoqVerificationHelpers covering lambda extraction, property extraction from VerifySet lambdas, and mocked member symbol/syntax retrieval.
    • Refactored compilation setup to use shared CreateCompilation and CreateMoqCompilationAsync methods.
  • tests/Moq.Analyzers.Test/Common/SemanticModelExtensionsTests.cs
    • Updated existing tests and added new tests for SemanticModelExtensions covering finding setup methods from callback invocations, getting mocked method symbols, and identifying callback/return/raises invocations.
    • Refactored compilation setup to use shared CreateMoqCompilationAsync method.
  • tests/Moq.Analyzers.Test/Common/SyntaxNodeExtensionsTests.cs
    • Added new unit tests for SyntaxNodeExtensions covering finding locations of symbols and skipping parentheses in parent traversal.
Activity
  • The pull request author, rjmurillo, initiated this change to add unit tests for previously untested Common extension methods.
  • 53 new unit tests were added, targeting 16 methods across 8 Common extension classes.
  • New test files were introduced for IMethodSymbolExtensions, ITypeSymbolExtensions, MoqKnownSymbolExtensions, SyntaxNodeExtensions, and InvocationExpressionSyntaxExtensions.
  • Existing test files for ISymbolExtensions, MoqVerificationHelpers, and SemanticModelExtensions were expanded with additional test cases.
  • All tests leverage Roslyn compilation for accurate semantic analysis.
  • The author confirmed that the CI pedantic build passes with no warnings or errors.
  • Locally, all 2328 tests passed, including the 60 new tests introduced.
  • This pull request addresses and closes issue Add unit tests for 16 untested Common extension methods #897.
  • The changes were generated with the assistance of 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.

@deepsource-io
Copy link
Copy Markdown

deepsource-io bot commented Feb 17, 2026

DeepSource Code Review

DeepSource reviewed changes in the commit range cdc195c..4d44b6a 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
Prioritize fixing 5 methods with `Task` return type not following naming conventions in the tests directory.
Reliability × 0 issues
Complexity × 0 issues
Hygiene × 42 issues

Code Review Summary

Analyzer Status Summary Details
C# 42 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.

@coderabbitai coderabbitai bot requested a review from MattKotsenas February 17, 2026 01:30
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 significantly improves test coverage by adding 53 new unit tests for 16 previously untested extension methods. The new tests are well-structured, cover a variety of scenarios including edge cases, and use Roslyn's semantic analysis capabilities effectively. The refactoring in existing test files to use common helpers is also a good improvement.

My main feedback is regarding code duplication. Several test files now contain identical helper methods for creating Moq-enabled Roslyn compilations. Consolidating this logic into a shared base class would improve the maintainability of the test suite. Overall, this is a great contribution to the project's quality and robustness.

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Feb 17, 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 (cdc195c) 2049 1825 89.07%
Head commit (4d44b6a) 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 (#898) 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

@coderabbitai coderabbitai bot added analyzers Change that impacts an analyzer behavior build housekeeping labels Feb 17, 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/Common/SemanticModelExtensionsTests.cs`:
- Around line 516-542: The test
FindSetupMethodFromCallbackInvocation_ReturnsChain_FindsSetup duplicates
FindSetupMethodFromCallbackInvocation_ValidReturnsChain_FindsSetupInvocation;
remove the redundant test method entirely (the whole method declaration
including its body) so only one of the two tests invoking
model.FindSetupMethodFromCallbackInvocation with the Returns invocation remains;
verify you keep the intended test (e.g.,
FindSetupMethodFromCallbackInvocation_ValidReturnsChain_FindsSetupInvocation)
and run tests to ensure coverage is unchanged.

Extract duplicated compilation boilerplate (CorlibReference,
CoreReferences, CreateCompilation, CreateMoqCompilationAsync,
GetMoqReferencesAsync) from 12 test files into a shared
CompilationHelper class.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
FindSetupMethodFromCallbackInvocation_ReturnsChain_FindsSetup was a
strict subset of FindSetupMethodFromCallbackInvocation_ValidReturnsChain_FindsSetupInvocation
(same code, same setup, fewer assertions).

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: 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/Common/InvocationExpressionSyntaxExtensionsTests.cs`:
- Around line 8-20: The test snippets (e.g., in
FindMockedMethodInvocationFromSetupMethod_ValidLambdaWithMethodInvocation_ReturnsInvocation)
use bare expressions like "mock.Setup(x => x.Method())" which are not
compilable; update each const string snippet to be a minimal, compilable script
by declaring a stub Mock type and a mock variable and any minimal Setup
overloads used by the tests (e.g., add a simple class/record/interface and a
Mock class with a Setup method that accepts the same delegate/signature the test
uses), so replace the raw snippet with a small script that declares the stub
types and "var mock = new Mock();" before calling mock.Setup(...); apply the
same wrapping to the other affected test snippets referenced in the comment.

In `@tests/Moq.Analyzers.Test/Helpers/CompilationHelper.cs`:
- Around line 29-40: CoreReferences and CoreReferencesWithLinq currently
allocate new arrays on every access; change them to cached static readonly
fields initialized once (in a static constructor if needed) to avoid repeated
allocations. Replace the expression-bodied properties CoreReferences and
CoreReferencesWithLinq with public/internal properties that return prebuilt
static readonly arrays (e.g., CoreReferencesCache, CoreReferencesWithLinqCache)
populated from CorlibReference, SystemRuntimeReference, SystemLinqReference, and
SystemLinqExpressionsReference during type initialization.

@rjmurillo rjmurillo merged commit 7f88c4a into main Feb 17, 2026
34 of 37 checks passed
@rjmurillo rjmurillo deleted the test/897-untested-common-methods branch February 17, 2026 02:47
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 build feature housekeeping releasable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for 16 untested Common extension methods

1 participant