Skip to content

Commit

Permalink
Fix issue with it.IsAny completion when working with overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
lconstan committed May 21, 2020
1 parent 010695a commit b33d80c
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class AutoMockerItIsAnyProviderActionTests : CodeCompletionTestBase
[TestCase("itIsAnyCompletionFull")]
[TestCase("itIsAnyCompletionParam")]
[TestCase("itIsAnyCompletionGeneric")]
[TestCase("itIsAnyCompletionOverload")]
[TestCase("itIsAnyCompletionOverloadAndGenerics")]
[TestCase("itIsAnyVerifyCompletionFull")]
public void should_fill_with_it_isAny(string testSrc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ItIsAnyProviderActionTests : CodeCompletionTestBase
[TestCase("itIsAnyCompletionFull")]
[TestCase("itIsAnyCompletionParam")]
[TestCase("itIsAnyCompletionGeneric")]
[TestCase("itIsAnyCompletionOverload")]
[TestCase("itIsAnyCompletionOverloadAndGenerics")]
[TestCase("itIsAnyVerifyCompletionFull")]
public void should_fill_with_it_isAny(string testSrc) => DoOneTest(testSrc);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;
using Moq.AutoMock;
using NUnit.Framework;

namespace ConsoleApp1.Tests
{
public interface ITestInterface
{
decimal GetGrossAmountInEuro(decimal price, decimal quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

[TestFixture]
public class Test1
{
[Test]
public void METHOD()
{
var mock = new AutoMocker();
mock.Setup<ITestInterface>(x=>x.GetGrossAmountInEuro(It{caret}))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;
using Moq.AutoMock;
using NUnit.Framework;

namespace ConsoleApp1.Tests
{
public interface ITestInterface
{
decimal GetGrossAmountInEuro(decimal price, decimal quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

[TestFixture]
public class Test1
{
[Test]
public void METHOD()
{
var mock = new AutoMocker();
mock.Setup<ITestInterface>(x=>x.GetGrossAmountInEuro(It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>())){caret}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using NUnit.Framework;
using System;
using Moq;
using Moq.AutoMock;

namespace ConsoleApp1.Tests
{
public interface ITestInterface<T>
{
decimal GetGrossAmountInEuro(decimal price, T quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

[TestFixture]
public class Test1
{
[Test]
public void METHOD()
{
var mock = new AutoMocker();
mock.Setup<ITestInterface<decimal>>(x=>x.GetGrossAmountInEuro(It{caret}))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using NUnit.Framework;
using System;
using Moq;
using Moq.AutoMock;

namespace ConsoleApp1.Tests
{
public interface ITestInterface<T>
{
decimal GetGrossAmountInEuro(decimal price, T quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

[TestFixture]
public class Test1
{
[Test]
public void METHOD()
{
var mock = new AutoMocker();
mock.Setup<ITestInterface<decimal>>(x=>x.GetGrossAmountInEuro(It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>())){caret}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;

namespace ConsoleApp1.Tests
{
public interface ITestInterface
{
decimal GetGrossAmountInEuro(decimal price, decimal quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

public class Test1
{
public void METHOD()
{
var mock = new Mock<ITestInterface>();
mock.Setup(x=>x.GetGrossAmountInEuro(it{caret}))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;

namespace ConsoleApp1.Tests
{
public interface ITestInterface
{
decimal GetGrossAmountInEuro(decimal price, decimal quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

public class Test1
{
public void METHOD()
{
var mock = new Mock<ITestInterface>();
mock.Setup(x=>x.GetGrossAmountInEuro(It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>())){caret}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;

namespace ConsoleApp1.Tests
{
public interface ITestInterface<T>
{
decimal GetGrossAmountInEuro(decimal price, T quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

public class Test1
{
public void METHOD()
{
var mock = new Mock<ITestInterface<decimal>>();
mock.Setup(x=>x.GetGrossAmountInEuro(it{caret}))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ${COMPLETE_ITEM:It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>()}
using Moq;

namespace ConsoleApp1.Tests
{
public interface ITestInterface<T>
{
decimal GetGrossAmountInEuro(decimal price, T quantity, int securityId, int currencyId, decimal spotRateInEuro);
decimal GetGrossAmountInEuro(string message);
decimal GetGrossAmountInEuro(int trade);

void Build(int temp);
}

public class Test1
{
public void METHOD()
{
var mock = new Mock<ITestInterface<decimal>>();
mock.Setup(x=>x.GetGrossAmountInEuro(It.IsAny<decimal>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<decimal>())){caret}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,18 @@ protected override bool AddLookupItems(CSharpCodeCompletionContext context, IIte
return true;
}

var mockedMethodResolved = mockedMethodInvocationExpression.Reference.Resolve();

var declaredElements = Enumerable.Repeat(mockedMethodResolved.DeclaredElement, 1)
.Concat(mockedMethodResolved.Result.Candidates)
.Where(x => x != null);

var methods = declaredElements.OfType<IMethod>().Where(x => x.Parameters.Count > 1).ToList();

foreach (var method in methods)
{
var parameter = method.Parameters.Select(x => GetItIsAny(x, mockedMethodResolved.Substitution));
var proposedCompletion = string.Join(", ", parameter);
AddLookup(context, collector, proposedCompletion, isSetup ? 2 : 1);
var candidates = mockedMethodInvocationExpression.InvocationExpressionReference.GetCandidates();
foreach (var candidate in candidates)
{
var method = candidate.GetDeclaredElement() as IMethod;
var substitution = candidate.GetSubstitution();

if (method == null || method.Parameters.Count <= 1)
continue;

var parameter = method.Parameters.Select(x => GetItIsAny(x, substitution));
var proposedCompletion = string.Join(", ", parameter);
AddLookup(context, collector, proposedCompletion, isSetup ? 2 : 1);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Abc.MoqComplete/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>1.3.2</Version>
<Version>1.3.3</Version>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion Abc.MoqComplete/Plugin.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<SdkVersion>2020.1.0</SdkVersion>
<SdkVersion>2020.1.3</SdkVersion>
<Title>MoqComplete</Title>
<Description>Code completion for Moq</Description>
<Authors>ABC Arbitrage Asset Management</Authors>
Expand Down

0 comments on commit b33d80c

Please sign in to comment.