提交 9025ad48 编写于 作者: C CyrusNajmabadi

Add VB tests.

上级 f904ba18
......@@ -136,6 +136,7 @@
<Compile Include="CodeActions\IntroduceVariable\IntroduceVariableTests.vb" />
<Compile Include="CodeActions\InvertIf\InvertIfTests.vb" />
<Compile Include="CodeActions\Preview\PreviewTests.vb" />
<Compile Include="CodeActions\ReplacePropertyWithMethods\ReplacePropertyWithMethodsTests.vb" />
<Compile Include="Diagnostics\AddImport\AddImportTests_NuGet.vb" />
<Compile Include="Diagnostics\ImplementAbstractClass\ImplementAbstractClassTests_FixAllTests.vb" />
<Compile Include="Diagnostics\ImplementInterface\ImplementInterfaceTests_FixAllTests.vb" />
......@@ -609,4 +610,4 @@
<Import Project="..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings
Imports Microsoft.CodeAnalysis.ReplacePropertyWithMethods
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeActions.ReplacePropertyWithMethods
Public Class ReplacePropertyWithMethodsTests
Inherits AbstractVisualBasicCodeActionTest
Protected Overrides Function CreateCodeRefactoringProvider(workspace As Workspace) As Object
Return New ReplacePropertyWithMethodsCodeRefactoringProvider()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestGetWithBody() As Task
Await TestAsync(
"class C
readonly property [||]Prop as integer
get
return 0
end get
end property
end class",
"class C
Public Function GetProp() As Integer
return 0
End Function
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestPrivateProperty() As Task
Await TestAsync(
"class C
private readonly property [||]Prop as integer
get
return 0
end get
end property
end class",
"class C
Private Function GetProp() As Integer
return 0
End Function
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAnonyousType1() As Task
Await TestAsync(
"class C
public readonly property [||]Prop as integer
get
return 0
end get
end property
public sub M()
dim v = new with { .P = me.Prop }
end sub
end class",
"class C
Public Function GetProp() As Integer
return 0
End Function
public sub M()
dim v = new with { .P = me.GetProp() }
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAnonyousType2() As Task
Await TestAsync(
"class C
public readonly [||]Prop as integer
get
return 0
end get
end property
public sub M()
dim v = new with { me.Prop }
end sub
end class",
"class C
Public Function GetProp() As Integer
return 0
End Function
public sub M()
dim v = new with { .Prop = me.GetProp() }
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestPassedToRef1() As Task
Await TestAsync(
"class C
public readonly [||]Prop as integer
get
return 0
end get
end property
public sub RefM(byref i as integer)
end sub
public sub M()
RefM(me.Prop)
end sub
end class",
"class C
Public Function GetProp() As Integer
return 0
End Function
public sub RefM(byref i as integer)
end sub
public sub M()
RefM(me.{|Conflict:GetProp|}())
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestUsedInAttribute1() As Task
Await TestAsync(
"
imports System
class CAttribute
inherits Attribute
public readonly property [||]Prop as integer
get
return 0
end get
end property
end class
<C(Prop:=1)>
class D
end class
",
"
imports System
class CAttribute
inherits Attribute
Public Function GetProp() As Integer
return 0
End Function
end class
<C({|Conflict:Prop|}:=1)>
class D
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestSetWithBody1() As Task
Await TestAsync(
"class C
writeonly property [||]Prop as integer
set
dim v = value
end set
end property
end class",
"class C
Public Sub SetProp(Value As Integer)
dim v = value
End Sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestSetWithBody2() As Task
Await TestAsync(
"class C
writeonly property [||]Prop as integer
set(val as integer)
dim v = val
end set
end property
end class",
"class C
Public Sub SetProp(val As Integer)
dim v = val
End Sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestSetReference1() As Task
Await TestAsync(
"class C
writeonly property [||]Prop as integer
set(val as integer)
dim v = val
end set
end property
sub M()
me.Prop = 1
end sub
end class",
"class C
Private Sub SetProp(Value As Integer)
dim v = value
End Sub
sub M()
me.SetProp(1)
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestGetterAndSetter() As Task
Await TestAsync(
"class C
property [||]Prop as integer
get
return 0
end get
set
dim v = value
end set
end property
end class",
"class C
Public Function GetProp() As Integer
return 0
End Function
Public Sub SetProp(Value As Integer)
dim v = value
End Sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestRecursiveGet() As Task
Await TestAsync(
"class C
readonly property [||]Prop as integer
get
return me.Prop + 1
end get
end property
end class",
"class C
Public Function GetProp() As Integer
return me.GetProp() + 1
End Function
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestRecursiveSet() As Task
Await TestAsync(
"class C
writeonly property [||]Prop as integer
set
me.Prop = value + 1
end get
end property
end class",
"class C
Public Sub SetProp(Value As Integer)
me.SetProp(value + 1)
End Sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAbstractProperty() As Task
Await TestAsync(
"class C
public readonly mustinherit property[||]Prop as integer
public sub M()
dim v = me.Prop
end sub
end class",
"class C
Public MustInherit Function GetProp() As Integer
public sub M()
dim v = me.GetProp()
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestVirtualProperty() As Task
Await TestAsync(
"class C
public readonly overridable property[||]Prop as integer
get
return 0
end get
end property
public sub M()
dim v = me.Prop
end sub
end class",
"class C
Public Overridable Function GetProp() As Integer
return 0
End Function
public sub M()
dim v = me.GetProp()
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestInterfaceProperty1() As Task
Await TestAsync(
"interface I
readonly property [||]Prop as integer
end interface",
"interface I
Function GetProp() As Integer
end interface")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestInterfaceProperty2() As Task
Await TestAsync(
"interface I
writeonly property [||]Prop as integer
end interface",
"interface I
Sub SetProp(Value As Integer)
end interface")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestInterfaceProperty3() As Task
Await TestAsync(
"interface I
property [||]Prop as integer
end interface",
"interface I
Function GetProp() As Integer
Sub SetProp(Value As Integer)
end interface")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAutoProperty1() As Task
Await TestAsync(
"class C
public readonly property [||]Prop as integer
end class",
"class C
Private _Prop As Integer
Public Function GetProp() As Integer
Return Me._Prop
End Function
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAutoProperty2() As Task
Await TestAsync(
"class C
public readonly property [||]Prop as integer
public sub new()
me.Prop = 1
end sub
end class",
"class C
Private _Prop As Integer
Public Function GetProp() As Integer
Return Me._Prop
End Function
public sub new()
me._Prop = 1
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Async Function TestAutoProperty4() As Task
Await TestAsync(
"class C
public readonly property [||]Prop as integer = 1
end class",
"class C
Private _Prop As Integer = 1
Public Function GetProp() As Integer
Return Me._Prop
End Function
end class")
End Function
End Class
End Namespace
\ No newline at end of file
......@@ -828,6 +828,30 @@ End Class]]></a>.Value.NormalizeLineEndings()
Public Function GetRightSideOfDot(node As SyntaxNode) As SyntaxNode Implements ISyntaxFactsService.GetRightSideOfDot
Throw New NotImplementedException()
End Function
Public Function IsLeftSideOfAssignment(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsLeftSideOfAssignment
Throw New NotImplementedException()
End Function
Public Function IsLeftSideOfAnyAssignment(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsLeftSideOfAnyAssignment
Throw New NotImplementedException()
End Function
Public Function GetRightHandSideOfAssignment(node As SyntaxNode) As SyntaxNode Implements ISyntaxFactsService.GetRightHandSideOfAssignment
Throw New NotImplementedException()
End Function
Public Function IsInferredAnonymousObjectMemberDeclarator(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsInferredAnonymousObjectMemberDeclarator
Throw New NotImplementedException()
End Function
Public Function IsOperandOfIncrementExpression(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsOperandOfIncrementExpression
Throw New NotImplementedException()
End Function
Public Function IsOperandOfIncrementOrDecrementExpression(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsOperandOfIncrementOrDecrementExpression
Throw New NotImplementedException()
End Function
End Class
End Class
End Namespace
......@@ -16,6 +16,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
Return Nothing
End If
' a parameterized property can be trivially converted to a method.
If containingProperty.ParameterList IsNot Nothing Then
Return Nothing
End If
Dim start = If(containingProperty.AttributeLists.Count > 0,
containingProperty.AttributeLists.Last().GetLastToken().GetNextToken().SpanStart,
containingProperty.SpanStart)
......@@ -31,10 +36,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
Return Nothing
End If
If position > containingProperty.ParameterList.Span.End Then
Return Nothing
End If
Return containingProperty
End Function
......@@ -101,7 +102,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
cancellationToken As CancellationToken) As SyntaxNode
Dim statements = New List(Of SyntaxNode)()
Dim getAccessorDeclaration = TryCast(getMethod.DeclaringSyntaxReferences(0).GetSyntax(cancellationToken), AccessorStatementSyntax)
Dim getAccessorDeclaration = If(getMethod.DeclaringSyntaxReferences.Length = 0,
Nothing,
TryCast(getMethod.DeclaringSyntaxReferences(0).GetSyntax(cancellationToken), AccessorStatementSyntax))
If TypeOf getAccessorDeclaration?.Parent Is AccessorBlockSyntax Then
Dim block = DirectCast(getAccessorDeclaration.Parent, AccessorBlockSyntax)
statements.AddRange(block.Statements)
......@@ -122,7 +126,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
cancellationToken As CancellationToken) As SyntaxNode
Dim statements = New List(Of SyntaxNode)()
Dim setAccessorDeclaration = TryCast(setMethod.DeclaringSyntaxReferences(0).GetSyntax(cancellationToken), AccessorStatementSyntax)
Dim setAccessorDeclaration = If(setMethod.DeclaringSyntaxReferences.Length = 0,
Nothing,
TryCast(setMethod.DeclaringSyntaxReferences(0).GetSyntax(cancellationToken), AccessorStatementSyntax))
If TypeOf setAccessorDeclaration?.Parent Is AccessorBlockSyntax Then
Dim block = DirectCast(setAccessorDeclaration.Parent, AccessorBlockSyntax)
statements.AddRange(block.Statements)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册