AbstractCodeFunctionTests.vb 9.6 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 133
        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

        Protected Sub TestCanOverride(code As XElement, expected As Boolean)
134 135 136 137
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, codeElement.CanOverride)
                End Sub)
138 139 140 141 142 143 144
        End Sub

        Protected Sub TestSetCanOverride(code As XElement, expectedCode As XElement, value As Boolean)
            TestSetCanOverride(code, expectedCode, value, NoThrow(Of Boolean)())
        End Sub

        Protected Sub TestSetCanOverride(code As XElement, expectedCode As XElement, value As Boolean, action As SetterAction(Of Boolean))
145 146 147 148
            TestElementUpdate(code, expectedCode,
                Sub(codeElement)
                    action(value, Sub(v) codeElement.CanOverride = v)
                End Sub)
149 150 151
        End Sub

        Protected Sub TestIsOverloaded(code As XElement, expectedOverloaded As Boolean)
152 153 154 155 156
            TestElement(code,
                Sub(codeElement)
                    Dim overloaded = GetIsOverloaded(codeElement)
                    Assert.Equal(expectedOverloaded, overloaded)
                End Sub)
157 158 159
        End Sub

        Protected Sub TestOverloadsUniqueSignatures(code As XElement, ParamArray expectedOverloadNames As String())
160 161 162 163 164 165 166 167 168 169
            TestElement(code,
                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)
170 171
        End Sub

172
        Protected Sub TestFunctionKind(code As XElement, expected As EnvDTE.vsCMFunction)
173 174 175 176
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, codeElement.FunctionKind)
                End Sub)
177
        End Sub
D
Dustin Campbell 已提交
178

179
        Protected Sub TestFunctionKind(code As XElement, expected As EnvDTE80.vsCMFunction2)
180 181 182 183
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, CType(codeElement.FunctionKind, EnvDTE80.vsCMFunction2))
                End Sub)
184
        End Sub
185

186
        Protected Sub TestExtensionMethodExtender_IsExtension(code As XElement, expected As Boolean)
187 188 189 190
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, ExtensionMethodExtender_GetIsExtension(codeElement))
                End Sub)
191 192 193
        End Sub

        Protected Sub TestPartialMethodExtender_IsPartial(code As XElement, expected As Boolean)
194 195 196 197
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetIsPartial(codeElement))
                End Sub)
198 199 200
        End Sub

        Protected Sub TestPartialMethodExtender_IsDeclaration(code As XElement, expected As Boolean)
201 202 203 204
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetIsDeclaration(codeElement))
                End Sub)
205 206 207
        End Sub

        Protected Sub TestPartialMethodExtender_HasOtherPart(code As XElement, expected As Boolean)
208 209 210 211
            TestElement(code,
                Sub(codeElement)
                    Assert.Equal(expected, PartialMethodExtender_GetHasOtherPart(codeElement))
                End Sub)
212 213 214 215
        End Sub

    End Class
End Namespace