From 4d9a70628665eddf60656499600737c173685cb7 Mon Sep 17 00:00:00 2001 From: tpodolak Date: Fri, 22 Jul 2022 16:46:13 +0200 Subject: [PATCH] GH-186 - CallInfoAnalyzer support for ThrowsAsync like methods --- .../MetadataNames.cs | 2 + .../ThrowsAsExtensionMethodTests.cs | 163 +++++---- .../ThrowsAsOrdinaryMethodTests.cs | 333 ++++++------------ .../ThrowsAsExtensionMethodsTests.cs | 144 ++++---- .../ThrowsAsOrdinaryMethodsTests.cs | 148 ++++---- 5 files changed, 373 insertions(+), 417 deletions(-) diff --git a/src/NSubstitute.Analyzers.Shared/MetadataNames.cs b/src/NSubstitute.Analyzers.Shared/MetadataNames.cs index 1e6d4147..ea8d10a4 100644 --- a/src/NSubstitute.Analyzers.Shared/MetadataNames.cs +++ b/src/NSubstitute.Analyzers.Shared/MetadataNames.cs @@ -128,7 +128,9 @@ internal class MetadataNames [NSubstituteReturnsMethod] = NSubstituteSubstituteExtensionsFullTypeName, [NSubstituteReturnsForAnyArgsMethod] = NSubstituteSubstituteExtensionsFullTypeName, [NSubstituteThrowsMethod] = NSubstituteExceptionExtensionsFullTypeName, + [NSubstituteThrowsAsyncMethod] = NSubstituteExceptionExtensionsFullTypeName, [NSubstituteThrowsForAnyArgsMethod] = NSubstituteExceptionExtensionsFullTypeName, + [NSubstituteThrowsAsyncForAnyArgsMethod] = NSubstituteExceptionExtensionsFullTypeName, [NSubstituteAndDoesMethod] = NSubstituteConfiguredCallFullTypeName, [NSubstituteDoMethod] = NSubstituteWhenCalledType }; diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodTests.cs index 3f628e33..5ab854a1 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodTests.cs @@ -5,12 +5,13 @@ namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.CallInfoAnalyzerTests; -[CombinatoryData("Throws", "ThrowsForAnyArgs")] +[CombinatoryData("Throws", "ThrowsForAnyArgs", "ThrowsAsync", "ThrowsAsyncForAnyArgs")] public class ThrowsAsExtensionMethodTests : CallInfoDiagnosticVerifier { public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -18,11 +19,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -46,17 +47,18 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBounds(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -78,6 +80,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentOutOfBound_AndPositionIsNotLiteralExpression(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -85,11 +88,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y); + Task Bar(int x, int y); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x, int y] {{ get; }} + Task this[int x, int y] {{ get; }} }} public class FooTests @@ -111,6 +114,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBounds(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -119,11 +123,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y = 1); + Task Bar(int x, int y = 1); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x, int y = 1] {{ get; }} + Task this[int x, int y = 1] {{ get; }} }} public class FooTests @@ -145,6 +149,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBoundsForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -152,12 +157,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(int x, int y); + Task FooBaz(int x, int y); }} public class FooTests @@ -192,6 +197,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenManuallyCasting_ToSupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -199,9 +205,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, Bar y); + Task Bar(int x, Bar y); - int this[int x, Bar y] {{ get; }} + Task this[int x, Bar y] {{ get; }} }} public class BarBase @@ -232,6 +238,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenManuallyCasting_ToUnsupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -239,17 +246,17 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(string x, object y); + Task Bar(string x, object y); - int Foo(int x, FooBar bar); + Task Foo(int x, FooBar bar); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[string x, object y] {{ get; }} + Task this[string x, object y] {{ get; }} - int this[int x, FooBar bar] {{ get; }} + Task this[int x, FooBar bar] {{ get; }} }} public class Bar @@ -279,6 +286,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenCasting_WithArgAt_ToSupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -287,13 +295,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, Bar y); + Task Bar(int x, Bar y); - int Bar(decimal x, object y, int z = 1); + Task Bar(decimal x, object y, int z = 1); - int this[int x, Bar y] {{ get; }} + Task this[int x, Bar y] {{ get; }} - int this[decimal x, object y] {{ get; }} + Task this[decimal x, object y] {{ get; }} }} public class BarBase @@ -323,24 +331,24 @@ public void Test() public override async Task ReportsDiagnostic_WhenCasting_WithArgAt_ToUnsupportedType(string method, string call, string argAccess, string message) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(object x, object y); + Task Bar(object x, object y); - int Foo(int x, FooBar bar); + Task Foo(int x, FooBar bar); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[object x, object y] {{ get; }} + Task this[object x, object y] {{ get; }} - int this[int x, FooBar bar] {{ get; }} + Task this[int x, FooBar bar] {{ get; }} }} public class Bar @@ -370,7 +378,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenCastingElementsFromArgTypes(string method, string callInfo, string argAccess) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -378,9 +386,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(Bar x); + Task Bar(Bar x); - int this[Bar x] {{ get; }} + Task this[Bar x] {{ get; }} }} public class Bar @@ -406,7 +414,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningValueToNotRefNorOutArgumentViaIndirectCall(string method, string call, string argAccess) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -414,9 +422,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(Bar x); + Task Bar(Bar x); - int this[Bar x] {{ get; }} + Task this[Bar x] {{ get; }} }} public class Bar @@ -442,7 +450,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocation(string method, string call, string argAccess, string message) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -450,11 +458,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -476,6 +484,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocationForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -483,12 +492,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(int x); + Task FooBaz(int x); }} public class FooTests @@ -520,6 +529,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBoundsForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -527,12 +537,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(int x, int y); + Task FooBaz(int x, int y); }} public class FooTests @@ -580,7 +590,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInInvocation(string method, string call, string argAccess) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -588,17 +598,17 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); - int Bar(Foo x); + Task Bar(Foo x); - int Bar(int x, object y); + Task Bar(int x, object y); - int this[int x] {{ get; }} + Task this[int x] {{ get; }} - int this[Foo x] {{ get; }} + Task this[Foo x] {{ get; }} - int this[int x, object y] {{ get; }} + Task this[int x, object y] {{ get; }} }} public class FooBase @@ -629,6 +639,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInvocationForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -636,12 +647,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(string x); + Task FooBaz(string x); }} public class FooTests @@ -672,6 +683,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeMultipleTimesInInvocation(string method, string call, string argAccess, string message) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -679,13 +691,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y); + Task Bar(int x, int y); - int Bar(object x, object y); + Task Bar(object x, object y); - int this[int x, int y] {{ get; }} + Task this[int x, int y] {{ get; }} - int this[object x, object y] {{ get; }} + Task this[object x, object y] {{ get; }} }} public class FooBar @@ -712,6 +724,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeMultipleDifferentTypesInInvocation(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -719,13 +732,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(object x, FooBar y); + Task Bar(object x, FooBar y); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[object x, FooBar y] {{ get; }} + Task this[object x, FooBar y] {{ get; }} }} public class FooBar @@ -752,6 +765,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningValueToNotOutNorRefArgument(string method, string call) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -759,9 +773,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} }} public class FooTests @@ -783,6 +797,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningValueToRefArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -790,7 +805,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(ref int x); + Task Bar(ref int x); }} public class FooTests @@ -813,6 +828,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningValueToOutArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -820,7 +836,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out int x); + Task Bar(out int x); }} public class FooTests @@ -843,6 +859,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningValueToOutOfBoundsArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -850,7 +867,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out int x); + Task Bar(out int x); }} public class FooTests @@ -873,6 +890,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningType_NotAssignableTo_Argument(string method, string left, string right, string expectedMessage) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using System.Collections.Generic; using NSubstitute.ExceptionExtensions; @@ -881,7 +899,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out {left} x); + Task Bar(out {left} x); }} public class FooTests @@ -905,6 +923,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningType_AssignableTo_Argument(string method, string left, string right) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using System.Collections.Generic; using NSubstitute.ExceptionExtensions; @@ -913,7 +932,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out {left} x); + Task Bar(out {left} x); }} public class FooTests diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index 00cb6469..084f4880 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -5,12 +5,17 @@ namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.CallInfoAnalyzerTests; -[CombinatoryData("ExceptionExtensions.Throws", "ExceptionExtensions.ThrowsForAnyArgs")] +[CombinatoryData( + "ExceptionExtensions.Throws", + "ExceptionExtensions.ThrowsAsync", + "ExceptionExtensions.ThrowsForAnyArgs", + "ExceptionExtensions.ThrowsAsyncForAnyArgs")] public class ThrowsAsOrdinaryMethodTests : CallInfoDiagnosticVerifier { public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -18,11 +23,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -41,11 +46,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: returnedValue); }} }} }}"; @@ -56,17 +56,18 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBounds(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -79,26 +80,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}); }} }} }}"; await VerifyDiagnostic(source, CallInfoArgumentOutOfRangeDescriptor, "There is no argument at position 1"); } - public override async Task - ReportsNoDiagnostic_WhenAccessingArgumentOutOfBound_AndPositionIsNotLiteralExpression(string method, string call, string argAccess) + public override async Task ReportsNoDiagnostic_WhenAccessingArgumentOutOfBound_AndPositionIsNotLiteralExpression(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -106,11 +97,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y); + Task Bar(int x, int y); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x, int y] {{ get; }} + Task this[int x, int y] {{ get; }} }} public class FooTests @@ -128,11 +119,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -142,6 +128,8 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBounds(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; +using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -149,11 +137,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y = 1); + Task Bar(int x, int y = 1); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x, int y = 1] {{ get; }} + Task this[int x, int y = 1] {{ get; }} }} public class FooTests @@ -166,16 +154,6 @@ 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}); }} }} }}"; @@ -185,6 +163,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBoundsForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -192,12 +171,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(int x, int y); + Task FooBaz(int x, int y); }} public class FooTests @@ -213,15 +192,15 @@ public void Test() var x = outerCallInfo.ArgAt(1); var y = outerCallInfo[1]; - var xx = innerCallInfo.ArgAt(0); - var yy = innerCallInfo[0]; + var xx = innerCallInfo.ArgAt(0); + var yy = innerCallInfo[0]; + + return new Exception(); + }}); return new Exception(); }}); - return new Exception(); - }}); - }} }} }}"; @@ -231,6 +210,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenManuallyCasting_ToSupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -238,9 +218,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, Bar y); + Task Bar(int x, Bar y); - int this[int x, Bar y] {{ get; }} + Task this[int x, Bar y] {{ get; }} }} public class BarBase @@ -266,11 +246,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -281,23 +256,25 @@ public void Test() public override async Task ReportsDiagnostic_WhenManuallyCasting_ToUnsupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; +using System; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(string x, object y); + Task Bar(string x, object y); - int Foo(int x, FooBar bar); + Task Foo(int x, FooBar bar); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[string x, object y] {{ get; }} + Task this[string x, object y] {{ get; }} - int this[int x, FooBar bar] {{ get; }} + Task this[int x, FooBar bar] {{ get; }} }} public class Bar @@ -323,11 +300,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -337,6 +309,8 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenCasting_WithArgAt_ToSupportedType(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; +using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -344,13 +318,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, Bar y); + Task Bar(int x, Bar y); - int Bar(decimal x, object y, int z = 1); + Task Bar(decimal x, object y, int z = 1); - int this[int x, Bar y] {{ get; }} + Task this[int x, Bar y] {{ get; }} - int this[decimal x, object y] {{ get; }} + Task this[decimal x, object y] {{ get; }} }} public class BarBase @@ -371,16 +345,6 @@ 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}); }} }} }}"; @@ -390,24 +354,24 @@ public void Test() public override async Task ReportsDiagnostic_WhenCasting_WithArgAt_ToUnsupportedType(string method, string call, string argAccess, string message) { var source = $@"using System; -using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(object x, object y); + Task Bar(object x, object y); - int Foo(int x, FooBar bar); + Task Foo(int x, FooBar bar); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[object x, object y] {{ get; }} + Task this[object x, object y] {{ get; }} - int this[int x, FooBar bar] {{ get; }} + Task this[int x, FooBar bar] {{ get; }} }} public class Bar @@ -433,20 +397,16 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; await VerifyDiagnostic(source, CallInfoCouldNotConvertParameterAtPositionDescriptor, message); } - public override async Task ReportsNoDiagnostic_WhenCastingElementsFromArgTypes(string method, string call, string argAccess) + public override async Task ReportsNoDiagnostic_WhenCastingElementsFromArgTypes(string method, string callInfo, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -454,9 +414,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(Bar x); + Task Bar(Bar x); - int this[Bar x] {{ get; }} + Task this[Bar x] {{ get; }} }} public class Bar @@ -468,21 +428,11 @@ public class FooTests public void Test() {{ var substitute = NSubstitute.Substitute.For(); - {method}({call}, callInfo => + {method}({callInfo}, callInfo => {{ {argAccess} return new Exception(); }}); - {method}(value: {call}, createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -492,16 +442,17 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningValueToNotRefNorOutArgumentViaIndirectCall(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; namespace MyNamespace {{ - public interface Foo + public interface Foo {{ - int Bar(Bar x); + Task Bar(Bar x); - int this[Bar x] {{ get; }} + Task this[Bar x] {{ get; }} }} public class Bar @@ -523,11 +474,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -537,6 +483,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocation(string method, string call, string argAccess, string message) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -544,11 +491,11 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x); + Task Bar(int x); - int Barr {{ get; }} + Task Barr {{ get; }} - int this[int x] {{ get; }} + Task this[int x] {{ get; }} }} public class FooTests @@ -561,16 +508,6 @@ 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}); }} }} }}"; @@ -580,6 +517,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocationForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -587,12 +525,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(object x); + Task FooBaz(int x); }} public class FooTests @@ -600,7 +538,7 @@ public class FooTests public void Test() {{ var substitute = NSubstitute.Substitute.For(); - {method}(substitute.FooBaz(Arg.Any()), outerCallInfo => + {method}(substitute.FooBaz(Arg.Any()), outerCallInfo => {{ var otherSubstitute = NSubstitute.Substitute.For(); {method}(otherSubstitute.Bar(Arg.Any()), innerCallInfo => @@ -623,6 +561,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBoundsForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -630,12 +569,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(int x, int y); + Task FooBaz(int x, int y); }} public class FooTests @@ -682,6 +621,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInInvocation(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -689,17 +629,17 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); - int Bar(Foo x); + Task Bar(Foo x); - int Bar(int x, object y); + Task Bar(int x, object y); - int this[int x] {{ get; }} + Task this[int x] {{ get; }} - int this[Foo x] {{ get; }} + Task this[Foo x] {{ get; }} - int this[int x, object y] {{ get; }} + Task this[int x, object y] {{ get; }} }} public class FooBase @@ -720,16 +660,6 @@ 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}); }} }} }}"; @@ -740,6 +670,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInvocationForNestedCall(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -747,12 +678,12 @@ namespace MyNamespace {{ public interface IFoo {{ - int Bar(int x); + Task Bar(int x); }} public interface IFooBar {{ - int FooBaz(string x); + Task FooBaz(string x); }} public class FooTests @@ -782,6 +713,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeMultipleTimesInInvocation(string method, string call, string argAccess, string message) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -789,13 +721,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, int y); + Task Bar(int x, int y); - int Bar(object x, object y); + Task Bar(object x, object y); - int this[int x, int y] {{ get; }} + Task this[int x, int y] {{ get; }} - int this[object x, object y] {{ get; }} + Task this[object x, object y] {{ get; }} }} public class FooBar @@ -817,11 +749,6 @@ public void Test() {argAccess} return new Exception(); }}); - {method}(createException: callInfo => - {{ - {argAccess} - return new Exception(); - }}, value: {call}); }} }} }}"; @@ -832,6 +759,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeMultipleDifferentTypesInInvocation(string method, string call, string argAccess) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -839,13 +767,13 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int Bar(object x, FooBar y); + Task Bar(object x, FooBar y); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} - int this[object x, FooBar y] {{ get; }} + Task this[object x, FooBar y] {{ get; }} }} public class FooBar @@ -862,16 +790,6 @@ 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}); }} }} }}"; @@ -882,6 +800,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningValueToNotOutNorRefArgument(string method, string call) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -889,9 +808,9 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(int x, double y); + Task Bar(int x, double y); - int this[int x, double y] {{ get; }} + Task this[int x, double y] {{ get; }} }} public class FooTests @@ -909,21 +828,16 @@ public void Test() [|callInfo[1]|] = 1; return new Exception(); }}); - {method}(createException: callInfo => - {{ - [|callInfo[1]|] = 1; - return new Exception(); - }}, value: {call}); }} }} }}"; - await VerifyDiagnostic(source, CallInfoArgumentIsNotOutOrRefDescriptor, "Could not set argument 1 (double) as it is not an out or ref argument."); } public override async Task ReportsNoDiagnostic_WhenAssigningValueToRefArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -931,7 +845,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(ref int x); + Task Bar(ref int x); }} public class FooTests @@ -950,11 +864,6 @@ public void Test() callInfo[0] = 1; return new Exception(); }}); - {method}(createException: callInfo => - {{ - callInfo[0] = 1; - return new Exception(); - }}, value: substitute.Bar(ref value)); }} }} }}"; @@ -964,6 +873,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningValueToOutArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -971,7 +881,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out int x); + Task Bar(out int x); }} public class FooTests @@ -985,16 +895,6 @@ 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)); }} }} }}"; @@ -1004,6 +904,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningValueToOutOfBoundsArgument(string method) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -1011,7 +912,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out int x); + Task Bar(out int x); }} public class FooTests @@ -1030,11 +931,6 @@ public void Test() [|callInfo[1]|] = 1; return new Exception(); }}); - {method}(createException: callInfo => - {{ - [|callInfo[1]|] = 1; - return new Exception(); - }}, value: substitute.Bar(out value)); }} }} }}"; @@ -1044,6 +940,7 @@ public void Test() public override async Task ReportsDiagnostic_WhenAssigningType_NotAssignableTo_Argument(string method, string left, string right, string expectedMessage) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using System.Collections.Generic; using NSubstitute.ExceptionExtensions; @@ -1052,7 +949,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out {left} x); + Task Bar(out {left} x); }} public class FooTests @@ -1066,16 +963,6 @@ 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)); }} }} }}"; @@ -1086,6 +973,7 @@ public void Test() public override async Task ReportsNoDiagnostic_WhenAssigningType_AssignableTo_Argument(string method, string left, string right) { var source = $@"using System; +using System.Threading.Tasks; using NSubstitute; using System.Collections.Generic; using NSubstitute.ExceptionExtensions; @@ -1094,7 +982,7 @@ namespace MyNamespace {{ public interface Foo {{ - int Bar(out {left} x); + Task Bar(out {left} x); }} public class FooTests @@ -1113,11 +1001,6 @@ public void Test() 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.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodsTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodsTests.cs index f173d85a..25bfcd64 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodsTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsExtensionMethodsTests.cs @@ -5,20 +5,21 @@ namespace NSubstitute.Analyzers.Tests.VisualBasic.DiagnosticAnalyzersTests.CallInfoAnalyzerTests; -[CombinatoryData("Throws", "ThrowsForAnyArgs")] +[CombinatoryData("Throws", "ThrowsAsync", "ThrowsForAnyArgs", "ThrowsAsyncForAnyArgs")] public class ThrowsAsExtensionMethodsTests : CallInfoDiagnosticVerifier { public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -39,13 +40,14 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBounds(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -65,14 +67,15 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentOutOfBound_AndPositionIsNotLiteralExpression(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Integer + Function Bar(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -91,14 +94,15 @@ End Class public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBounds(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal Optional y As Integer = 1) As Integer + Function Bar(ByVal x As Integer, ByVal Optional y As Integer = 1) As Task(Of Integer) ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal Optional y As Integer = 1) As Integer + Default ReadOnly Property Item(ByVal x As Integer, ByVal Optional y As Integer = 1) As Task(Of Integer) End Interface Public Class FooTests @@ -118,16 +122,17 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBoundsForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Integer + Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -154,16 +159,17 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBoundsForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Integer + Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -202,13 +208,14 @@ End Class public override async Task ReportsNoDiagnostic_WhenManuallyCasting_ToSupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) End Interface Public Class BarBase @@ -235,14 +242,15 @@ End Class public override async Task ReportsDiagnostic_WhenManuallyCasting_ToUnsupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) End Interface Public Class Bar @@ -269,13 +277,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenCasting_WithArgAt_ToSupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) End Interface Public Class BarBase @@ -303,14 +312,15 @@ End Namespace public override async Task ReportsDiagnostic_WhenCasting_WithArgAt_ToUnsupportedType(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) End Interface Public Class Bar @@ -337,13 +347,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenCastingElementsFromArgTypes(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Bar) As Integer + Function Bar(ByVal x As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Bar) As Task(Of Integer) End Interface Public Class Bar @@ -366,13 +377,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToNotRefNorOutArgumentViaIndirectCall(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Bar) As Integer + Function Bar(ByVal x As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Bar) As Task(Of Integer) End Interface Public Class Bar @@ -395,14 +407,15 @@ End Namespace public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocation(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface @@ -423,17 +436,18 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInInvocation(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer - Function Bar(ByVal x As Foo) As Integer - Function Bar(ByVal x As Integer, ByVal y As Object) As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer - Default ReadOnly Property Item(ByVal x As Foo) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y as Object) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + Function Bar(ByVal x As Foo) As Task(Of Integer) + Function Bar(ByVal x As Integer, ByVal y As Object) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Foo) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y as Object) As Task(Of Integer) End Interface Public Class FooBase @@ -461,16 +475,17 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInvocationForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As String) As Integer + Function FooBaz(ByVal x As String) As Task(Of Integer) End Interface Public Class FooTests @@ -495,15 +510,16 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeMultipleTimesInInvocation(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Integer) As Integer - Function Bar(ByVal x As Object, ByVal y As Object) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Integer - Default ReadOnly Property Item(ByVal x As Object, ByVal y As Object) As Integer + Function Bar(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + Function Bar(ByVal x As Object, ByVal y As Object) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Object, ByVal y As Object) As Task(Of Integer) End Interface Public Class FooBar @@ -526,15 +542,16 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeMultipleDifferentTypesInInvocation(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Bar(ByVal x As Object, ByVal y As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Object, ByVal y As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Bar(ByVal x As Object, ByVal y As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Object, ByVal y As FooBar) As Task(Of Integer) End Interface Public Class FooBar @@ -558,13 +575,14 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningValueToNotOutNorRefArgument(string method, string call) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) End Interface Public Class FooTests @@ -584,12 +602,13 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToRefArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByRef x As Integer) As Integer + Function Bar(ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -610,13 +629,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToOutArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices Namespace MyNamespace Interface Foo - Function Bar( ByRef x As Integer) As Integer + Function Bar( ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -637,13 +657,14 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningValueToOutOfBoundsArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices Namespace MyNamespace Interface Foo - Function Bar( ByRef x As Integer) As Integer + Function Bar( ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -664,6 +685,7 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningType_NotAssignableTo_Argument(string method, string left, string right, string expectedMessage) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices @@ -671,7 +693,7 @@ Imports System.Collections.Generic Namespace MyNamespace Interface Foo - Function Bar( ByRef x As {left}) As Integer + Function Bar( ByRef x As {left}) As Task(Of Integer) End Interface Public Class FooTests @@ -694,6 +716,7 @@ public override async Task ReportsNoDiagnostic_WhenAssigningType_AssignableTo_Ar { var source = $@" Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices @@ -701,7 +724,7 @@ Imports System.Collections.Generic Namespace MyNamespace Interface Foo - Function Bar( ByRef x As {left}) As Integer + Function Bar( ByRef x As {left}) As Task(Of Integer) End Interface Public Class FooTests @@ -723,16 +746,17 @@ End Namespace public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocationForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer) As Integer + Function FooBaz(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodsTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodsTests.cs index 5dde1838..12b704de 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodsTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/CallInfoAnalyzerTests/ThrowsAsOrdinaryMethodsTests.cs @@ -5,20 +5,25 @@ namespace NSubstitute.Analyzers.Tests.VisualBasic.DiagnosticAnalyzersTests.CallInfoAnalyzerTests; -[CombinatoryData("ExceptionExtensions.Throws", "ExceptionExtensions.ThrowsForAnyArgs")] +[CombinatoryData( + "ExceptionExtensions.Throws", + "ExceptionExtensions.ThrowsAsync", + "ExceptionExtensions.ThrowsForAnyArgs", + "ExceptionExtensions.ThrowsAsyncForAnyArgs")] public class ThrowsAsOrdinaryMethodsTests : CallInfoDiagnosticVerifier { public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -47,13 +52,14 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBounds(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -81,14 +87,15 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentOutOfBound_AndPositionIsNotLiteralExpression(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Integer + Function Bar(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -115,14 +122,15 @@ End Class public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBounds(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal Optional y As Integer = 1) As Integer + Function Bar(ByVal x As Integer, ByVal Optional y As Integer = 1) As Task(Of Integer) ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal Optional y As Integer = 1) As Integer + Default ReadOnly Property Item(ByVal x As Integer, ByVal Optional y As Integer = 1) As Task(Of Integer) End Interface Public Class FooTests @@ -150,16 +158,17 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentWithinBoundsForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Integer + Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -186,16 +195,17 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentOutOfBoundsForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Integer + Function FooBaz(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -234,13 +244,14 @@ End Class public override async Task ReportsNoDiagnostic_WhenManuallyCasting_ToSupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) End Interface Public Class BarBase @@ -275,14 +286,15 @@ End Class public override async Task ReportsDiagnostic_WhenManuallyCasting_ToUnsupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) End Interface Public Class Bar @@ -317,13 +329,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenCasting_WithArgAt_ToSupportedType(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Bar) As Task(Of Integer) End Interface Public Class BarBase @@ -359,14 +372,15 @@ End Namespace public override async Task ReportsDiagnostic_WhenCasting_WithArgAt_ToUnsupportedType(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Foo(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal bar As FooBar) As Task(Of Integer) End Interface Public Class Bar @@ -401,13 +415,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenCastingElementsFromArgTypes(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Bar) As Integer + Function Bar(ByVal x As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Bar) As Task(Of Integer) End Interface Public Class Bar @@ -438,13 +453,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToNotRefNorOutArgumentViaIndirectCall(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Bar) As Integer - Default ReadOnly Property Item(ByVal x As Bar) As Integer + Function Bar(ByVal x As Bar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Bar) As Task(Of Integer) End Interface Public Class Bar @@ -475,14 +491,15 @@ End Namespace public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocation(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer) As Integer - ReadOnly Property Barr As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + ReadOnly Property Barr As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) End Interface @@ -511,17 +528,18 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInInvocation(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer - Function Bar(ByVal x As Foo) As Integer - Function Bar(ByVal x As Integer, ByVal y As Object) As Integer - Default ReadOnly Property Item(ByVal x As Integer) As Integer - Default ReadOnly Property Item(ByVal x As Foo) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y as Object) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) + Function Bar(ByVal x As Foo) As Task(Of Integer) + Function Bar(ByVal x As Integer, ByVal y As Object) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Foo) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y as Object) As Task(Of Integer) End Interface Public Class FooBase @@ -557,16 +575,17 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeInInvocationForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As String) As Integer + Function FooBaz(ByVal x As String) As Task(Of Integer) End Interface Public Class FooTests @@ -591,15 +610,16 @@ End Class public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeMultipleTimesInInvocation(string method, string call, string argAccess, string message) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Integer) As Integer - Function Bar(ByVal x As Object, ByVal y As Object) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Integer - Default ReadOnly Property Item(ByVal x As Object, ByVal y As Object) As Integer + Function Bar(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + Function Bar(ByVal x As Object, ByVal y As Object) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Object, ByVal y As Object) As Task(Of Integer) End Interface Public Class FooBar @@ -631,15 +651,16 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAccessingArgumentByTypeMultipleDifferentTypesInInvocation(string method, string call, string argAccess) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Function Bar(ByVal x As Object, ByVal y As FooBar) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Object, ByVal y As FooBar) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Function Bar(ByVal x As Object, ByVal y As FooBar) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Object, ByVal y As FooBar) As Task(Of Integer) End Interface Public Class FooBar @@ -671,13 +692,14 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningValueToNotOutNorRefArgument(string method, string call) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByVal x As Integer, ByVal y As Double) As Integer - Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Integer + Function Bar(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) + Default ReadOnly Property Item(ByVal x As Integer, ByVal y As Double) As Task(Of Integer) End Interface Public Class FooTests @@ -705,12 +727,13 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToRefArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface Foo - Function Bar(ByRef x As Integer) As Integer + Function Bar(ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -739,13 +762,14 @@ End Namespace public override async Task ReportsNoDiagnostic_WhenAssigningValueToOutArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices Namespace MyNamespace Interface Foo - Function Bar( ByRef x As Integer) As Integer + Function Bar( ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -774,13 +798,14 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningValueToOutOfBoundsArgument(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices Namespace MyNamespace Interface Foo - Function Bar( ByRef x As Integer) As Integer + Function Bar( ByRef x As Integer) As Task(Of Integer) End Interface Public Class FooTests @@ -809,6 +834,7 @@ End Namespace public override async Task ReportsDiagnostic_WhenAssigningType_NotAssignableTo_Argument(string method, string left, string right, string expectedMessage) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices @@ -816,7 +842,7 @@ Imports System.Collections.Generic Namespace MyNamespace Interface Foo - Function Bar( ByRef x As {left}) As Integer + Function Bar( ByRef x As {left}) As Task(Of Integer) End Interface Public Class FooTests @@ -847,6 +873,7 @@ public override async Task ReportsNoDiagnostic_WhenAssigningType_AssignableTo_Ar { var source = $@" Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Imports System.Runtime.InteropServices @@ -854,7 +881,7 @@ Imports System.Collections.Generic Namespace MyNamespace Interface Foo - Function Bar( ByRef x As {left}) As Integer + Function Bar( ByRef x As {left}) As Task(Of Integer) End Interface Public Class FooTests @@ -884,16 +911,17 @@ End Namespace public override async Task ReportsDiagnostic_WhenAccessingArgumentByTypeNotInInvocationForNestedCall(string method) { var source = $@"Imports System +Imports System.Threading.Tasks Imports NSubstitute Imports NSubstitute.ExceptionExtensions Namespace MyNamespace Interface IFoo - Function Bar(ByVal x As Integer) As Integer + Function Bar(ByVal x As Integer) As Task(Of Integer) End Interface Interface IFooBar - Function FooBaz(ByVal x As Integer) As Integer + Function FooBaz(ByVal x As Integer) As Task(Of Integer) End Interface Public Class FooTests