-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update analyzer, refactor code, and add abstract class support #20
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
21226ac
Update analyzer, refactor code, and add abstract class support
rjmurillo 8789898
retrigger checks
rjmurillo 24ba0d6
Merge branch 'master' into repro-issue-1
rjmurillo 246ab16
Merge branch 'master' into repro-issue-1
rjmurillo 6a5857b
Updated test files and refactored AbstractClassTests.cs
rjmurillo 56c9516
`Updated test methods and diagnostic messages in AbstractClassTests`
rjmurillo 012524a
Delete Source/Moq.Analyzers.Test/AbstractClassTests.ShouldPassIfGoodP…
rjmurillo 7560816
Update DiagnosticVerifier.Helper.cs to move using inside namespace
rjmurillo b568ce6
Update ConstructorArgumentsShouldMatchAnalyzer.cs comment about abstr…
rjmurillo 1ffbc5e
Update Moq.Analyzers.csproj to remove language version override
rjmurillo d889cdf
Merge branch 'master' into repro-issue-1
rjmurillo c552220
Update baselines for abstract class and ctor arguments due to refactor
rjmurillo 5243b0e
Merge branch 'master' into repro-issue-1
rjmurillo 300fde8
Rebaseline constructor arguments using Verify.Terminal
rjmurillo b034462
Merge branch 'repro-issue-1' of https://github.com/Litee/moq.analyzer…
rjmurillo 0107aeb
Added new cases to analyze abstract classes' constructor arguments
rjmurillo b3205bb
Rebaseline constructor arguments using Verify.Terminal
rjmurillo c3c0a3d
Fix line endings on test csharp
rjmurillo 03ade9d
Add positive and negative cases for generic
rjmurillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...zers.Test/AbstractClassTests.ShouldPassIfGoodParametersAndFailOnTypeMismatch.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Diagnostic 1 | ||
Id: Moq1002 | ||
Location: SourceFile(Test1.cs[252..258)) | ||
Highlight: ("42") | ||
Lines: var mock = new Mock<AbstractClassWithCtor>("42"); | ||
Severity: Warning | ||
Message: Parameters provided into mock do not match any existing constructors. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
||
namespace Moq.Analyzers.Test | ||
{ | ||
using System.IO; | ||
|
||
using TestHelper; | ||
|
||
using Xunit; | ||
|
||
public class AbstractClassTests : DiagnosticVerifier | ||
{ | ||
[Fact] | ||
public Task ShouldPassIfGoodParametersAndFailOnTypeMismatch() | ||
{ | ||
return Verify(VerifyCSharpDiagnostic( | ||
[ | ||
File.ReadAllText("Data/AbstractClass.Good.cs"), | ||
File.ReadAllText("Data/AbstractClass.Bad.cs") | ||
] | ||
)); | ||
} | ||
|
||
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() | ||
{ | ||
return new ConstructorArgumentsShouldMatchAnalyzer(); | ||
} | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...uctorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Moq.Analyzers.Test.Data | ||
{ | ||
internal class MyBadUnitTests | ||
{ | ||
private void TestBad() | ||
{ | ||
// The class has a constructor that takes an int but passes a string | ||
var mock = new Mock<AbstractClassWithCtor>("42"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace Moq.Analyzers.Test.Data | ||
{ | ||
internal abstract class AbstractClassDefaultCtor | ||
{ | ||
protected AbstractClassDefaultCtor() | ||
{ | ||
} | ||
} | ||
|
||
internal abstract class AbstractClassWithCtor | ||
{ | ||
protected AbstractClassWithCtor(int a) | ||
{ | ||
} | ||
} | ||
|
||
internal class MyUnitTests | ||
{ | ||
// Base case that we can handle abstract types | ||
private void TestForBaseNoArgs() | ||
{ | ||
var mock = new Mock<AbstractClassDefaultCtor>(); | ||
mock.As<AbstractClassDefaultCtor>(); | ||
|
||
var mock2 = new Mock<AbstractClassWithCtor>(); | ||
var mock3 = new Mock<AbstractClassDefaultCtor>(MockBehavior.Default); | ||
} | ||
|
||
// This is syntatically not allowed by C#, but you can do it with Moq | ||
private void TestForBaseWithArgsNonePassed() | ||
{ | ||
var mock = new Mock<AbstractClassWithCtor>(); | ||
mock.As<AbstractClassWithCtor>(); | ||
} | ||
|
||
private void TestForBaseWithArgsPassed() | ||
{ | ||
var mock2 = new Mock<AbstractClassWithCtor>(42); | ||
var mock3 = new Mock<AbstractClassWithCtor>(MockBehavior.Default, 42); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From conversation, some test cases missing: