From 9bce49448b5ae0f79b70dfc7045436385e1e9e89 Mon Sep 17 00:00:00 2001 From: tpodolak Date: Sun, 1 Nov 2020 20:35:05 +0100 Subject: [PATCH] [GH-153] - substitute analyzers handling named parameters --- .../AbstractSubstituteConstructorAnalysis.cs | 5 +- .../AbstractSubstituteProxyAnalysis.cs | 3 +- ...gumentsForInterfaceCodeFixProviderTests.cs | 10 + ...dForUnsupportedTypeCodeFixProviderTests.cs | 8 + ...DoesMethodPrecededByOrdinaryMethodTests.cs | 162 ++++++++++++++ .../DoMethodPrecededByOrdinaryMethodTests.cs | 162 ++++++++++++++ .../ReturnsAsOrdinaryMethodTests.cs | 200 ++++++++++++++++++ .../ThrowsAsOrdinaryMethodTests.cs | 200 ++++++++++++++++++ .../ReturnsAsOrdinaryMethodTests.cs | 111 ++++++++++ .../ThrowsAsOrdinaryMethodTests.cs | 100 +++++++++ .../ReturnsAsOrdinaryMethodTests.cs | 57 ++++- .../ReceivedAsOrdinaryMethodTests.cs | 25 ++- .../ForAsGenericMethodTests.cs | 7 + .../ForAsNonGenericMethodTests.cs | 67 +++++- .../SubstituteFactoryCreateMethodTests.cs | 49 ++++- ...bstituteFactoryCreatePartialMethodTests.cs | 36 +++- .../ReceivedAsOrdinaryMethodTests.cs | 38 +++- .../CodeFixProviders/CodeFixVerifier.cs | 11 +- .../CodeVerifier.cs | 14 +- .../ReturnsAsOrdinaryMethodTests.cs | 69 +++++- .../ThrowsAsOrdinaryMethodTests.cs | 71 ++++++- .../ReceivedAsOrdinaryMethodTests.cs | 55 ++++- 22 files changed, 1423 insertions(+), 37 deletions(-) diff --git a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteConstructorAnalysis.cs b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteConstructorAnalysis.cs index 107de8f4..294d3deb 100644 --- a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteConstructorAnalysis.cs +++ b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteConstructorAnalysis.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis; @@ -114,11 +115,11 @@ bool IsVisibleToProxy(IMethodSymbol symbol) (IsAccessible(symbol) || IsVisibleToProxy(symbol))).ToArray(); } - private ImmutableArray GetInvocationArguments(SubstituteContext substituteContext, TInvocationExpression invocationExpression) + private IEnumerable GetInvocationArguments(SubstituteContext substituteContext, TInvocationExpression invocationExpression) { var invocationOperation = (IInvocationOperation)substituteContext.SyntaxNodeAnalysisContext.SemanticModel.GetOperation(invocationExpression); - return invocationOperation.Arguments; + return invocationOperation.GetOrderedArgumentOperations(); } private ITypeSymbol[] TypeSymbols(IArrayCreationOperation arrayInitializerOperation) diff --git a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs index da4688ec..78fb79f5 100644 --- a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs +++ b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs @@ -2,6 +2,7 @@ using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Operations; +using NSubstitute.Analyzers.Shared.Extensions; namespace NSubstitute.Analyzers.Shared.DiagnosticAnalyzers { @@ -36,7 +37,7 @@ public ImmutableArray 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; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests.cs index c1b45677..91623943 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests/ConstructorArgumentsForInterfaceCodeFixProviderTests.cs @@ -30,6 +30,7 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(1, 2, 3); + var otherSubstitute = NSubstitute.Substitute.For(constructorArguments: new [] { 1, 2, 3 }); } } }"; @@ -46,6 +47,7 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(); + var otherSubstitute = NSubstitute.Substitute.For(); } } }"; @@ -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) }); } } }"; @@ -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) }); } } }"; @@ -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)}); } } }"; @@ -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)}); } } }"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests.cs index c74a5271..1eb8833f 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests/PartialSubstituteUsedForUnsupportedTypeCodeFixProviderTests.cs @@ -97,6 +97,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(System.Func)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new[] {typeof(System.Func)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new[] {typeof(System.Func)}); } } }"; @@ -110,6 +112,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(System.Func)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(System.Func)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(System.Func)}); } } }"; @@ -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)}); } } }"; @@ -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)}); } } }"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/AndDoesMethodPrecededByOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/AndDoesMethodPrecededByOrdinaryMethodTests.cs index 64c6d823..120ec3d3 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/AndDoesMethodPrecededByOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/AndDoesMethodPrecededByOrdinaryMethodTests.cs @@ -28,10 +28,20 @@ public void Test() {{ var substitute = NSubstitute.Substitute.For(); var returnedValue = SubstituteExtensions.Returns({call}, 1); + var otherValue = SubstituteExtensions.Returns(value: {call}, returnThis: 1); + var yetAnotherValue = SubstituteExtensions.Returns(returnThis: 1, value: {call}); returnedValue.{method}(callInfo => {{ {argAccess} }}); + otherValue.{method}(callInfo => + {{ + {argAccess} + }}); + yetAnotherValue.{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -64,6 +74,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -96,6 +114,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -127,6 +153,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -164,6 +198,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -210,6 +252,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -251,6 +301,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -297,6 +355,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -330,6 +396,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -363,6 +437,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -394,6 +476,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -439,6 +529,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -476,6 +574,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -512,6 +618,14 @@ public void Test() {{ {argAccess} }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + {argAccess} + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -541,6 +655,14 @@ public void Test() {{ [|callInfo[1]|] = 1; }}); + SubstituteExtensions.Returns(value: {call}, returnThis: 1).{method}(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: {call}).{method}(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); }} }} }}"; @@ -568,6 +690,14 @@ public void Test() {{ callInfo[0] = 1; }}); + SubstituteExtensions.Returns(value: substitute.Bar(ref value), returnThis: 1).{method}(callInfo => + {{ + callInfo[0] = 1; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: substitute.Bar(ref value)).{method}(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -595,6 +725,14 @@ public void Test() {{ callInfo[0] = 1; }}); + SubstituteExtensions.Returns(value: substitute.Bar(out value), returnThis: 1).{method}(callInfo => + {{ + callInfo[0] = 1; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: substitute.Bar(out value)).{method}(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -622,6 +760,14 @@ public void Test() {{ [|callInfo[1]|] = 1; }}); + SubstituteExtensions.Returns(value: substitute.Bar(out value), returnThis: 1).{method}(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: substitute.Bar(out value)).{method}(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); }} }} }}"; @@ -650,6 +796,14 @@ public void Test() {{ [|callInfo[0]|] = {right}; }}); + SubstituteExtensions.Returns(value: substitute.Bar(out value), returnThis: 1).{method}(callInfo => + {{ + [|callInfo[0]|] = {right}; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: substitute.Bar(out value)).{method}(callInfo => + {{ + [|callInfo[0]|] = {right}; + }}); }} }} }}"; @@ -679,6 +833,14 @@ public void Test() {{ callInfo[0] = {right}; }}); + SubstituteExtensions.Returns(value: substitute.Bar(out value), returnThis: 1).{method}(callInfo => + {{ + callInfo[0] = {right}; + }}); + SubstituteExtensions.Returns(returnThis: 1, value: substitute.Bar(out value)).{method}(callInfo => + {{ + callInfo[0] = {right}; + }}); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/DoMethodPrecededByOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/DoMethodPrecededByOrdinaryMethodTests.cs index 63363120..20219509 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/DoMethodPrecededByOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/DoMethodPrecededByOrdinaryMethodTests.cs @@ -28,10 +28,20 @@ public void Test() {{ var sub = NSubstitute.Substitute.For(); var returnValue = {method}(sub, substitute => {{var _ = {call}; }}); + var otherValue = {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}); + var yetAnotherValue = {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub); returnValue.Do(callInfo => {{ {argAccess} }}); + otherValue.Do(callInfo => + {{ + {argAccess} + }}); + yetAnotherValue.Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -64,6 +74,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -95,6 +113,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -126,6 +152,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -163,6 +197,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -209,6 +251,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -251,6 +301,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -297,6 +355,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -331,6 +397,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -364,6 +438,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -395,6 +477,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -441,6 +531,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -478,6 +576,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -515,6 +621,14 @@ public void Test() {{ {argAccess} }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + {argAccess} + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -544,6 +658,14 @@ public void Test() {{ [|callInfo[1]|] = 1; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = {call}; }}).Do(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); + {method}(substituteCall: substitute => {{var _ = {call}; }}, substitute: sub).Do(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); }} }} }}"; @@ -572,6 +694,14 @@ public void Test() {{ callInfo[0] = 1; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = substitute.Bar(ref value); }}).Do(callInfo => + {{ + callInfo[0] = 1; + }}); + {method}(substituteCall: substitute => {{var _ = substitute.Bar(ref value); }}, substitute: sub).Do(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -599,6 +729,14 @@ public void Test() {{ callInfo[0] = 1; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = substitute.Bar(out value); }}).Do(callInfo => + {{ + callInfo[0] = 1; + }}); + {method}(substituteCall: substitute => {{var _ = substitute.Bar(out value); }}, substitute: sub).Do(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -626,6 +764,14 @@ public void Test() {{ [|callInfo[1]|] = 1; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = substitute.Bar(out value); }}).Do(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); + {method}(substituteCall: substitute => {{var _ = substitute.Bar(out value); }}, substitute: sub).Do(callInfo => + {{ + [|callInfo[1]|] = 1; + }}); }} }} }}"; @@ -656,6 +802,14 @@ public void Test() {{ [|callInfo[0]|] = {right}; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = substitute.Bar(out value); }}).Do(callInfo => + {{ + [|callInfo[0]|] = {right}; + }}); + {method}(substituteCall: substitute => {{var _ = substitute.Bar(out value); }}, substitute: sub).Do(callInfo => + {{ + [|callInfo[0]|] = {right}; + }}); }} }} }}"; @@ -686,6 +840,14 @@ public void Test() {{ callInfo[0] = {right}; }}); + {method}(substitute: sub, substituteCall: substitute => {{var _ = substitute.Bar(out value); }}).Do(callInfo => + {{ + callInfo[0] = {right}; + }}); + {method}(substituteCall: substitute => {{var _ = substitute.Bar(out value); }}, substitute: sub).Do(callInfo => + {{ + callInfo[0] = {right}; + }}); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index f1be71cf..324edc00 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -33,6 +33,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: returnedValue, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: returnedValue); }} }} }}"; @@ -66,6 +76,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -99,6 +119,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -131,6 +161,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -169,6 +209,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -216,6 +266,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -258,6 +318,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -305,6 +375,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -339,6 +419,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -373,6 +463,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -405,6 +505,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -451,6 +561,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -489,6 +609,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -526,6 +656,16 @@ public void Test() {argAccess} return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}); + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}); }} }} }}"; @@ -556,6 +696,16 @@ public void Test() [|callInfo[1]|] = 1; return 1; }}); + {method}(value: {call}, returnThis: callInfo => + {{ + [|callInfo[1]|] = 1; + return 1; + }}); + {method}(returnThis: callInfo => + {{ + [|callInfo[1]|] = 1; + return 1; + }}, value: {call}); }} }} }}"; @@ -584,6 +734,16 @@ public void Test() callInfo[0] = 1; return 1; }}); + {method}(value: substitute.Bar(ref value), returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}); + {method}(returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}, value: substitute.Bar(ref value)); }} }} }}"; @@ -612,6 +772,16 @@ public void Test() callInfo[0] = 1; return 1; }}); + {method}(value: substitute.Bar(out value), returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}); + {method}(returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -640,6 +810,16 @@ public void Test() [|callInfo[1]|] = 1; return 1; }}); + {method}(value: substitute.Bar(out value), returnThis:callInfo => + {{ + [|callInfo[1]|] = 1; + return 1; + }}); + {method}(returnThis:callInfo => + {{ + [|callInfo[1]|] = 1; + return 1; + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -669,6 +849,16 @@ public void Test() [|callInfo[0]|] = {right}; return 1; }}); + {method}(value: substitute.Bar(out value), returnThis: callInfo => + {{ + [|callInfo[0]|] = {right}; + return 1; + }}); + {method}(returnThis: callInfo => + {{ + [|callInfo[0]|] = {right}; + return 1; + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -699,6 +889,16 @@ public void Test() callInfo[0] = {right}; return 1; }}); + {method}(value: substitute.Bar(out value), returnThis: callInfo => + {{ + callInfo[0] = {right}; + return 1; + }}); + {method}(returnThis: callInfo => + {{ + callInfo[0] = {right}; + return 1; + }}, value: substitute.Bar(out value)); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index cc8c623b..4ea8448b 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -34,6 +34,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: returnedValue, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: returnedValue); }} }} }}"; @@ -67,6 +77,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -101,6 +121,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -134,6 +164,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -173,6 +213,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -220,6 +270,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -263,6 +323,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -310,6 +380,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -345,6 +425,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -380,6 +470,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -413,6 +513,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -460,6 +570,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -500,6 +620,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -540,6 +670,16 @@ public void Test() {argAccess} return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -572,6 +712,16 @@ public void Test() [|callInfo[1]|] = 1; return new Exception(); }}); + {method}(value: {call}, createException: callInfo => + {{ + [|callInfo[1]|] = 1; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + [|callInfo[1]|] = 1; + return new Exception(); + }}, value: {call}); }} }} }}"; @@ -603,6 +753,16 @@ public void Test() callInfo[0] = 1; return new Exception(); }}); + {method}(value: substitute.Bar(ref value), createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}, value: substitute.Bar(ref value)); }} }} }}"; @@ -633,6 +793,16 @@ public void Test() callInfo[0] = 1; return new Exception(); }}); + {method}(value: substitute.Bar(out value), createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -663,6 +833,16 @@ public void Test() [|callInfo[1]|] = 1; return new Exception(); }}); + {method}(value: substitute.Bar(out value), createException: callInfo => + {{ + [|callInfo[1]|] = 1; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + [|callInfo[1]|] = 1; + return new Exception(); + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -694,6 +874,16 @@ public void Test() [|callInfo[0]|] = {right}; return new Exception(); }}); + {method}(value: substitute.Bar(out value), createException: callInfo => + {{ + [|callInfo[0]|] = {right}; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + [|callInfo[0]|] = {right}; + return new Exception(); + }}, value: substitute.Bar(out value)); }} }} }}"; @@ -726,6 +916,16 @@ public void Test() callInfo[0] = {right}; return new Exception(); }}); + {method}(value: substitute.Bar(out value), createException: callInfo => + {{ + callInfo[0] = {right}; + return new Exception(); + }}); + {method}(createException: callInfo => + {{ + callInfo[0] = {right}; + return new Exception(); + }}, value: substitute.Bar(out value)); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index 7e14a005..b81f1292 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -36,6 +36,26 @@ public void Test() {{ {andDoesArgAccess} }}); + + {method}(value: {call}, returnThis: callInfo => 1, + returnThese: callInfo => + {{ + {previousCallArgAccess} + return 1; + }}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + + {method}(returnThese: callInfo => + {{ + {previousCallArgAccess} + return 1; + }}, value: {call}, + returnThis: callInfo => 1).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; @@ -66,10 +86,33 @@ public void Test() return 1; }}); + var otherCall = {method}(value: substitute.Bar(Arg.Any()), returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}); + + var yetAnotherCall = {method}(returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}, value: substitute.Bar(Arg.Any())); + + configuredCall.AndDoes(callInfo => {{ callInfo[0] = 1; }}); + + otherCall.AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); + + yetAnotherCall.AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -145,6 +188,24 @@ public void Test() {{ {andDoesArgAccess} }}); + + {method}(value: {call}, returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + + {method}(returnThis: callInfo => + {{ + callInfo[0] = 1; + return 1; + }}, value: {call}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; @@ -181,6 +242,24 @@ public void Test() {{ {argAccess} }}); + + {method}(value: {call}, returnThis: callInfo => + {{ + {argAccess} + return 1; + }}).AndDoes(callInfo => + {{ + {argAccess} + }}); + + {method}(returnThis: callInfo => + {{ + {argAccess} + return 1; + }}, value: {call}).AndDoes(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -215,6 +294,28 @@ public void Test() {{ callInfo[0] = 1; }}); + + {method}(value: substitute.Bar(Arg.Any()), returnThis: callInfo => + {{ + callInfo.Args()[0] = 1; + callInfo.ArgTypes()[0] = typeof(int); + ((byte[])callInfo[0])[0] = 1; + return 1; + }}).AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); + + {method}(returnThis: callInfo => + {{ + callInfo.Args()[0] = 1; + callInfo.ArgTypes()[0] = typeof(int); + ((byte[])callInfo[0])[0] = 1; + return 1; + }}, value: substitute.Bar(Arg.Any())).AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -247,6 +348,16 @@ public void Test() {{ {andDoesArgAccess} }}); + + {method}(value: {call}, returnThis: 1).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + + {method}(returnThis: 1, value: {call}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index dbae0136..8cbd7aa3 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ConflictingArgumentAssignmentsAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -36,6 +36,24 @@ public void Test() {{ {andDoesArgAccess} }}); + + {method}(value: {call}, createException: callInfo => + {{ + {previousCallArgAccess} + return new Exception(); + }}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + + {method}(createException: callInfo => + {{ + {previousCallArgAccess} + return new Exception(); + }}, value: {call}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; @@ -67,10 +85,30 @@ public void Test() return new Exception(); }}); + var otherCall = {method}(value: substitute.Bar(Arg.Any()), createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}); + + var yetAnotherCall = {method}(createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}, value: substitute.Bar(Arg.Any())); + configuredCall.AndDoes(callInfo => {{ callInfo[0] = 1; }}); + otherCall.AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); + yetAnotherCall.AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -148,6 +186,22 @@ public void Test() {{ {andDoesArgAccess} }}); + {method}(value: {call}, createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + {method}(createException: callInfo => + {{ + callInfo[0] = 1; + return new Exception(); + }}, value: {call}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; @@ -185,6 +239,24 @@ public void Test() {{ {argAccess} }}); + + {method}(value: {call}, createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}).AndDoes(callInfo => + {{ + {argAccess} + }}); + + {method}(createException: callInfo => + {{ + {argAccess} + return new Exception(); + }}, value: {call}).AndDoes(callInfo => + {{ + {argAccess} + }}); }} }} }}"; @@ -220,6 +292,26 @@ public void Test() {{ callInfo[0] = 1; }}); + {method}(value: substitute.Bar(Arg.Any()), createException: callInfo => + {{ + callInfo.Args()[0] = 1; + callInfo.ArgTypes()[0] = typeof(int); + ((byte[])callInfo[0])[0] = 1; + return new Exception(); + }}).AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); + {method}(createException: callInfo => + {{ + callInfo.Args()[0] = 1; + callInfo.ArgTypes()[0] = typeof(int); + ((byte[])callInfo[0])[0] = 1; + return new Exception(); + }}, value: substitute.Bar(Arg.Any())).AndDoes(callInfo => + {{ + callInfo[0] = 1; + }}); }} }} }}"; @@ -253,6 +345,14 @@ public void Test() {{ {andDoesArgAccess} }}); + {method}(value: {call}, ex: new Exception()).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); + {method}(ex: new Exception(), value: {call}).AndDoes(callInfo => + {{ + {andDoesArgAccess} + }}); }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReEntrantReturnsSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReEntrantReturnsSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index 1316b290..48b5bf9f 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReEntrantReturnsSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReEntrantReturnsSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using MoreLinq; using NSubstitute.Analyzers.Tests.Shared.Extensibility; using NSubstitute.Analyzers.Tests.Shared.Extensions; @@ -32,6 +33,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), [|ReturnThis()|], [|OtherReturn()|]); + {method}(value: substitute.Bar(), returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|]); + {method}(returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|], value: substitute.Bar()); }} @@ -55,7 +58,7 @@ private int OtherReturn() { $"{plainMethodName}() is set with a method that itself calls Returns. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => ReturnThis()).", $"{plainMethodName}() is set with a method that itself calls Returns. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => OtherReturn())." - }; + }.Repeat(3).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -85,6 +88,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), [|ReturnThis()|], [|OtherReturn()|]); + {method}(value: substitute.Bar(), returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|]); + {method}(returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|], value: substitute.Bar()); }} @@ -108,7 +113,7 @@ private int OtherReturn() { $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => ReturnThis()).", $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => OtherReturn())." - }; + }.Repeat(3).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -138,6 +143,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), [|ReturnThis()|], [|OtherReturn()|]); + {method}(value: substitute.Bar(), returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|]); + {method}(returnThis: [|ReturnThis()|], returnThese: [|OtherReturn()|], value: substitute.Bar()); }} @@ -160,7 +167,7 @@ private int OtherReturn() { $"{plainMethodName}() is set with a method that itself calls Do. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => ReturnThis()).", $"{plainMethodName}() is set with a method that itself calls Do. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => OtherReturn())." - }; + }.Repeat(3).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -225,7 +232,7 @@ private int OtherNestedReturnThis() $"{plainMethodName}() is set with a method that itself calls {plainMethodName}. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => ReturnThis()).", $"{plainMethodName}() is set with a method that itself calls {plainMethodName}. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => OtherReturn()).", $"{plainMethodName}() is set with a method that itself calls {plainMethodName}. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => NestedReturnThis())." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -256,6 +263,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), x => ReturnThis()); + {method}(value: substitute.Bar(), returnThis: x => ReturnThis()); + {method}(returnThis: x => ReturnThis(), value: substitute.Bar()); }} private int ReturnThis() @@ -311,6 +320,8 @@ public void Test() {localVariable} var substitute = Substitute.For(); {method}(substitute.Bar(), bar); + {method}(value: substitute.Bar(), returnThis: bar); + {method}(returnThis: bar, value: substitute.Bar()); }} public IBar Bar() @@ -348,6 +359,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), {rootCall}); + {method}(value: substitute.Bar(), returnThis: {rootCall}); + {method}(returnThis: {rootCall}, value: substitute.Bar()); }} private int ReturnThis() @@ -405,6 +418,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), {rootCall}); + {method}(value: substitute.Bar(), returnThis: {rootCall}); + {method}(returnThis: {rootCall}, value: substitute.Bar()); }} private int ReturnThis() @@ -456,6 +471,7 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), {firstReturn}, {secondReturn}); + {method}(value: substitute.Bar(), returnThis: {firstReturn}, returnThese: {secondReturn}); }} @@ -507,6 +523,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), [|FooBar.ReturnThis()|]); + {method}(value: substitute.Bar(), returnThis: [|FooBar.ReturnThis()|]); + {method}(returnThis: [|FooBar.ReturnThis()|], value: substitute.Bar()); }} }} }}"; @@ -550,6 +568,8 @@ public async Task Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), [|await ReturnThis()|]); + {method}(value: substitute.Bar(), returnThis: [|await ReturnThis()|]); + {method}(returnThis: [|await ReturnThis()|], value: substitute.Bar()); }} private async Task ReturnThis() @@ -584,6 +604,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), 1, {reEntrantArrayCall}); + {method}(value: substitute.Bar(), returnThis: 1, returnThese: {reEntrantArrayCall}); + {method}(returnThis: 1, returnThese: {reEntrantArrayCall}, value: substitute.Bar()); }} private int ReturnThis() @@ -622,6 +644,7 @@ public void Test() var substitute = Substitute.For(); var array = new[] {{ ReturnThis() }}; {method}(substitute.Bar(), 1, array); + {method}(value: substitute.Bar(), returnThis: 1, returnThese: array); }} private int ReturnThis() @@ -673,6 +696,8 @@ public void Test() {{ var substitute = NSubstitute.Substitute.For(); {method}(substitute.FooBar(), typeof({type})); + {method}(value: substitute.FooBar(), returnThis: typeof({type})); + {method}(returnThis: typeof({type}), value: substitute.FooBar()); }} }} }}"; @@ -704,6 +729,8 @@ public void Test() foreach (var fooBar in new FooBar[0]) {{ {method}(substitute.Bar(), fooBar.Value); + {method}(value: substitute.Bar(), returnThis: fooBar.Value); + {method}(returnThis: fooBar.Value, value: substitute.Bar()); }} }} }} @@ -731,10 +758,20 @@ public void Test() foreach (var value in Enumerable.Empty()) {{ {method}(firstEnumerator.Current, value + 1); + {method}(value: firstEnumerator.Current, returnThis: value + 1); + {method}(returnThis: value + 1, value: firstEnumerator.Current); {method}(firstEnumerator.Current, value + 1); + {method}(value: firstEnumerator.Current, returnThis: value + 1); + {method}(returnThis: value + 1, value: firstEnumerator.Current); {method}(secondEnumerator.Current, value + 1); + {method}(value: secondEnumerator.Current, returnThis: value + 1); + {method}(returnThis: value + 1, value: secondEnumerator.Current); {method}(thirdEnumerator.Current, value + 1); + {method}(value: thirdEnumerator.Current, returnThis: value + 1); + {method}(returnThis: value + 1, value: thirdEnumerator.Current); {method}(fourthEnumerator.Current, value + 1); + {method}(value: fourthEnumerator.Current, returnThis: value + 1); + {method}(returnThis: value + 1, value: fourthEnumerator.Current); }} }} }} @@ -764,6 +801,8 @@ public void Test() var secondSubstitute = Substitute.For(); {method}(secondSubstitute.Id, [|firstSubstitute.Id|]); + {method}(value: secondSubstitute.Id, returnThis: [|firstSubstitute.Id|]); + {method}(returnThis: [|firstSubstitute.Id|], value: secondSubstitute.Id); }} }} }}"; @@ -796,6 +835,8 @@ public void Test() {{ var secondSubstitute = Substitute.For(); {method}(secondSubstitute.Id, [|firstSubstitute.Id|]); + {method}(value: secondSubstitute.Id, returnThis: [|firstSubstitute.Id|]); + {method}(returnThis: [|firstSubstitute.Id|], value: secondSubstitute.Id); }} }} }}"; @@ -825,6 +866,8 @@ public void Test() {{ var secondSubstitute = Substitute.For(); {method}(secondSubstitute.Id, [|firstSubstitute.Id|]); + {method}(value: secondSubstitute.Id, returnThis: [|firstSubstitute.Id|]); + {method}(returnThis: [|firstSubstitute.Id|], value: secondSubstitute.Id); }} }} }}"; @@ -859,7 +902,11 @@ public void Test() var value = fourthSubstitute.Id; {method}(secondSubstitute.Id, firstSubstitute.Id); + {method}(value: secondSubstitute.Id, returnThis: firstSubstitute.Id); + {method}(returnThis: firstSubstitute.Id, value: secondSubstitute.Id); {method}(secondSubstitute.Id, value); + {method}(value: secondSubstitute.Id, returnThis: value); + {method}(returnThis: value, value: secondSubstitute.Id); }} }} }}"; @@ -890,6 +937,8 @@ public void Test() {{ var substitute = Substitute.For(); {method}(substitute.Bar(), _ => 1, new Func[] {{ _ => OtherReturn() }}); + {method}(value: substitute.Bar(), returnThis: _ => 1, returnThese: new Func[] {{ _ => OtherReturn() }}); + {method}(returnThis: _ => 1, returnThese: new Func[] {{ _ => OtherReturn() }}, value: substitute.Bar()); }} private int OtherReturn() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReceivedInReceivedInOrderAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReceivedInReceivedInOrderAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs index c813b48b..dbf15118 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReceivedInReceivedInOrderAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/ReceivedInReceivedInOrderAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs @@ -5,17 +5,31 @@ namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.ReceivedInR { [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity: Quantity.None(), substitute: substitute)", "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute: substitute)", "SubstituteExtensions.Received(substitute)", - "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", - "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", + "SubstituteExtensions.Received(substitute: substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity: Quantity.None(), substitute: substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute: substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute: substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute: substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute: substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute: substitute)")] public class ReceivedAsOrdinaryMethodTests : ReceivedInReceivedInOrderDiagnosticVerifier { public override async Task ReportsDiagnostic_WhenUsingReceivedLikeMethodInReceivedInOrderBlock_ForMethod(string method) @@ -237,7 +251,10 @@ private static string GetPlainMethodName(string methodName) { var plainMethodName = methodName.Replace("", string.Empty) .Replace("(substitute, Quantity.None())", string.Empty) - .Replace("(substitute)", string.Empty); + .Replace("(substitute: substitute, requiredQuantity: Quantity.None())", string.Empty) + .Replace("(requiredQuantity: Quantity.None(), substitute: substitute)", string.Empty) + .Replace("(substitute)", string.Empty) + .Replace("(substitute: substitute)", string.Empty); var planMethodNameWithoutNamespace = plainMethodName.Replace("ReceivedExtensions.", string.Empty) diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsGenericMethodTests.cs index d17cfa38..85963e1b 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsGenericMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsGenericMethodTests.cs @@ -44,6 +44,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(1)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: 1)|]; } } }"; @@ -84,6 +85,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For>(1)|]; + var otherSubstitute = [|NSubstitute.Substitute.For>(constructorArguments: 1)|]; } } }"; @@ -213,6 +215,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(1)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: 1)|]; } } }"; @@ -363,6 +366,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(1, 2, 3)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(new [] { 1, 2, 3 })|]; } } }"; @@ -388,6 +392,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(1)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: 1)|]; } } }"; @@ -413,6 +418,7 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(1)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: 1)|]; } } }"; @@ -509,6 +515,7 @@ public class FooTests public void Test() {{ var substitute = [|NSubstitute.Substitute.For({invocationValues})|]; + var otherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: {invocationValues})|]; }} }} }}"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsNonGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsNonGenericMethodTests.cs index f6596c82..837634c4 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsNonGenericMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/ForAsNonGenericMethodTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; +using NSubstitute.Analyzers.Tests.Shared.Extensions; using Xunit; namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests @@ -21,6 +23,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) }); } } }"; @@ -44,6 +48,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(IFoo) }, new object[] { }); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo) }, constructorArguments: new object[] { }); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: new object[] { }, typesToProxy: new [] { typeof(IFoo) }); } } }"; @@ -67,6 +73,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) })|]; } } }"; @@ -89,6 +97,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(Func) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Func) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Func) }); } } }"; @@ -107,10 +117,23 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Func) }, new object[] { 1 })|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Func) }, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(Func) })|]; } } }"; - await VerifyDiagnostic(source, SubstituteConstructorArgumentsForDelegateDescriptor, "Can not provide constructor arguments when substituting for a delegate. Use NSubstitute.Substitute.For(new [] { typeof(Func) },null) instead."); + var textParserResult = TextParser.GetSpans(source); + + // TODO + var diagnosticMessages = new[] + { + "Can not provide constructor arguments when substituting for a delegate. Use NSubstitute.Substitute.For(new [] { typeof(Func) },null) instead.", + "Can not provide constructor arguments when substituting for a delegate. Use NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Func) },null) instead.", + "Can not provide constructor arguments when substituting for a delegate. Use NSubstitute.Substitute.For(constructorArguments: new object[] { 1 },null)" + }; + + var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(SubstituteConstructorArgumentsForDelegateDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); + await VerifyDiagnostic(textParserResult.Text, diagnostics); } [Theory] @@ -136,6 +159,8 @@ public void Test() {{ var bar = new Bar(); var substitute = NSubstitute.Substitute.For({proxyExpression}, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: {proxyExpression}, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: {proxyExpression}); }} }} }}"; @@ -163,6 +188,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo), typeof(Bar) }, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo), typeof(Bar) }, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo), typeof(Bar) })|]; } } }"; @@ -185,6 +212,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(Foo), typeof(Foo) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo), typeof(Foo) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo), typeof(Foo) }); } } }"; @@ -212,6 +241,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(IFoo), typeof(IBar) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo), typeof(IBar) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(IFoo), typeof(IBar) }); } } }"; @@ -239,6 +270,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(IFoo), typeof(Bar) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo), typeof(Bar) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(IFoo), typeof(Bar) }); } } }"; @@ -266,6 +299,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(IFoo), typeof(Bar) }, new object[] { 1 })|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(IFoo), typeof(Bar) }, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(IFoo), typeof(Bar) })|]; } } }"; @@ -292,6 +327,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -316,6 +353,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -340,6 +379,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -366,6 +407,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(Foo) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) }); } } }"; @@ -392,6 +435,8 @@ public class FooTests public void Test() { var substitute = NSubstitute.Substitute.For(new [] { typeof(Foo) }, null); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) }); } } }"; @@ -417,6 +462,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, new object[] { 1, 2, 3 })|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: new object[] { 1, 2, 3 })|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] { 1, 2, 3 }, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -442,6 +489,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, new object[] { 1 })|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -467,6 +516,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, new object[] { 1 })|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -488,6 +539,8 @@ public class FooTests public void Test() { var substitute = [|NSubstitute.Substitute.For(new [] { typeof(Foo) }, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] { typeof(Foo) }, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(Foo) })|]; } } }"; @@ -510,6 +563,8 @@ public class FooTests public void Test() {{ var substitute = NSubstitute.Substitute.For(new [] {{ typeof(Foo) }}, null ); + var otherSubstitute = NSubstitute.Substitute.For(typesToProxy: new [] {{ typeof(Foo) }}, constructorArguments: null ); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] {{ typeof(Foo) }}); }} }} }}"; @@ -532,6 +587,8 @@ public class FooTests public void Test() {{ var substitute = [|NSubstitute.Substitute.For(new [] {{ typeof(Foo) }}, null)|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] {{ typeof(Foo) }}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: null, typesToProxy: new [] {{ typeof(Foo) }})|]; }} }} }}"; @@ -562,6 +619,8 @@ public class FooTests public void Test() {{ var substitute = [|NSubstitute.Substitute.For(new [] {{ typeof(Foo) }}, new object[] {{{invocationValues}}})|]; + var otherSubstitute = [|NSubstitute.Substitute.For(typesToProxy: new [] {{ typeof(Foo) }}, constructorArguments: new object[] {{{invocationValues}}})|]; + var yetAnotherSubstitute = [|NSubstitute.Substitute.For(constructorArguments: new object[] {{{invocationValues}}}, typesToProxy: new [] {{ typeof(Foo) }})|]; }} }} }}"; @@ -596,7 +655,7 @@ public class FooTests {{ public void Test() {{ - var substitute = NSubstitute.Substitute.For(new [] {{ typeof(Foo) }}, {invocationValues}); + var yetAnotherSubstitute = NSubstitute.Substitute.For(constructorArguments: {invocationValues}, typesToProxy: new [] {{ typeof(Foo) }}); }} }} }}"; @@ -613,6 +672,8 @@ public class FooTests { public T Foo() where T : class { + Substitute.For(typesToProxy: new [] { typeof(T)}, constructorArguments: null); + Substitute.For(constructorArguments: null, typesToProxy: new [] { typeof(T)}); return (T)Substitute.For(new [] { typeof(T)}, null); } } diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreateMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreateMethodTests.cs index d9404fb4..ae7e1771 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreateMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreateMethodTests.cs @@ -22,6 +22,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)}); } } }"; @@ -46,6 +48,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)})|]; } } }"; @@ -70,6 +74,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Func)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Func)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Func)}); } } }"; @@ -93,6 +99,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Func)}, new object[] { 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Func)}, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[] { 1 }, typesToProxy: new[] {typeof(Func)})|]; } } }"; @@ -119,6 +127,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new [] { typeof(Foo), typeof(Bar)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new [] { typeof(Foo), typeof(Bar)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new [] { typeof(Foo), typeof(Bar)})|]; } } }"; @@ -141,6 +151,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new [] { typeof(Foo), typeof(Foo)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new [] { typeof(Foo), typeof(Foo)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new [] { typeof(Foo), typeof(Foo)}); } } }"; @@ -168,6 +180,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new [] { typeof(IFoo), typeof(IBar)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new [] { typeof(IFoo), typeof(IBar)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new [] { typeof(IFoo), typeof(IBar)}); } } @@ -197,6 +211,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new [] { typeof(IFoo), typeof(Bar) }, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new [] { typeof(IFoo), typeof(Bar) }, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new [] { typeof(IFoo), typeof(Bar) }); } } }"; @@ -224,6 +240,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new [] { typeof(IFoo), typeof(Bar) }, new object[] { 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new [] { typeof(IFoo), typeof(Bar) }, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[] { 1 }, typesToProxy: new [] { typeof(IFoo), typeof(Bar) })|]; } } }"; @@ -249,6 +267,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)})|]; } } }"; @@ -273,6 +293,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)})|]; } } }"; @@ -297,6 +319,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)})|]; } } }"; @@ -323,6 +347,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)}); } } }"; @@ -349,6 +375,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)}); } } }"; @@ -374,6 +402,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, new object[]{ 1, 2, 3})|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: new object[]{ 1, 2, 3})|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[]{ 1, 2, 3}, typesToProxy: new[] {typeof(Foo)})|]; } } }"; @@ -400,6 +430,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, new object[]{ 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: new object[]{ 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[]{ 1 }, typesToProxy: new[] {typeof(Foo)})|]; } } }"; @@ -427,6 +459,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, new object[]{ 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: new object[]{ 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[]{ 1 }, typesToProxy: new[] {typeof(Foo)} )|]; } } }"; @@ -449,6 +483,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {typeof(Foo)})|]; } } } @@ -474,6 +510,8 @@ public class FooTests public void Test() {{ var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {{typeof(Foo)}}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {{typeof(Foo)}}); }} }} }}"; @@ -498,6 +536,8 @@ public class FooTests public void Test() {{ var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {{typeof(Foo)}}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new[] {{typeof(Foo)}})|]; }} }} }}"; @@ -530,6 +570,8 @@ public class FooTests public void Test() {{ var substitute = [|SubstitutionContext.Current.SubstituteFactory.Create(new[] {{typeof(Foo)}}, new object[] {{{invocationValues}}})|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: new object[] {{{invocationValues}}})|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: new object[] {{{invocationValues}}}, typesToProxy: new[] {{typeof(Foo)}})|]; }} }} }}"; @@ -567,6 +609,8 @@ public class FooTests public void Test() {{ var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {{typeof(Foo)}}, {invocationValues}); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: {invocationValues}); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: {invocationValues}, typesToProxy: new[] {{typeof(Foo)}}); }} }} }}"; @@ -586,7 +630,10 @@ public class FooTests { public T Foo() where T : class { - return (T) SubstitutionContext.Current.SubstituteFactory.Create(new Type[] {typeof(T)}, null); + var substitute = (T)SubstitutionContext.Current.SubstituteFactory.Create(new Type[] {typeof(T)}, null); + var otherSubstitute = (T)SubstitutionContext.Current.SubstituteFactory.Create(typesToProxy: new Type[] {typeof(T)}, constructorArguments: null); + var yetAnotherSubstitute = (T)SubstitutionContext.Current.SubstituteFactory.Create(constructorArguments: null, typesToProxy: new Type[] {typeof(T)}); + return substitute; } } }"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreatePartialMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreatePartialMethodTests.cs index b70d5cd0..2c34cefd 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreatePartialMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/SubstituteAnalyzerTests/SubstituteFactoryCreatePartialMethodTests.cs @@ -22,6 +22,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(IFoo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(IFoo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(IFoo)})|]; } } }"; @@ -45,6 +47,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Func)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Func)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Func)})|]; } } }"; @@ -71,6 +75,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -96,6 +102,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -121,6 +129,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -148,6 +158,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)}); } } }"; @@ -175,6 +187,8 @@ public class FooTests public void Test() { var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)}); } } }"; @@ -201,6 +215,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, new object[] { 1, 2, 3})|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: new object[] { 1, 2, 3})|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: new object[] { 1, 2, 3}, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -227,6 +243,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, new object[] { 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: new object[] { 1 }, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -254,6 +272,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, new object[] { 1 })|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: new object[] { 1 })|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: new object[] { 1 }, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -277,6 +297,8 @@ public class FooTests public void Test() { var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] { typeof(Foo)}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] { typeof(Foo)}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] { typeof(Foo)})|]; } } }"; @@ -302,6 +324,8 @@ public class FooTests public void Test() {{ var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] {{ typeof(Foo)}}, null); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] {{ typeof(Foo)}}, constructorArguments: null); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] {{ typeof(Foo)}}); }} }} }}"; @@ -327,6 +351,8 @@ public class FooTests public void Test() {{ var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] {{ typeof(Foo)}}, null)|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] {{ typeof(Foo)}}, constructorArguments: null)|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] {{ typeof(Foo)}})|]; }} }} }}"; @@ -359,6 +385,8 @@ public class FooTests public void Test() {{ var substitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {{typeof(Foo)}}, new object[] {{{invocationValues}}})|]; + var otherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: new object[] {{{invocationValues}}})|]; + var yetAnotherSubstitute = [|SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: new object[] {{{invocationValues}}}, typesToProxy: new[] {{typeof(Foo)}})|]; }} }} }}"; @@ -396,6 +424,8 @@ public class FooTests public void Test() {{ var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {{typeof(Foo)}}, {invocationValues}); + var otherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new[] {{typeof(Foo)}}, constructorArguments: {invocationValues}); + var yetAnotherSubstitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: {invocationValues}, typesToProxy: new[] {{typeof(Foo)}}); }} }} }}"; @@ -415,7 +445,11 @@ public class FooTests { public T Foo() where T : class { - return (T) SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] {typeof(T)}, null); + var substitute = (T)SubstitutionContext.Current.SubstituteFactory.CreatePartial(new Type[] {typeof(T)}, null); + var otherSubstitute = (T)SubstitutionContext.Current.SubstituteFactory.CreatePartial(typesToProxy: new Type[] {typeof(T)}, constructorArguments: null); + var yetAnotherSubstitute = (T)SubstitutionContext.Current.SubstituteFactory.CreatePartial(constructorArguments: null, typesToProxy: new Type[] {typeof(T)}); + + return substitute; } } }"; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/UnusedReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/UnusedReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs index dfc82a22..a773f129 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/UnusedReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/UnusedReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs @@ -5,17 +5,31 @@ namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.UnusedRecei { [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity: Quantity.None(), substitute: substitute)", "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute: substitute)", "SubstituteExtensions.Received(substitute)", - "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", - "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", + "SubstituteExtensions.Received(substitute: substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity: Quantity.None(), substitute: substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute: substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute: substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute: substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute: substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute: substitute)")] public class ReceivedAsOrdinaryMethodTests : UnusedReceivedDiagnosticVerifier { public override async Task ReportDiagnostics_WhenUsedWithoutMemberCall(string method) @@ -130,17 +144,33 @@ public void Test() [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity: Quantity.None(), substitute: substitute)", "ReceivedExtensions.Received>(substitute, Quantity.None())", + "ReceivedExtensions.Received>(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.Received>(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute: substitute)", "SubstituteExtensions.Received>(substitute)", + "SubstituteExtensions.Received>(substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute: substitute)", "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity: Quantity.None(), substitute: substitute)", "ReceivedExtensions.ReceivedWithAnyArgs>(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs>(substitute: substitute, requiredQuantity: Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs>(requiredQuantity: Quantity.None(), substitute: substitute)", "SubstituteExtensions.ReceivedWithAnyArgs>(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs>(substitute: substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute: substitute)", "SubstituteExtensions.DidNotReceive>(substitute)", + "SubstituteExtensions.DidNotReceive>(substitute: substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs>(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute: substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs>(substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs>(substitute: substitute)")] public override async Task ReportNoDiagnostics_WhenUsedWithInvokingDelegate(string method) { var source = $@"using System; diff --git a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs index 6e716ef2..e5a24ecc 100644 --- a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs +++ b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs @@ -28,6 +28,7 @@ protected async Task VerifyFix(string oldSource, string newSource, int? codeFixI { using (var workspace = new AdhocWorkspace()) { + codeFixIndex ??= 0; var project = AddProject(workspace.CurrentSolution, oldSource); var document = project.Documents.Single(); var compilation = await project.GetCompilationAsync(); @@ -54,12 +55,18 @@ protected async Task VerifyFix(string oldSource, string newSource, int? codeFixI break; } - document = await document.ApplyCodeAction(actions[codeFixIndex ?? 0]); + document = await document.ApplyCodeAction(actions[codeFixIndex.Value]); compilation = await document.Project.GetCompilationAsync(); compilerDiagnostics = compilation.GetDiagnostics(); - VerifyNoCompilerDiagnosticErrors(compilerDiagnostics); + var compilationErrorDiagnostics = GetCompilationErrorDiagnostics(compilerDiagnostics); + + if (compilationErrorDiagnostics.Any()) + { + Execute.Assertion.Fail( + $"Fix {codeFixIndex} for diagnostic {analyzerDiagnostics[i].ToString()} introduced compilation error(s): {compilationErrorDiagnostics.ToDebugString()} New document:{Environment.NewLine}{await document.ToFullString()}"); + } analyzerDiagnostics = await compilation.GetSortedAnalyzerDiagnostics( DiagnosticAnalyzer, diff --git a/tests/NSubstitute.Analyzers.Tests.Shared/CodeVerifier.cs b/tests/NSubstitute.Analyzers.Tests.Shared/CodeVerifier.cs index def02658..9d4dfae3 100644 --- a/tests/NSubstitute.Analyzers.Tests.Shared/CodeVerifier.cs +++ b/tests/NSubstitute.Analyzers.Tests.Shared/CodeVerifier.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Collections.Immutable; using System.Globalization; using System.Linq; @@ -36,14 +37,21 @@ protected Project AddProject(Solution solution, string[] sources) protected static void VerifyNoCompilerDiagnosticErrors(ImmutableArray diagnostics) { - var compilationErrorDiagnostics = diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error) - .ToList(); + var compilationErrorDiagnostics = GetCompilationErrorDiagnostics(diagnostics); if (compilationErrorDiagnostics.Any()) { Execute.Assertion.Fail($"Compilation failed. Errors encountered {compilationErrorDiagnostics.ToDebugString()}"); } } + + protected static IReadOnlyList GetCompilationErrorDiagnostics(ImmutableArray diagnostics) + { + var compilationErrorDiagnostics = diagnostics.Where(diagnostic => + diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error) + .ToList(); + + return compilationErrorDiagnostics; + } } } \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index 78249005..5dcf1e29 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using MoreLinq.Extensions; using NSubstitute.Analyzers.Shared; using NSubstitute.Analyzers.Shared.Settings; using NSubstitute.Analyzers.Tests.Shared.Extensibility; @@ -28,6 +29,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}([|substitute.Bar()|], 1) + {method}(value:= [|substitute.Bar()|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.Bar()|]) End Sub End Class End Namespace @@ -47,6 +50,8 @@ Namespace MyNamespace Public Class FooTests Public Sub Test() {method}([|{literal}|], {literal}) + {method}(value:= [|{literal}|], returnThis:= {literal}) + {method}(returnThis:= {literal}, value:= [|{literal}|]) End Sub End Class End Namespace @@ -71,6 +76,8 @@ Public Class FooTests Public Sub Test() {method}([|Foo.Bar()|], 1) + {method}(value:= [|Foo.Bar()|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|Foo.Bar()|]) End Sub End Class End Namespace @@ -96,6 +103,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(), 1) + {method}(value:= substitute.Bar(), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar()) End Sub End Class End Namespace @@ -129,6 +138,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo2)() {method}(substitute.Bar(), 1) + {method}(value:= substitute.Bar(), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar()) End Sub End Class End Namespace @@ -155,6 +166,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim returnValue = substitute.Bar() {method}(returnValue, 1) + {method}(value:= returnValue, returnThis:= 1) + {method}(returnThis:= 1, value:= returnValue) End Sub End Class End Namespace @@ -174,6 +187,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Func(Of Integer))() {method}(substitute(), 1) + {method}(value:= substitute(), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute()) End Sub End Class End Namespace @@ -207,6 +222,7 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo2)() {method}([|substitute.Bar()|], 1) + {method}(value:= [|substitute.Bar()|], returnThis:= 1) End Sub End Class End Namespace @@ -230,6 +246,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(), 1) + {method}(value:= substitute.Bar(), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar()) End Sub End Class End Namespace @@ -255,6 +273,7 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.Bar(), 1) + {method}(value:= substitute.Bar(), returnThis:= 1) End Sub End Class End Namespace @@ -279,6 +298,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.Bar, 1) + {method}(value:= substitute.Bar, returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar) End Sub End Class End Namespace @@ -302,6 +323,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo(Of Integer))() {method}(substitute.Bar(Of Integer), 1) + {method}(value:= substitute.Bar(Of Integer), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar(Of Integer)) End Sub End Class End Namespace"; @@ -325,6 +348,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute.Bar, 1) + {method}(value:= substitute.Bar, returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar) End Sub End Class End Namespace"; @@ -348,6 +373,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of IFoo) {method}(substitute(1), 1) + {method}(value:= substitute(1), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute(1)) End Sub End Class End Namespace"; @@ -373,6 +400,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute.Bar, 1) + {method}(value:= substitute.Bar, returnThis:= 1) + {method}(returnThis:= 1, value:= substitute.Bar) End Sub End Class End Namespace"; @@ -399,6 +428,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}([|substitute.Bar|], 1) + {method}(value:= [|substitute.Bar|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.Bar|]) End Sub End Class End Namespace"; @@ -431,6 +462,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute(1), 1) + {method}(value:= substitute(1), returnThis:= 1) + {method}(returnThis:= 1, value:= substitute(1)) End Sub End Class End Namespace"; @@ -459,6 +492,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}([|substitute(1)|], 1) + {method}(value:= [|substitute(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute(1)|]) End Sub End Class End Namespace"; @@ -517,6 +552,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar, 1) {method}([|substitute.FooBar|], 1) + {method}(value:= [|substitute.FooBar|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.FooBar|]) End Sub End Class End Namespace @@ -542,6 +579,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo(Of Integer))() {method}(substitute.Bar, 1) {method}([|substitute.FooBar|], 1) + {method}(value:= [|substitute.FooBar|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.FooBar|]) End Sub End Class End Namespace @@ -572,6 +611,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(1, 2), 1) {method}([|substitute.Bar(1)|], 1) + {method}(value:= [|substitute.Bar(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.Bar(1)|]) End Sub End Class End Namespace @@ -602,6 +643,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(Of Integer)(1, 2), 1) {method}([|substitute.Bar(1)|], 1) + {method}(value:= [|substitute.Bar(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.Bar(1)|]) End Sub End Class End Namespace @@ -636,6 +679,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute(1 ,2), 1) {method}([|substitute(1)|], 1) + {method}(value:= [|substitute(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute(1)|]) End Sub End Class End Namespace @@ -670,6 +715,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo(Of Integer))() {method}(substitute(1 ,2), 1) {method}([|substitute(1)|], 1) + {method}(value:= [|substitute(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute(1)|]) End Sub End Class End Namespace @@ -721,6 +768,8 @@ Public Sub Test() {method}(substitute.FooBar(), 1) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar)() {method}([|substituteFooBarBar(1)|], 1) + {method}(value:= [|substituteFooBarBar(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], 1) {method}([|substituteFooBarBar.FooBar()|], 1) End Sub @@ -735,7 +784,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -785,6 +834,8 @@ Public Sub Test() {method}(substitute.FooBar(), 1) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar(Of Integer))() {method}([|substituteFooBarBar(1)|], 1) + {method}(value:= [|substituteFooBarBar(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], 1) {method}([|substituteFooBarBar.FooBar()|], 1) End Sub @@ -799,7 +850,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -852,6 +903,8 @@ Public Sub Test() {method}(substitute.FooBar(), 1) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar)() {method}([|substituteFooBarBar(1)|], 1) + {method}(value:= [|substituteFooBarBar(1)|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], 1) {method}([|substituteFooBarBar.FooBar()|], 1) End Sub @@ -866,7 +919,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -887,6 +940,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.GetBar(), 1) {method}([|substitute.GetFooBar()|], 1) + {method}(value:= [|substitute.GetFooBar()|], returnThis:= 1) + {method}(returnThis:= 1, value:= [|substitute.GetFooBar()|]) End Sub End Class @@ -940,6 +995,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}([|substitute{call}|], 1) + Dim y = {method}(value:= [|substitute{call}|], returnThis:= 1) + Dim z = {method}(returnThis:= 1, value:= [|substitute{call}|]) End Sub End Class End Namespace"; @@ -974,6 +1031,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}(substitute{call}, 1) + Dim y = {method}(value:= substitute{call}, returnThis:= 1) + Dim z = {method}(returnThis:= 1, value:= substitute{call}) End Sub End Class End Namespace"; @@ -1006,6 +1065,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}([|substitute{call}|], 1) + Dim y = {method}(value:= [|substitute{call}|], returnThis:= 1) + Dim z = {method}(returnThis:= 1, value:= [|substitute{call}|]) End Sub End Class End Namespace"; @@ -1036,6 +1097,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}(substitute{call}, 1) + Dim y = {method}(value:= substitute{call}, returnThis:= 1) + Dim z = {method}(returnThis:= 1, value:= substitute{call}) End Sub End Class End Namespace"; diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index b86bfe44..0fce8b84 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using MoreLinq.Extensions; using NSubstitute.Analyzers.Shared; using NSubstitute.Analyzers.Shared.Settings; using NSubstitute.Analyzers.Tests.Shared.Extensibility; @@ -29,7 +30,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() - {method}([|substitute.Bar()|], New Exception()) + {method}(value:= [|substitute.Bar()|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.Bar()|]) End Sub End Class End Namespace @@ -48,6 +50,8 @@ Namespace MyNamespace Public Class FooTests Public Sub Test() {method}([|{literal}|], New Exception()) + {method}(value:= [|{literal}|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|{literal}|]) End Sub End Class End Namespace @@ -74,6 +78,8 @@ Public Class FooTests Public Sub Test() {method}([|Foo.Bar()|], New Exception()) + {method}(value:= [|Foo.Bar()|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|Foo.Bar()|]) End Sub End Class End Namespace @@ -101,6 +107,7 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(), New Exception()) + {method}(value:= substitute.Bar(), ex:= New Exception()) End Sub End Class End Namespace @@ -136,6 +143,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo2)() {method}(substitute.Bar(), New Exception()) + {method}(value:= substitute.Bar(), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar()) End Sub End Class End Namespace @@ -164,6 +173,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim returnValue = substitute.Bar() {method}(returnValue, New Exception()) + {method}(value:= returnValue, ex:= New Exception()) + {method}(ex:= New Exception(), value:= returnValue) End Sub End Class End Namespace @@ -184,6 +195,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Func(Of Integer))() {method}(substitute(), New Exception()) + {method}(value:= substitute(), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute()) End Sub End Class End Namespace @@ -219,6 +232,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo2)() {method}([|substitute.Bar()|], New Exception()) + {method}(value:= [|substitute.Bar()|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.Bar()|]) End Sub End Class End Namespace @@ -244,6 +259,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(), New Exception()) + {method}(value:= substitute.Bar(), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar()) End Sub End Class End Namespace @@ -271,6 +288,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.Bar(), New Exception()) + {method}(value:= substitute.Bar(), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar()) End Sub End Class End Namespace @@ -297,6 +316,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.Bar, New Exception()) + {method}(value:= substitute.Bar, ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar) End Sub End Class End Namespace @@ -322,6 +343,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo(Of Integer))() {method}(substitute.Bar(Of Integer), New Exception()) + {method}(value:= substitute.Bar(Of Integer), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar(Of Integer)) End Sub End Class End Namespace"; @@ -347,6 +370,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute.Bar, New Exception()) + {method}(value:= substitute.Bar, ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar) End Sub End Class End Namespace"; @@ -372,6 +397,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of IFoo) {method}(substitute(1), New Exception()) + {method}(value:= substitute(1), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute(1)) End Sub End Class End Namespace"; @@ -399,6 +426,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute.Bar, New Exception()) + {method}(value:= substitute.Bar, ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute.Bar) End Sub End Class End Namespace"; @@ -427,6 +456,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}([|substitute.Bar|], New Exception()) + {method}(value:= [|substitute.Bar|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.Bar|]) End Sub End Class End Namespace"; @@ -460,6 +491,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}(substitute(1), New Exception()) + {method}(value:= substitute(1), ex:= New Exception()) + {method}(ex:= New Exception(), value:= substitute(1)) End Sub End Class End Namespace"; @@ -489,6 +522,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.For(Of Foo) {method}([|substitute(1)|], New Exception()) + {method}(value:= [|substitute(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute(1)|]) End Sub End Class End Namespace"; @@ -549,6 +584,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar, New Exception()) {method}([|substitute.FooBar|], New Exception()) + {method}(value:= [|substitute.FooBar|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.FooBar|]) End Sub End Class End Namespace @@ -576,6 +613,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo(Of Integer))() {method}(substitute.Bar, New Exception()) {method}([|substitute.FooBar|], New Exception()) + {method}(value:= [|substitute.FooBar|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.FooBar|]) End Sub End Class End Namespace @@ -608,6 +647,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(1, 2), New Exception()) {method}([|substitute.Bar(1)|], New Exception()) + {method}(value:= [|substitute.Bar(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.Bar(1)|]) End Sub End Class End Namespace @@ -640,6 +681,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute.Bar(Of Integer)(1, 2), New Exception()) {method}([|substitute.Bar(1)|], New Exception()) + {method}(value:= [|substitute.Bar(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.Bar(1)|]) End Sub End Class End Namespace @@ -676,6 +719,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() {method}(substitute(1 ,2), New Exception()) {method}([|substitute(1)|], New Exception()) + {method}(value:= [|substitute(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute(1)|]) End Sub End Class End Namespace @@ -712,6 +757,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo(Of Integer))() {method}(substitute(1 ,2), New Exception()) {method}([|substitute(1)|], New Exception()) + {method}(value:= [|substitute(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute(1)|]) End Sub End Class End Namespace @@ -765,6 +812,8 @@ Public Sub Test() {method}(substitute.FooBar(), New Exception()) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar)() {method}([|substituteFooBarBar(1)|], New Exception()) + {method}(value:= [|substituteFooBarBar(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], New Exception()) {method}([|substituteFooBarBar.FooBar()|], New Exception()) End Sub @@ -779,7 +828,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -831,6 +880,8 @@ Public Sub Test() {method}(substitute.FooBar(), New Exception()) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar(Of Integer))() {method}([|substituteFooBarBar(1)|], New Exception()) + {method}(value:= [|substituteFooBarBar(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], New Exception()) {method}([|substituteFooBarBar.FooBar()|], New Exception()) End Sub @@ -845,7 +896,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -900,6 +951,8 @@ Public Sub Test() {method}(substitute.FooBar(), New Exception()) Dim substituteFooBarBar = NSubstitute.Substitute.[For](Of FooBarBar)() {method}([|substituteFooBarBar(1)|], New Exception()) + {method}(value:= [|substituteFooBarBar(1)|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substituteFooBarBar(1)|]) {method}([|substituteFooBarBar.Bar|], New Exception()) {method}([|substituteFooBarBar.FooBar()|], New Exception()) End Sub @@ -914,7 +967,7 @@ End Namespace "Member Item can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member Bar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted.", "Member FooBar can not be intercepted. Only interface members and overrideable, overriding, and must override members can be intercepted." - }; + }.Repeat(2).ToList(); var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(NonVirtualSetupSpecificationDescriptor.OverrideMessage(diagnosticMessages[idx]), span)).ToArray(); @@ -937,6 +990,8 @@ Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() {method}(substitute.GetBar(), New Exception()) {method}([|substitute.GetFooBar()|], New Exception()) + {method}(value:= [|substitute.GetFooBar()|], ex:= New Exception()) + {method}(ex:= New Exception(), value:= [|substitute.GetFooBar()|]) End Sub End Class @@ -992,6 +1047,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}([|substitute{call}|], New Exception()) + Dim y = {method}(value:= [|substitute{call}|], ex:= New Exception()) + Dim z = {method}(ex:= New Exception(), value:= [|substitute{call}|]) End Sub End Class End Namespace"; @@ -1028,6 +1085,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}(substitute{call}, New Exception()) + Dim y = {method}(value:= substitute{call}, ex:= New Exception()) + Dim z = {method}(ex:= New Exception(), value:= substitute{call}) End Sub End Class End Namespace"; @@ -1062,6 +1121,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}([|substitute{call}|], New Exception()) + Dim y = {method}(value:= [|substitute{call}|], ex:= New Exception()) + Dim z = {method}(ex:= New Exception(), value:= [|substitute{call}|]) End Sub End Class End Namespace"; @@ -1094,6 +1155,8 @@ Public Class FooTests Public Sub Test() Dim substitute = NSubstitute.Substitute.[For](Of Foo)() Dim x = {method}(substitute{call}, New Exception()) + Dim y = {method}(value:= substitute{call}, ex:= New Exception()) + Dim z = {method}(ex:= New Exception(), value:= substitute{call}) End Sub End Class End Namespace"; diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs index bc4b40d4..f2ed0574 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonSubstitutableMemberReceivedAnalyzerTests/ReceivedAsOrdinaryMethodTests.cs @@ -5,17 +5,32 @@ namespace NSubstitute.Analyzers.Tests.VisualBasic.DiagnosticAnalyzersTests.NonSu { [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity:= Quantity.None(), substitute:= substitute)", "ReceivedExtensions.Received(Of Foo)(substitute, Quantity.None())", + "ReceivedExtensions.Received(Of Foo)(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(Of Foo)(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute:= substitute)", "SubstituteExtensions.Received(Of Foo)(substitute)", + "SubstituteExtensions.Received(Of Foo)(substitute:= substitute)", "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", - "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo)(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity:= Quantity.None(), substitute:= substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo)(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo)(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(Of Foo)(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(Of Foo)(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(Of Foo)(substitute)", + "SubstituteExtensions.DidNotReceive(Of Foo)(substitute:= substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Foo)(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute:= substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Foo)(substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Foo)(substitute:= substitute)")] public class ReceivedAsOrdinaryMethodTests : NonSubstitutableMemberReceivedDiagnosticVerifier { public override async Task ReportsDiagnostics_WhenCheckingReceivedCallsForNonVirtualMethod(string method) @@ -106,17 +121,33 @@ End Namespace [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity:= Quantity.None(), substitute:= substitute)", "ReceivedExtensions.Received(Of Func(Of Foo))(substitute, Quantity.None())", + "ReceivedExtensions.Received(Of Func(Of Foo))(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(Of Func(Of Foo))(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute:= substitute)", "SubstituteExtensions.Received(Of Func(Of Foo))(substitute)", + "SubstituteExtensions.Received(Of Func(Of Foo))(substitute:= substitute)", "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity:= Quantity.None(), substitute:= substitute)", "ReceivedExtensions.ReceivedWithAnyArgs(Of Func(Of Foo))(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Func(Of Foo))(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Func(Of Foo))(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(Of Func(Of Foo))(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(Of Func(Of Foo))(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(Of Func(Of Foo))(substitute)", + "SubstituteExtensions.DidNotReceive(Of Func(Of Foo))(substitute:= substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Func(Of Foo))(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute:= substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Func(Of Foo))(substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Func(Of Foo))(substitute:= substitute)")] public override async Task ReportsNoDiagnostics_WhenCheckingReceivedCallsForDelegate(string method) { var source = $@"Imports NSubstitute @@ -251,17 +282,31 @@ End Namespace [CombinatoryData( "ReceivedExtensions.Received(substitute, Quantity.None())", + "ReceivedExtensions.Received(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(requiredQuantity:= Quantity.None(), substitute:= substitute)", "ReceivedExtensions.Received(Of Foo(Of Integer))(substitute, Quantity.None())", + "ReceivedExtensions.Received(Of Foo(Of Integer))(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.Received(Of Foo(Of Integer))(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.Received(substitute)", + "SubstituteExtensions.Received(substitute:= substitute)", "SubstituteExtensions.Received(Of Foo(Of Integer))(substitute)", + "SubstituteExtensions.Received(Of Foo(Of Integer))(substitute:= substitute)", "ReceivedExtensions.ReceivedWithAnyArgs(substitute, Quantity.None())", - "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo(Of Integer))(substitute, Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(requiredQuantity:= Quantity.None(), substitute:= substitute)", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo(Of Integer))(substitute:= substitute, requiredQuantity:= Quantity.None())", + "ReceivedExtensions.ReceivedWithAnyArgs(Of Foo(Of Integer))(requiredQuantity:= Quantity.None(), substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(substitute:= substitute)", "SubstituteExtensions.ReceivedWithAnyArgs(Of Foo(Of Integer))(substitute)", + "SubstituteExtensions.ReceivedWithAnyArgs(Of Foo(Of Integer))(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(substitute)", + "SubstituteExtensions.DidNotReceive(substitute:= substitute)", "SubstituteExtensions.DidNotReceive(Of Foo(Of Integer))(substitute)", + "SubstituteExtensions.DidNotReceive(Of Foo(Of Integer))(substitute:= substitute)", "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute)", - "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Foo(Of Integer))(substitute)")] + "SubstituteExtensions.DidNotReceiveWithAnyArgs(substitute:= substitute)", + "SubstituteExtensions.DidNotReceiveWithAnyArgs(Of Foo(Of Integer))(substitute:= substitute)")] public override async Task ReportsNoDiagnostics_WhenCheckingReceivedCallsForGenericInterfaceMethod(string method) { var source = $@"Imports NSubstitute