test: add unit tests for 16 untested Common extension methods#898
test: add unit tests for 16 untested Common extension methods#898
Conversation
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>
📝 WalkthroughWalkthroughAdds 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Summary of ChangesHello @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 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
DeepSource reviewed changes in the commit range For detailed review results, please see the PR on DeepSource ↗ PR Report CardCode Review Summary
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. |
tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
Show resolved
Hide resolved
tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
tests/Moq.Analyzers.Test/Common/SemanticModelExtensionsTests.cs
Outdated
Show resolved
Hide resolved
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
There was a problem hiding this comment.
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.
tests/Moq.Analyzers.Test/Common/SemanticModelExtensionsTests.cs
Outdated
Show resolved
Hide resolved
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>
tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
Show resolved
Hide resolved
tests/Moq.Analyzers.Test/Common/InvocationExpressionSyntaxExtensionsTests.cs
Show resolved
Hide resolved
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>
There was a problem hiding this comment.
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.
Summary
Test plan
Closes #897
🤖 Generated with Claude Code
Summary by CodeRabbit