diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs index 7b8e27da..a50c2239 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs @@ -53,7 +53,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -104,7 +104,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -155,7 +155,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs index 62e96d9f..f9afb7d7 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs @@ -51,7 +51,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -100,7 +100,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -149,7 +149,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs index 43733a51..fd2b7e7c 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs @@ -55,7 +55,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -108,7 +108,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -161,7 +161,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index 17a7d2d3..a59bd6a0 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -53,7 +53,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -104,7 +104,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -155,7 +155,7 @@ public void Test() }} }}"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs index 4f24adf0..5953d621 100644 --- a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs +++ b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/CodeFixVerifier.cs @@ -24,11 +24,6 @@ protected CodeFixVerifier(WorkspaceFactory workspaceFactory) protected abstract DiagnosticAnalyzer DiagnosticAnalyzer { get; } - protected Task VerifyFix( - string oldSource, - string newSource, - NSubstituteVersion version) => VerifyFix(oldSource, newSource, null, version); - protected async Task VerifyFix( string oldSource, string newSource, diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/SyncOverAsyncThrowsCodeFixActionsTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/SyncOverAsyncThrowsCodeFixActionsTests.cs index 37082437..3084d811 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/SyncOverAsyncThrowsCodeFixActionsTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/SyncOverAsyncThrowsCodeFixActionsTests.cs @@ -39,7 +39,7 @@ End Sub End Class End Namespace"; - await VerifyCodeActions(source, expectedCodeActionTitle); + await VerifyCodeActions(source, NSubstituteVersion.NSubstitute4_2_2, expectedCodeActionTitle); } [Theory] diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs index 1c0f30b4..b3ca3ade 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionMethodTests.cs @@ -45,7 +45,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -88,7 +88,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -131,7 +131,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs index 67c4c597..32080fbc 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsExtensionsMethodWithGenericTypeSpecifiedTests.cs @@ -43,7 +43,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -84,7 +84,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -125,7 +125,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs index 9c2897fd..e129b64b 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodTests.cs @@ -47,7 +47,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -92,7 +92,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -137,7 +137,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index d1c75fae..b6520d8d 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SyncOverAsyncThrowsCodeFixProviderTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using NSubstitute.Analyzers.Tests.Shared; namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SyncOverAsyncThrowsCodeFixProviderTests; @@ -44,7 +45,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod) @@ -87,7 +88,7 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod) @@ -130,21 +131,135 @@ End Sub End Class End Namespace"; - await VerifyFix(source, newSource); + await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2); } - public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) + public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod) { - throw new System.NotImplementedException(); + var source = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Function Bar() As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{method}(Of Exception)(substitute.Bar()) + ExceptionExtensions.{method}(Of Exception)(value := substitute.Bar()) + End Sub + End Class +End Namespace"; + + var newSource = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Function Bar() As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{updatedMethod}(Of Exception)(substitute.Bar()) + ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute.Bar()) + End Sub + End Class +End Namespace"; + + await VerifyFix(source, newSource); } - public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInProperty(string method, string updatedMethod) + public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInProperty(string method, string updatedMethod) { - throw new System.NotImplementedException(); + var source = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Property Bar As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{method}(Of Exception)(substitute.Bar) + ExceptionExtensions.{method}(Of Exception)(value := substitute.Bar) + End Sub + End Class +End Namespace"; + + var newSource = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Property Bar As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{updatedMethod}(Of Exception)(substitute.Bar) + ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute.Bar) + End Sub + End Class +End Namespace"; + + await VerifyFix(source, newSource); } - public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInIndexer(string method, string updatedMethod) + public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInIndexer(string method, string updatedMethod) { - throw new System.NotImplementedException(); + var source = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Default Property Item(ByVal x As Integer) As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{method}(Of Exception)(substitute(0)) + ExceptionExtensions.{method}(Of Exception)(value := substitute(0)) + End Sub + End Class +End Namespace"; + + var newSource = $@"Imports System +Imports System.Threading.Tasks +Imports NSubstitute +Imports NSubstitute.ExceptionExtensions + +Namespace MyNamespace + Interface IFoo + Default Property Item(ByVal x As Integer) As Task + End Interface + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For](Of IFoo)() + ExceptionExtensions.{updatedMethod}(Of Exception)(substitute(0)) + ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute(0)) + End Sub + End Class +End Namespace"; + + await VerifyFix(source, newSource); } } \ No newline at end of file