Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analyzers for strict behavior mode #127

Closed
rjmurillo opened this issue Jun 25, 2024 · 1 comment · Fixed by #302
Closed

Add analyzers for strict behavior mode #127

rjmurillo opened this issue Jun 25, 2024 · 1 comment · Fixed by #302
Assignees
Labels
analyzers Change that impacts an analyzer behavior enhancement help wanted .NET Pull requests that update .net code
Milestone

Comments

@rjmurillo
Copy link
Owner

rjmurillo commented Jun 25, 2024

Given

public class TestClass
{
  public virtual Task TaskAsync() => Task.CompletedTask;
}

Two cases:

  1. Mock has no setup corresponding to the specified invocation
    When new Mock<TestClass>(MockBehavior.Strict).Object.TaskAsync(); executes it will throw an exception at runtime because MockBehavior.Strict is set but there is no Setup for the method TaskAsync
  2. Mock has no setup that provides a return value for the specified invocation
    Similar to the first case, if the setup does not include a return, there will be a runtime exception

Related to #78

@rjmurillo rjmurillo added analyzers Change that impacts an analyzer behavior .NET Pull requests that update .net code triage enhancement and removed .NET Pull requests that update .net code triage labels Jun 25, 2024
@rjmurillo
Copy link
Owner Author

See discussion at devlooped/moq#1520

@rjmurillo rjmurillo added this to the v0.2.0 milestone Oct 15, 2024
@rjmurillo rjmurillo modified the milestones: v0.2.0, vNext Oct 22, 2024
@rjmurillo rjmurillo self-assigned this Dec 24, 2024
rjmurillo added a commit that referenced this issue Dec 24, 2024
Introduced a new diagnostic rule, Moq1410, to ensure explicit setting of MockBehavior.Strict in Moq. Updated README.md, global.json, and added new entries in AnalyzerReleases.Unshipped.md and DiagnosticIds.cs. Created Moq1410.md for rule documentation. Implemented SetStrictMockBehaviorAnalyzer and SetStrictMockBehaviorFixer classes, along with corresponding tests in SetStrictMockBehaviorCodeFixTests.cs.

Fixes #127
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 enhancement help wanted .NET Pull requests that update .net code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants