未验证 提交 8a7bfd86 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #45608 from sharwell/make-synchronous

Convert MakeMethodSynchronousTests to the new test library
......@@ -2,25 +2,21 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic.MakeMethodSynchronous
Imports Microsoft.CodeAnalysis.Testing
Imports VerifyVB = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.VisualBasicCodeFixVerifier(
Of Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer,
Microsoft.CodeAnalysis.VisualBasic.MakeMethodSynchronous.VisualBasicMakeMethodSynchronousCodeFixProvider)
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.MakeMethodSynchronous
Public Class MakeMethodSynchronousTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As (DiagnosticAnalyzer, CodeFixProvider)
Return (Nothing, New VisualBasicMakeMethodSynchronousCodeFixProvider())
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestTaskReturnType() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Async Function [|Goo|]() As Task
Async Function {|BC42356:Goo|}() As Task
End Function
End Class",
"Imports System.Threading.Tasks
......@@ -33,11 +29,11 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestTaskOfTReturnType() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Async Function [|Goo|]() As Task(of String)
Async Function {|BC42356:Goo|}() As Task(of String)
End Function
End Class",
"Imports System.Threading.Tasks
......@@ -50,11 +46,11 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestSecondModifier() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Public Async Function [|Goo|]() As Task
Public Async Function {|BC42356:Goo|}() As Task
End Function
End Class",
"Imports System.Threading.Tasks
......@@ -67,11 +63,11 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestFirstModifier() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Async Public Function [|Goo|]() As Task
Async Public Function {|BC42356:Goo|}() As Task
End Function
End Class",
"Imports System.Threading.Tasks
......@@ -84,11 +80,11 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestRenameMethod() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Async Sub [|GooAsync|]()
Async Sub {|BC42356:GooAsync|}()
End Sub
End Class",
"Imports System.Threading.Tasks
......@@ -101,11 +97,11 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestRenameMethod1() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System.Threading.Tasks
Class C
Async Sub [|GooAsync|]()
Async Sub {|BC42356:GooAsync|}()
End Sub
Sub Bar()
......@@ -126,14 +122,14 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestSingleLineSubLambda() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System
Imports System.Threading.Tasks
Class C
Sub Goo()
dim f as Action(of Task) =
Async [|Sub|]() Return
Async {|BC42356:Sub|}() Return
End Sub
End Class",
"Imports System
......@@ -149,37 +145,45 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestSingleLineFunctionLambda() As Task
Await TestInRegularAndScriptAsync(
Dim source =
"Imports System
Imports System.Threading.Tasks
Class C
Sub Goo()
dim f as Func(of Task) =
Async [|Function|]() 1
Async {|BC42356:Function|}() 1
End Sub
End Class",
End Class"
Dim expected =
"Imports System
Imports System.Threading.Tasks
Class C
Sub Goo()
dim f as Func(of Task) =
Function() 1
Function() {|#0:1|}
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
' /0/Test0.vb(7) : error BC30311: Value of type 'Integer' cannot be converted to 'Task'.
test.FixedState.ExpectedDiagnostics.Add(DiagnosticResult.CompilerError("BC30311").WithLocation(0).WithArguments("Integer", "System.Threading.Tasks.Task"))
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestMultiLineSubLambda() As Task
Await TestInRegularAndScriptAsync(
Await VerifyVB.VerifyCodeFixAsync(
"Imports System
Imports System.Threading.Tasks
Class C
Sub Goo()
dim f as Action(of Task) =
Async [|Sub|]()
Async {|BC42356:Sub|}()
Return
End Sub
End Sub
......@@ -199,18 +203,19 @@ End Class")
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
Public Async Function TestMultiLineFunctionLambda() As Task
Await TestInRegularAndScriptAsync(
Dim source =
"Imports System
Imports System.Threading.Tasks
Class C
Sub Goo()
dim f as Func(of Task) =
Async [|Function|]()
Async {|BC42356:Function|}()
Return 1
End Function
End Sub
End Class",
End Class"
Dim expected =
"Imports System
Imports System.Threading.Tasks
......@@ -218,166 +223,221 @@ Class C
Sub Goo()
dim f as Func(of Task) =
Function()
Return 1
Return {|#0:1|}
End Function
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
' /0/Test0.vb(8) : error BC30311: Value of type 'Integer' cannot be converted to 'Task'.
test.FixedState.ExpectedDiagnostics.Add(DiagnosticResult.CompilerError("BC30311").WithLocation(0).WithArguments("Integer", "System.Threading.Tasks.Task"))
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCaller1() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|]() As Task
Async Function {|BC42356:GooAsync|}() As Task
End Function
Async Sub BarAsync()
Await GooAsync()
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Sub Goo()
End Sub
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Goo()
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCaller2() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|]() As Task
Async Function {|BC42356:GooAsync|}() As Task
End Function
Async Sub BarAsync()
Await GooAsync().ConfigureAwait(false)
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Sub Goo()
End Sub
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Goo()
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCaller3() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|]() As Task
Async Function {|BC42356:GooAsync|}() As Task
End Function
Async Sub BarAsync()
Await Me.GooAsync()
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Sub Goo()
End Sub
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Me.Goo()
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCaller4() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|]() As Task
Async Function {|BC42356:GooAsync|}() As Task
End Function
Async Sub BarAsync()
Await Me.GooAsync().ConfigureAwait(false)
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Sub Goo()
End Sub
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Me.Goo()
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCallerNested1() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|](i As Integer) As Task(Of Integer)
Async Function {|BC42356:GooAsync|}(i As Integer) As Task(Of Integer)
End Function
Async Sub BarAsync()
Await GooAsync(Await GooAsync(0))
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Function Goo(i As Integer) As Integer
End Function
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Goo(Goo(0))
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)>
<WorkItem(13961, "https://github.com/dotnet/roslyn/issues/13961")>
Public Async Function TestRemoveAwaitFromCallerNested2() As Task
Await TestInRegularAndScriptAsync(
"Imports System.Threading.Tasks;
Dim source =
"Imports System.Threading.Tasks
Public Class Class1
Async Function [|GooAsync|](i As Integer) As Task(Of Integer)
Async Function {|BC42356:GooAsync|}(i As Integer) As Task(Of Integer)
End Function
Async Sub BarAsync()
Await Me.GooAsync(Await Me.GooAsync(0).ConfigureAwait(false)).ConfigureAwait(false)
End Sub
End Class",
"Imports System.Threading.Tasks;
End Class"
Dim expected =
"Imports System.Threading.Tasks
Public Class Class1
Function Goo(i As Integer) As Integer
End Function
Async Sub BarAsync()
Async Sub {|BC42356:BarAsync|}()
Me.Goo(Me.Goo(0))
End Sub
End Class")
End Class"
Dim test = New VerifyVB.Test()
test.TestState.Sources.Add(source)
test.FixedState.Sources.Add(expected)
test.FixedState.MarkupHandling = MarkupMode.Allow
test.CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne
Await test.RunAsync()
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册