Skip to content

Commit

Permalink
[GH-153] - substitute analyzers handling named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tpodolak committed Dec 20, 2020
1 parent af690d8 commit 9bce494
Show file tree
Hide file tree
Showing 22 changed files with 1,423 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -114,11 +115,11 @@ bool IsVisibleToProxy(IMethodSymbol symbol)
(IsAccessible(symbol) || IsVisibleToProxy(symbol))).ToArray();
}

private ImmutableArray<IArgumentOperation> GetInvocationArguments(SubstituteContext<TInvocationExpression> substituteContext, TInvocationExpression invocationExpression)
private IEnumerable<IArgumentOperation> GetInvocationArguments(SubstituteContext<TInvocationExpression> substituteContext, TInvocationExpression invocationExpression)
{
var invocationOperation = (IInvocationOperation)substituteContext.SyntaxNodeAnalysisContext.SemanticModel.GetOperation(invocationExpression);

return invocationOperation.Arguments;
return invocationOperation.GetOrderedArgumentOperations();
}

private ITypeSymbol[] TypeSymbols(IArrayCreationOperation arrayInitializerOperation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Operations;
using NSubstitute.Analyzers.Shared.Extensions;

namespace NSubstitute.Analyzers.Shared.DiagnosticAnalyzers
{
Expand Down Expand Up @@ -36,7 +37,7 @@ public ImmutableArray<ITypeSymbol> GetProxySymbols(SemanticModel semanticModel,

var operation = (IInvocationOperation)semanticModel.GetOperation(invocationExpressionSyntax);

var argument = operation.Arguments.First();
var argument = operation.GetOrderedArgumentOperations().First();
var typeSymbols = ArgType(argument);

return typeSymbols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class FooTests
public void Test()
{
var substitute = NSubstitute.Substitute.For<IFoo>(1, 2, 3);
var otherSubstitute = NSubstitute.Substitute.For<IFoo>(constructorArguments: new [] { 1, 2, 3 });
}
}
}";
Expand All @@ -46,6 +47,7 @@ public class FooTests
public void Test()
{
var substitute = NSubstitute.Substitute.For<IFoo>();
var otherSubstitute = NSubstitute.Substitute.For<IFoo>();
}
}
}";
Expand All @@ -69,6 +71,8 @@ public class FooTests
public void Test()
{
var substitute = NSubstitute.Substitute.For(new [] { typeof(IFoo) }, new object[] { 1 });
var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo) }, constructorArguments: new object[] { 1 });
var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(IFoo) });
}
}
}";
Expand All @@ -85,6 +89,8 @@ public class FooTests
public void Test()
{
var substitute = NSubstitute.Substitute.For(new [] { typeof(IFoo) }, null);
var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo) }, constructorArguments: null);
var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(IFoo) });
}
}
}";
Expand All @@ -108,6 +114,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(IFoo)}, new object[] { 1 });
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(IFoo)}, constructorArguments: new object[] { 1 });
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[] { 1 }, typesToProxy: new[] {typeof(IFoo)});
}
}
}";
Expand All @@ -125,6 +133,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(IFoo)}, null);
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(IFoo)}, constructorArguments: null);
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(IFoo)});
}
}
}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(System.Func<int>)}, null);
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new[] {typeof(System.Func<int>)}, constructorArguments: null);
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new[] {typeof(System.Func<int>)});
}
}
}";
Expand All @@ -110,6 +112,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(System.Func<int>)}, null);
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(System.Func<int>)}, constructorArguments: null);
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(System.Func<int>)});
}
}
}";
Expand All @@ -134,6 +138,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(IFoo)}, null);
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new[] {typeof(IFoo)}, constructorArguments: null);
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new[] {typeof(IFoo)});
}
}
}";
Expand All @@ -151,6 +157,8 @@ public class FooTests
public void Test()
{
var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(IFoo)}, null);
var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(IFoo)}, constructorArguments: null);
var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(IFoo)});
}
}
}";
Expand Down
Loading

0 comments on commit 9bce494

Please sign in to comment.