-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tu for suspicious callback analyzer
- Loading branch information
Showing
13 changed files
with
276 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Abc.MoqComplete/MoqComplete.Tests/CodeAnalysis/SuspiciousCallbackAnalyzerTests.cs
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,31 @@ | ||
using JetBrains.ReSharper.FeaturesTestFramework.Daemon; | ||
using JetBrains.ReSharper.TestFramework; | ||
using MoqComplete.CodeAnalysis; | ||
using NUnit.Framework; | ||
|
||
namespace MoqComplete.Tests.CodeAnalysis | ||
{ | ||
[TestNetCore21("Moq/4.10.1")] | ||
public class SuspiciousCallbackAnalyzerTests : CSharpHighlightingTestBase | ||
{ | ||
private SupiciousCallbackAnalyzer _analyzer; | ||
protected override string RelativeTestDataPath => "SuspiciousCallback"; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
base.SetUp(); | ||
// /!\ Mandatory otherwise the completion is not done | ||
_analyzer = new SupiciousCallbackAnalyzer(); | ||
} | ||
|
||
[TestCase("typeMismatch_return_before")] | ||
[TestCase("typeCountMismatch_return_before")] | ||
[TestCase("typeMismatch_return_after")] | ||
[TestCase("typeCountMismatch_return_after")] | ||
public void should_detect_suspicious_callback(string testSrc) => DoOneTest(testSrc); | ||
|
||
[TestCase("no_types")] | ||
public void should_not_detect_suspicious_callbacl(string testSrc) => DoOneTest(testSrc); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/no_types.cs
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,23 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback<int, string, bool>((i, s, arg3) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/no_types.cs.gold
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,24 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback<int, string, bool>((i, s, arg3) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} | ||
--------------------------------------------------------- |
23 changes: 23 additions & 0 deletions
23
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeCountMismatch_return_after.cs
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,23 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Callback<int, string>((i, s, arg3) => count += i) | ||
.Returns(0); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...Complete/MoqComplete.Tests/data/SuspiciousCallback/typeCountMismatch_return_after.cs.gold
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,26 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Callback|<int, string>|(0)(|(i, s, arg3)|(1) => count += i) | ||
.Returns(0); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} | ||
--------------------------------------------------------- | ||
(0): ReSharper Warning: (T) 'Suspicious Callback method call: Generic types do not match' (E) '' | ||
(1): ReSharper Underlined Error Highlighting: Incompatible anonymous function signature |
23 changes: 23 additions & 0 deletions
23
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeCountMismatch_return_before.cs
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,23 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback<int, string>((i, s, arg3) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...omplete/MoqComplete.Tests/data/SuspiciousCallback/typeCountMismatch_return_before.cs.gold
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,26 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback|<int, string>|(0)(|(i, s, arg3)|(1) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} | ||
--------------------------------------------------------- | ||
(0): ReSharper Warning: (T) 'Suspicious Callback method call: Generic types do not match' (E) '' | ||
(1): ReSharper Underlined Error Highlighting: Incompatible anonymous function signature |
23 changes: 23 additions & 0 deletions
23
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeMismatch_return_after.cs
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,23 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Callback<int, string, string>((i, s, arg3) => count += i) | ||
.Returns(0); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeMismatch_return_after.cs.gold
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,25 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Callback|<int, string, string>|(0)((i, s, arg3) => count += i) | ||
.Returns(0); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} | ||
--------------------------------------------------------- | ||
(0): ReSharper Warning: (T) 'Suspicious Callback method call: Generic types do not match' (E) '' |
23 changes: 23 additions & 0 deletions
23
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeMismatch_return_before.cs
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,23 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback<int, string, string>((i, s, arg3) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Abc.MoqComplete/MoqComplete.Tests/data/SuspiciousCallback/typeMismatch_return_before.cs.gold
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,25 @@ | ||
using System; | ||
using Moq; | ||
|
||
namespace ConsoleApp1.Tests | ||
{ | ||
public interface ITestInterface | ||
{ | ||
int BuildSomething(int theInt, string theString, bool theBool); | ||
} | ||
|
||
public class Test1 | ||
{ | ||
public void METHOD() | ||
{ | ||
var mock = new Mock<ITestInterface>(); | ||
var count = 0; | ||
mock.Setup(x => x.BuildSomething(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>())) | ||
.Returns(0) | ||
.Callback|<int, string, string>|(0)((i, s, arg3) => count += i); | ||
Console.WriteLine(count); | ||
} | ||
} | ||
} | ||
--------------------------------------------------------- | ||
(0): ReSharper Warning: (T) 'Suspicious Callback method call: Generic types do not match' (E) '' |