Skip to content

Commit

Permalink
Merge pull request #39 from Abc-Arbitrage/fix/38
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski authored Feb 29, 2024
2 parents d2f7858 + 82cdd96 commit fe2b8ef
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 76 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NUnit.Framework;
using System;
using Moq;

namespace ConsoleApp1.Tests
{
public class Test1(ITest test, ITest2 test2)
{

public interface ITest
{
void Coco(ITest test, ITest test2, string test3);
}
public interface ITest2
{
}
}

[TestFixture]
public class TestClass
{
[Test]
public void METHOD()
{
var t = new Test1({ caret });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NUnit.Framework;
using System;
using Moq;

namespace ConsoleApp1.Tests
{
public class Test1(ITest test, ITest2 test2)
{

public interface ITest
{
void Coco(ITest test, ITest test2, string test3);
}
public interface ITest2
{
}
}

[TestFixture]
public class TestClass
{
private Mock<ITest> myTest;
private Mock<ITest2> myTest2;

[Test]
public void METHOD()
{
myTest = new Mock<ITest>();
myTest2 = new Mock<ITest2>();
var t = new Test1(myTest.Object, myTest2.Object{caret});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override bool IsAvailable(IUserDataHolder cache)
protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
{
var argumentList = _selectedElement.ArgumentList;
var parameters = _csharpMemberProvider.GetConstructorParameters(_constructor.ToString()).ToArray();
var parameters = _csharpMemberProvider.GetConstructorParameters(_constructor).ToArray();
var mockFieldsByType = _csharpMemberProvider.GetClassFields(_classBody, _selectedElement.Language);
var shortName = _constructor.Parameters[_parameterNumber].ShortName;
var currentParam = parameters[_parameterNumber];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution
var @class = (IClass)selectedElement.TypeReference?.Resolve().DeclaredElement;
var parameterCount = selectedElement.ArgumentList?.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);
var constructor = @class.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > parameterCount);
var parameters = csharpMemberProvider.GetConstructorParameters(constructor.ToString()).ToArray();
var parameters = csharpMemberProvider.GetConstructorParameters(constructor).ToArray();
var parameterNumber = csharpMemberProvider.GetCurrentParameterNumber(selectedElement, _dataProvider);
var shortName = constructor.Parameters[parameterNumber].ShortName;
var currentParam = parameters[parameterNumber];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override bool IsAvailable(IUserDataHolder cache)
&& x.Parameters.All(_csharpMemberProvider.IsAbstractOrInterface));
if (_constructor == null)
return false;

var isAvailable = testProjectProvider.IsTestProject(_dataProvider.PsiModule) && _selectedElement != null && _selectedElement.Arguments.Count == 0;
if (isAvailable)
cache.PutKey(AnchorKey.FillWithMockContextActionKey);
Expand All @@ -75,7 +75,7 @@ protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution
if (classDeclaration == null || block == null)
return null;

var parameters = _csharpMemberProvider.GetConstructorParameters(_constructor.ToString()).ToArray();
var parameters = _csharpMemberProvider.GetConstructorParameters(_constructor).ToArray();
var naming = _dataProvider.PsiServices.Naming;
var mockFieldsByType = _csharpMemberProvider.GetClassFields(classBody, _selectedElement.Language);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution
if (constructor == null)
return null;

var parameters = _csharpMemberProvider.GetConstructorParameters(constructor.ToString()).ToArray();
var parameters = _csharpMemberProvider.GetConstructorParameters(constructor).ToArray();

for (int i = 0; i < constructor.Parameters.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using JetBrains.ReSharper.Feature.Services.CSharp.ContextActions;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Util;
using JetBrains.TextControl;
using JetBrains.Util;

Expand All @@ -14,34 +15,7 @@ namespace Abc.MoqComplete.ContextActions.Services
[SolutionComponent]
public class CsharpMemberProvider : ICsharpMemberProvider
{
public IEnumerable<string> GetConstructorParameters(string constructorString)
{
var index = 0;
var openedBracket = 0;

while (constructorString[index] != '(')
index++;

var sb = new StringBuilder();
while (constructorString[index] != ')')
{
index++;

if (constructorString[index] == '<')
openedBracket++;

else if (constructorString[index] == '>')
openedBracket--;

if (openedBracket ==0 && (constructorString[index] == ',' || constructorString[index] == ')'))
{
yield return sb.ToString();
sb.Clear();
}
else
sb.Append(constructorString[index]);
}
}
public IEnumerable<string> GetConstructorParameters(IConstructor constructor) => constructor.Parameters.Select(s => s.Type.GetPresentableName(constructor.PresentationLanguage));

public Dictionary<string, string> GetClassFields(IClassBody classBody, PsiLanguageType languageType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Abc.MoqComplete.ContextActions.Services
{
public interface ICsharpMemberProvider
{
IEnumerable<string> GetConstructorParameters(string constructorString);
IEnumerable<string> GetConstructorParameters(IConstructor constructor);
Dictionary<string, string> GetClassFields(IClassBody classBody, PsiLanguageType languageType);
string GetGenericMock(string typeStr);
bool IsAbstractOrInterface(IParameter parameter);
Expand Down

0 comments on commit fe2b8ef

Please sign in to comment.