AbstractCodeFunctionTests.vb 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
' 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 Microsoft.CodeAnalysis.Editor.UnitTests.Extensions

Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel
    Public MustInherit Class AbstractCodeFunctionTests
        Inherits AbstractCodeElementTests(Of EnvDTE80.CodeFunction2)

        Protected Overrides Function GetStartPointFunc(codeElement As EnvDTE80.CodeFunction2) As Func(Of EnvDTE.vsCMPart, EnvDTE.TextPoint)
            Return Function(part) codeElement.GetStartPoint(part)
        End Function

        Protected Overrides Function GetEndPointFunc(codeElement As EnvDTE80.CodeFunction2) As Func(Of EnvDTE.vsCMPart, EnvDTE.TextPoint)
            Return Function(part) codeElement.GetEndPoint(part)
        End Function

        Protected Overrides Function GetAccess(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.vsCMAccess
            Return codeElement.Access
        End Function

21 22 23 24
        Protected Overrides Function GetAttributes(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.CodeElements
            Return codeElement.Attributes
        End Function

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        Protected Overrides Function GetComment(codeElement As EnvDTE80.CodeFunction2) As String
            Return codeElement.Comment
        End Function

        Protected Overrides Function GetDocComment(codeElement As EnvDTE80.CodeFunction2) As String
            Return codeElement.DocComment
        End Function

        Protected Overrides Function GetFullName(codeElement As EnvDTE80.CodeFunction2) As String
            Return codeElement.FullName
        End Function

        Protected Function GetFunctionKind(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.vsCMFunction
            Return codeElement.FunctionKind
        End Function

        Protected Overrides Function GetKind(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.vsCMElement
            Return codeElement.Kind
        End Function

        Protected Overrides Function GetMustImplement(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Return codeElement.MustImplement
        End Function

        Protected Overrides Function GetName(codeElement As EnvDTE80.CodeFunction2) As String
            Return codeElement.Name
        End Function

        Protected Overridable Function GetIsOverloaded(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Return codeElement.IsOverloaded
        End Function

        Protected Overridable Function GetOverloads(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.CodeElements
            Return codeElement.Overloads
        End Function

        Protected Overrides Function GetOverrideKind(codeElement As EnvDTE80.CodeFunction2) As EnvDTE80.vsCMOverrideKind
            Return codeElement.OverrideKind
        End Function

        Protected Overrides Function GetParent(codeElement As EnvDTE80.CodeFunction2) As Object
            Return codeElement.Parent
        End Function

        Protected Overrides Function GetPrototype(codeElement As EnvDTE80.CodeFunction2, flags As EnvDTE.vsCMPrototype) As String
            Return codeElement.Prototype(flags)
        End Function

        Protected Overrides Function GetAccessSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of EnvDTE.vsCMAccess)
            Return Sub(access) codeElement.Access = access
        End Function

        Protected Overrides Function GetIsSharedSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of Boolean)
            Return Sub(value) codeElement.IsShared = value
        End Function

        Protected Overrides Function GetMustImplementSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of Boolean)
            Return Sub(value) codeElement.MustImplement = value
        End Function

        Protected Overrides Function GetOverrideKindSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of EnvDTE80.vsCMOverrideKind)
            Return Sub(value) codeElement.OverrideKind = value
        End Function

        Protected Overrides Function GetNameSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of String)
            Return Sub(name) codeElement.Name = name
        End Function

        Protected Overrides Function GetTypeProp(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.CodeTypeRef
            Return codeElement.Type
        End Function

        Protected Overrides Function GetTypePropSetter(codeElement As EnvDTE80.CodeFunction2) As Action(Of EnvDTE.CodeTypeRef)
            Return Sub(value) codeElement.Type = value
        End Function

101 102 103 104
        Protected Overrides Function AddAttribute(codeElement As EnvDTE80.CodeFunction2, data As AttributeData) As EnvDTE.CodeAttribute
            Return codeElement.AddAttribute(data.Name, data.Value, data.Position)
        End Function

105 106 107 108 109 110 111 112
        Protected Overrides Function AddParameter(codeElement As EnvDTE80.CodeFunction2, data As ParameterData) As EnvDTE.CodeParameter
            Return codeElement.AddParameter(data.Name, data.Type, data.Position)
        End Function

        Protected Overrides Sub RemoveChild(codeElement As EnvDTE80.CodeFunction2, child As Object)
            codeElement.RemoveParameter(child)
        End Sub

113 114 115 116
        Protected Overrides Function GetParameters(codeElement As EnvDTE80.CodeFunction2) As EnvDTE.CodeElements
            Return codeElement.Parameters
        End Function

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        Protected Overridable Function ExtensionMethodExtender_GetIsExtension(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Throw New NotSupportedException
        End Function

        Protected Overridable Function PartialMethodExtender_GetIsPartial(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Throw New NotSupportedException
        End Function

        Protected Overridable Function PartialMethodExtender_GetIsDeclaration(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Throw New NotSupportedException
        End Function

        Protected Overridable Function PartialMethodExtender_GetHasOtherPart(codeElement As EnvDTE80.CodeFunction2) As Boolean
            Throw New NotSupportedException
        End Function

C
Cyrus Najmabadi 已提交
133 134
        Protected Async Function TestCanOverride(code As XElement, expected As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
135 136 137
                Sub(codeElement)
                    Assert.Equal(expected, codeElement.CanOverride)
                End Sub)
C
Cyrus Najmabadi 已提交
138
        End Function
139

C
Cyrus Najmabadi 已提交
140 141 142
        Protected Async Function TestSetCanOverride(code As XElement, expectedCode As XElement, value As Boolean) As Threading.Tasks.Task
            Await TestSetCanOverride(code, expectedCode, value, NoThrow(Of Boolean)())
        End Function
143

C
Cyrus Najmabadi 已提交
144 145
        Protected Async Function TestSetCanOverride(code As XElement, expectedCode As XElement, value As Boolean, action As SetterAction(Of Boolean)) As Threading.Tasks.Task
            Await TestElementUpdate(code, expectedCode,
146 147 148
                Sub(codeElement)
                    action(value, Sub(v) codeElement.CanOverride = v)
                End Sub)
C
Cyrus Najmabadi 已提交
149
        End Function
150

C
Cyrus Najmabadi 已提交
151 152
        Protected Async Function TestIsOverloaded(code As XElement, expectedOverloaded As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
153 154 155 156
                Sub(codeElement)
                    Dim overloaded = GetIsOverloaded(codeElement)
                    Assert.Equal(expectedOverloaded, overloaded)
                End Sub)
C
Cyrus Najmabadi 已提交
157
        End Function
158

C
Cyrus Najmabadi 已提交
159 160
        Protected Async Function TestOverloadsUniqueSignatures(code As XElement, ParamArray expectedOverloadNames As String()) As Threading.Tasks.Task
            Await TestElement(code,
161 162 163 164 165 166 167 168 169
                Sub(codeElement)
                    Dim actualOverloads = GetOverloads(codeElement)
                    Assert.Equal(expectedOverloadNames.Count, actualOverloads.Count)
                    For index = 1 To actualOverloads.Count
                        Dim codeFunction = CType(actualOverloads.Item(index), EnvDTE80.CodeFunction2)
                        Dim signature = GetPrototype(codeFunction, EnvDTE.vsCMPrototype.vsCMPrototypeUniqueSignature)
                        Assert.True(expectedOverloadNames.Contains(signature))
                    Next
                End Sub)
C
Cyrus Najmabadi 已提交
170
        End Function
171

C
Cyrus Najmabadi 已提交
172 173
        Protected Async Function TestFunctionKind(code As XElement, expected As EnvDTE.vsCMFunction) As Threading.Tasks.Task
            Await TestElement(code,
174 175 176
                Sub(codeElement)
                    Assert.Equal(expected, codeElement.FunctionKind)
                End Sub)
C
Cyrus Najmabadi 已提交
177
        End Function
D
Dustin Campbell 已提交
178

C
Cyrus Najmabadi 已提交
179 180
        Protected Async Function TestFunctionKind(code As XElement, expected As EnvDTE80.vsCMFunction2) As Threading.Tasks.Task
            Await TestElement(code,
181 182 183
                Sub(codeElement)
                    Assert.Equal(expected, CType(codeElement.FunctionKind, EnvDTE80.vsCMFunction2))
                End Sub)
C
Cyrus Najmabadi 已提交
184
        End Function
185

C
Cyrus Najmabadi 已提交
186 187
        Protected Async Function TestExtensionMethodExtender_IsExtension(code As XElement, expected As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
188 189 190
                Sub(codeElement)
                    Assert.Equal(expected, ExtensionMethodExtender_GetIsExtension(codeElement))
                End Sub)
C
Cyrus Najmabadi 已提交
191
        End Function
192

C
Cyrus Najmabadi 已提交
193 194
        Protected Async Function TestPartialMethodExtender_IsPartial(code As XElement, expected As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
195 196 197
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetIsPartial(codeElement))
                End Sub)
C
Cyrus Najmabadi 已提交
198
        End Function
199

C
Cyrus Najmabadi 已提交
200 201
        Protected Async Function TestPartialMethodExtender_IsDeclaration(code As XElement, expected As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
202 203 204
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetIsDeclaration(codeElement))
                End Sub)
C
Cyrus Najmabadi 已提交
205
        End Function
206

C
Cyrus Najmabadi 已提交
207 208
        Protected Async Function TestPartialMethodExtender_HasOtherPart(code As XElement, expected As Boolean) As Threading.Tasks.Task
            Await TestElement(code,
209 210 211
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetHasOtherPart(codeElement))
                End Sub)
C
Cyrus Najmabadi 已提交
212
        End Function
213 214 215

    End Class
End Namespace