Skip to content

Commit

Permalink
Add tu for suspicious callback analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
lconstan committed Jan 31, 2019
1 parent 9dd7f1e commit 661788e
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 2 deletions.
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);
}
}
4 changes: 3 additions & 1 deletion Abc.MoqComplete/MoqComplete.Tests/MoqComplete.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CodeAnalysis\SuspiciousCallbackAnalyzerTests.cs" />
<Compile Include="Completion\CallbackMethodProviderTests.cs" />
<Compile Include="Completion\ItIsAnyProviderActionTests.cs" />
<Compile Include="Completion\ItIsAnyProviderListTests.cs" />
<Compile Include="Completion\MoqCompleteTestsAssembly.cs" />
<Compile Include="MoqCompleteTestsAssembly.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Completion\SuggestMockProviderActionTests.cs" />
<Compile Include="Completion\SuggestMockProviderListTests.cs" />
Expand Down Expand Up @@ -180,5 +181,6 @@
<Version>4.10.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: TestDataPathBase("MoqComplete.Tests/data")]
#pragma warning restore 618

namespace MoqComplete.Tests.Completion
namespace MoqComplete.Tests
{
[ZoneDefinition]
public interface IUnitTestZone : ITestsEnvZone, IRequire<PsiFeatureTestZone>
Expand Down
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);
}
}
}
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);
}
}
}
---------------------------------------------------------
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);
}
}
}
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
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);
}
}
}
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
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);
}
}
}
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) ''
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);
}
}
}
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) ''

0 comments on commit 661788e

Please sign in to comment.