1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
#nullable enable
4
-
4
+ using System ;
5
+ using System . Collections . Generic ;
5
6
using System . Threading ;
6
7
using System . Threading . Tasks ;
8
+ using MediatR ;
9
+ using Microsoft . Extensions . Configuration ;
7
10
using Microsoft . Extensions . Logging . Abstractions ;
11
+ using Microsoft . Extensions . Primitives ;
8
12
using Microsoft . PowerShell . EditorServices . Handlers ;
9
13
using Microsoft . PowerShell . EditorServices . Services ;
10
14
using Microsoft . PowerShell . EditorServices . Test . Shared ;
15
+ using Newtonsoft . Json . Linq ;
16
+ using OmniSharp . Extensions . JsonRpc ;
11
17
using OmniSharp . Extensions . LanguageServer . Protocol ;
12
18
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
19
+ using OmniSharp . Extensions . LanguageServer . Protocol . Progress ;
20
+ using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
13
21
using Xunit ;
14
22
using static PowerShellEditorServices . Test . Handlers . RefactorFunctionTests ;
15
23
using static PowerShellEditorServices . Test . Refactoring . RefactorUtilities ;
@@ -27,7 +35,9 @@ public PrepareRenameHandlerTests()
27
35
{
28
36
Uri = DocumentUri . FromFileSystemPath ( TestUtilities . GetSharedPath ( "Refactoring" ) )
29
37
} ) ;
30
- handler = new ( workspace ) ;
38
+ // FIXME: Need to make a Mock<ILanguageServerFacade> to pass to the ExtensionService constructor
39
+
40
+ handler = new ( workspace , new fakeLspSendMessageRequestFacade ( "I Accept" ) , new fakeConfigurationService ( ) ) ;
31
41
}
32
42
33
43
// TODO: Test an untitled document (maybe that belongs in E2E tests)
@@ -55,3 +65,52 @@ public async Task FindsSymbol(RenameSymbolParamsSerialized param)
55
65
Assert . True ( result . Range . Contains ( position ) ) ;
56
66
}
57
67
}
68
+
69
+ public class fakeLspSendMessageRequestFacade ( string title ) : ILanguageServerFacade
70
+ {
71
+ public async Task < TResponse > SendRequest < TResponse > ( IRequest < TResponse > request , CancellationToken cancellationToken )
72
+ {
73
+ if ( request is ShowMessageRequestParams )
74
+ {
75
+ return ( TResponse ) ( object ) new MessageActionItem { Title = title } ;
76
+ }
77
+ else
78
+ {
79
+ throw new NotSupportedException ( ) ;
80
+ }
81
+ }
82
+
83
+ public ITextDocumentLanguageServer TextDocument => throw new NotImplementedException ( ) ;
84
+ public INotebookDocumentLanguageServer NotebookDocument => throw new NotImplementedException ( ) ;
85
+ public IClientLanguageServer Client => throw new NotImplementedException ( ) ;
86
+ public IGeneralLanguageServer General => throw new NotImplementedException ( ) ;
87
+ public IWindowLanguageServer Window => throw new NotImplementedException ( ) ;
88
+ public IWorkspaceLanguageServer Workspace => throw new NotImplementedException ( ) ;
89
+ public IProgressManager ProgressManager => throw new NotImplementedException ( ) ;
90
+ public InitializeParams ClientSettings => throw new NotImplementedException ( ) ;
91
+ public InitializeResult ServerSettings => throw new NotImplementedException ( ) ;
92
+ public object GetService ( Type serviceType ) => throw new NotImplementedException ( ) ;
93
+ public IDisposable Register ( Action < ILanguageServerRegistry > registryAction ) => throw new NotImplementedException ( ) ;
94
+ public void SendNotification ( string method ) => throw new NotImplementedException ( ) ;
95
+ public void SendNotification < T > ( string method , T @params ) => throw new NotImplementedException ( ) ;
96
+ public void SendNotification ( IRequest request ) => throw new NotImplementedException ( ) ;
97
+ public IResponseRouterReturns SendRequest ( string method ) => throw new NotImplementedException ( ) ;
98
+ public IResponseRouterReturns SendRequest < T > ( string method , T @params ) => throw new NotImplementedException ( ) ;
99
+ public bool TryGetRequest ( long id , out string method , out TaskCompletionSource < JToken > pendingTask ) => throw new NotImplementedException ( ) ;
100
+ }
101
+
102
+ public class fakeConfigurationService : ILanguageServerConfiguration
103
+ {
104
+ public string this [ string key ] { get => throw new NotImplementedException ( ) ; set => throw new NotImplementedException ( ) ; }
105
+
106
+ public bool IsSupported => throw new NotImplementedException ( ) ;
107
+
108
+ public ILanguageServerConfiguration AddConfigurationItems ( IEnumerable < ConfigurationItem > configurationItems ) => throw new NotImplementedException ( ) ;
109
+ public IEnumerable < IConfigurationSection > GetChildren ( ) => throw new NotImplementedException ( ) ;
110
+ public Task < IConfiguration > GetConfiguration ( params ConfigurationItem [ ] items ) => throw new NotImplementedException ( ) ;
111
+ public IChangeToken GetReloadToken ( ) => throw new NotImplementedException ( ) ;
112
+ public Task < IScopedConfiguration > GetScopedConfiguration ( DocumentUri scopeUri , CancellationToken cancellationToken ) => throw new NotImplementedException ( ) ;
113
+ public IConfigurationSection GetSection ( string key ) => throw new NotImplementedException ( ) ;
114
+ public ILanguageServerConfiguration RemoveConfigurationItems ( IEnumerable < ConfigurationItem > configurationItems ) => throw new NotImplementedException ( ) ;
115
+ public bool TryGetScopedConfiguration ( DocumentUri scopeUri , out IScopedConfiguration configuration ) => throw new NotImplementedException ( ) ;
116
+ }
0 commit comments