Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer add parameter to constructor refactoring for all applicable constructors #34041

Merged
merged 14 commits into from
Mar 26, 2019

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis.AddConstructorParametersFromMembers
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings

Expand All @@ -12,6 +14,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.AddConstructorPara
Return New AddConstructorParametersFromMembersCodeRefactoringProvider()
End Function

Protected Overrides Function MassageActions(actions As ImmutableArray(Of CodeAction)) As ImmutableArray(Of CodeAction)
Return FlattenActions(actions)
End Function

<WorkItem(530592, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530592")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestAdd1() As Task
Expand Down Expand Up @@ -56,8 +62,10 @@ index:=1)
End Function

<WorkItem(530592, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530592")>
<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestAddToConstructorWithMostMatchingParameters1() As Task
' behavior change with 33603, now all constructors offered
Await TestInRegularAndScriptAsync(
"Class Program
[|Private i As Integer
Expand All @@ -83,12 +91,14 @@ End Class",
Me.s = s
Me.b = b
End Sub
End Class")
End Class", index:=1)
End Function

<WorkItem(530592, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530592")>
<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestAddOptionalToConstructorWithMostMatchingParameters1() As Task
' behavior change with 33603, now all constructors offered
Await TestInRegularAndScriptAsync(
"Class Program
[|Private i As Integer
Expand All @@ -115,7 +125,7 @@ End Class",
Me.b = b
End Sub
End Class",
index:=1)
index:=3)
End Function

<WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")>
Expand Down Expand Up @@ -304,5 +314,248 @@ End Class",
End Sub
End Class")
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_FirstOfThree() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer)
Me.i = i
End Sub

Public Sub New(i As Integer, j As Integer)
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer)
End Sub
End Class",
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer, l As Integer)
Me.i = i
Me.l = l
End Sub

Public Sub New(i As Integer, j As Integer)
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer)
End Sub
End Class", index:=0)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_SecondOfThree() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer)
Me.i = i
End Sub

Public Sub New(i As Integer, j As Integer)
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer)
End Sub
End Class",
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer)
Me.i = i
End Sub

Public Sub New(i As Integer, j As Integer, l As Integer)
Me.l = l
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer)
End Sub
End Class", index:=1)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_ThirdOfThree() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer)
Me.i = i
End Sub

Public Sub New(i As Integer, j As Integer)
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer)
End Sub
End Class",
"Class Program
Private [|l|] As Integer

Public Sub New(i As Integer)
Me.i = i
End Sub

Public Sub New(i As Integer, j As Integer)
End Sub

Public Sub New(i As Integer, j As Integer, k As Integer, l As Integer)
Me.l = l
End Sub
End Class", index:=2)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_OneMustBeOptional() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|l|] As Integer

' index 0, and 2 as optional
Public Sub New(i As Integer)
Me.i = i
End Sub

' index 3 as optional
Public Sub New(Optional j As Double = Nothing)
End Sub

' index 1, and 4 as optional
Public Sub New(i As Integer, j As Double)
End Sub
End Class",
"Class Program
Private [|l|] As Integer

' index 0, and 2 as optional
Public Sub New(i As Integer)
Me.i = i
End Sub

' index 3 as optional
Public Sub New(Optional j As Double = Nothing)
End Sub

' index 1, and 4 as optional
Public Sub New(i As Integer, j As Double, l As Integer)
Me.l = l
End Sub
End Class", index:=1)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_OneMustBeOptional2() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|l|] As Integer

' index 0, and 2 as optional
Public Sub New(i As Integer)
Me.i = i
End Sub

' index 3 as optional
Public Sub New(Optional j As Double = Nothing)
End Sub

' index 1, and 4 as optional
Public Sub New(i As Integer, j As Double)
End Sub
End Class",
"Class Program
Private [|l|] As Integer

' index 0, and 2 as optional
Public Sub New(i As Integer)
Me.i = i
End Sub

' index 3 as optional
Public Sub New(Optional j As Double = Nothing, Optional l As Integer = Nothing)
Me.l = l
End Sub

' index 1, and 4 as optional
Public Sub New(i As Integer, j As Double)
End Sub
End Class", index:=3)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_AllMustBeOptional1() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|p|] As Integer

Public Sub New(Optional i As Integer = Nothing)
Me.i = i
End Sub

Public Sub New(j As Double, Optional k As Double = Nothing)
End Sub

Public Sub New(l As Integer, m As Integer, Optional n As Integer = Nothing)
End Sub
End Class",
"Class Program
Private p As Integer

Public Sub New(Optional i As Integer = Nothing, Optional p As Integer = Nothing)
Me.i = i
Me.p = p
End Sub

Public Sub New(j As Double, Optional k As Double = Nothing)
End Sub

Public Sub New(l As Integer, m As Integer, Optional n As Integer = Nothing)
End Sub
End Class", index:=0)
End Function

<WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)>
Public Async Function TestMultipleConstructors_AllMustBeOptional2() As Task
Await TestInRegularAndScriptAsync(
"Class Program
Private [|p|] As Integer

Public Sub New(Optional i As Integer = Nothing)
Me.i = i
End Sub

Public Sub New(j As Double, Optional k As Double = Nothing)
End Sub

Public Sub New(l As Integer, m As Integer, Optional n As Integer = Nothing)
End Sub
End Class",
"Class Program
Private p As Integer

Public Sub New(Optional i As Integer = Nothing)
Me.i = i
End Sub

Public Sub New(j As Double, Optional k As Double = Nothing)
End Sub

Public Sub New(l As Integer, m As Integer, Optional n As Integer = Nothing, Optional p As Integer = Nothing)
Me.p = p
End Sub
End Class", index:=2)
End Function
End Class
End Namespace
End Namespace
Loading