MockSymbolNavigationServiceProvider.vb 4.0 KB
Newer Older
1 2 3
' 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.Composition
4
Imports System.Threading
5
Imports Microsoft.CodeAnalysis.FindUsages
6 7 8
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.Navigation
9
Imports Microsoft.CodeAnalysis.Options
10

11
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
12 13 14 15 16 17
    ' Note: by default, TestWorkspace produces a composition from all assemblies except EditorServicesTest2.
    ' This type has to be defined here until we get that cleaned up. Otherwise, other tests may import it.
    <ExportWorkspaceServiceFactory(GetType(ISymbolNavigationService), ServiceLayer.Host), [Shared]>
    Public Class MockSymbolNavigationServiceProvider
        Implements IWorkspaceServiceFactory

B
beep boop 已提交
18
        Private _instance As MockSymbolNavigationService = New MockSymbolNavigationService()
19 20

        Public Function CreateService(workspaceServices As HostWorkspaceServices) As IWorkspaceService Implements IWorkspaceServiceFactory.CreateService
B
beep boop 已提交
21
            Return _instance
22 23 24 25 26
        End Function

        Friend Class MockSymbolNavigationService
            Implements ISymbolNavigationService

27 28
            Public TryNavigateToSymbolProvidedSymbol As ISymbol
            Public TryNavigateToSymbolProvidedProject As Project
29
            Public TryNavigateToSymbolProvidedOptions As OptionSet
30

31 32 33 34
            Public TrySymbolNavigationNotifyProvidedSymbol As ISymbol
            Public TrySymbolNavigationNotifyProvidedSolution As Solution
            Public TrySymbolNavigationNotifyReturnValue As Boolean = False

35
            Public WouldNavigateToSymbolProvidedDefinitionItem As DefinitionItem
36 37 38 39 40
            Public WouldNavigateToSymbolProvidedSolution As Solution
            Public WouldNavigateToSymbolReturnValue As Boolean = False
            Public NavigationFilePathReturnValue As String = String.Empty
            Public NavigationLineNumberReturnValue As Integer = 0
            Public NavigationCharOffsetReturnValue As Integer = 0
41

42
            Public Function TryNavigateToSymbol(symbol As ISymbol, project As Project, Optional options As OptionSet = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Boolean Implements ISymbolNavigationService.TryNavigateToSymbol
43 44
                Me.TryNavigateToSymbolProvidedSymbol = symbol
                Me.TryNavigateToSymbolProvidedProject = project
45
                Me.TryNavigateToSymbolProvidedOptions = options
46 47 48
                Return True
            End Function

49 50 51
            Public Function TrySymbolNavigationNotify(symbol As ISymbol,
                                                      solution As Solution,
                                                      cancellationToken As CancellationToken) As Boolean Implements ISymbolNavigationService.TrySymbolNavigationNotify
52 53 54 55
                Me.TrySymbolNavigationNotifyProvidedSymbol = symbol
                Me.TrySymbolNavigationNotifyProvidedSolution = solution

                Return TrySymbolNavigationNotifyReturnValue
56 57
            End Function

58
            Public Function WouldNavigateToSymbol(definitionItem As DefinitionItem,
59 60 61
                                                  solution As Solution,
                                                  cancellationToken As CancellationToken,
                                                  ByRef filePath As String, ByRef lineNumber As Integer, ByRef charOffset As Integer) As Boolean Implements ISymbolNavigationService.WouldNavigateToSymbol
62
                Me.WouldNavigateToSymbolProvidedDefinitionItem = definitionItem
63 64 65 66 67 68 69
                Me.WouldNavigateToSymbolProvidedSolution = solution

                filePath = Me.NavigationFilePathReturnValue
                lineNumber = Me.NavigationLineNumberReturnValue
                charOffset = Me.NavigationCharOffsetReturnValue

                Return WouldNavigateToSymbolReturnValue
70 71 72 73
            End Function
        End Class
    End Class
End Namespace