2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
- using System . Collections . Generic ;
6
- using System . Collections . ObjectModel ;
7
5
using System . Globalization ;
8
6
using System . IO ;
9
- using System . Management . Automation ;
10
7
using System . Management . Automation . Host ;
11
8
using System . Management . Automation . Runspaces ;
12
- using System . Security ;
13
9
using System . Threading ;
14
- using System . Threading . Tasks ;
15
10
using Microsoft . Extensions . Logging ;
16
- using Microsoft . Extensions . Logging . Abstractions ;
17
11
using Microsoft . PowerShell . EditorServices . Hosting ;
18
12
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
19
13
using Microsoft . PowerShell . EditorServices . Test . Shared ;
@@ -23,11 +17,11 @@ namespace Microsoft.PowerShell.EditorServices.Test
23
17
{
24
18
internal static class PsesHostFactory
25
19
{
26
- // NOTE: These paths are arbitrarily chosen just to verify that the profile paths
27
- // can be set to whatever they need to be for the given host.
20
+ // NOTE: These paths are arbitrarily chosen just to verify that the profile paths can be set
21
+ // to whatever they need to be for the given host.
28
22
29
23
public static readonly ProfilePathInfo TestProfilePaths =
30
- new ProfilePathInfo (
24
+ new (
31
25
Path . GetFullPath (
32
26
TestUtilities . NormalizePath ( "../../../../PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1" ) ) ,
33
27
Path . GetFullPath (
@@ -58,7 +52,7 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
58
52
initialSessionState . ExecutionPolicy = ExecutionPolicy . Bypass ;
59
53
}
60
54
61
- HostStartupInfo testHostDetails = new HostStartupInfo (
55
+ HostStartupInfo testHostDetails = new (
62
56
"PowerShell Editor Services Test Host" ,
63
57
"Test.PowerShellEditorServices" ,
64
58
new Version ( "1.0.0" ) ,
@@ -75,50 +69,29 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
75
69
76
70
var psesHost = new PsesInternalHost ( loggerFactory , null , testHostDetails ) ;
77
71
78
- psesHost . TryStartAsync ( new HostStartOptions { LoadProfiles = true } , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
72
+ // NOTE: Because this is used by constructors it can't use await.
73
+ // TODO: Should we actually load profiles here?
74
+ if ( psesHost . TryStartAsync ( new HostStartOptions { LoadProfiles = true } , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) )
75
+ {
76
+ return psesHost ;
77
+ }
79
78
80
- return psesHost ;
79
+ throw new Exception ( "Host didn't start!" ) ;
81
80
}
82
81
}
83
82
84
83
internal class NullPSHost : PSHost
85
84
{
86
85
public override CultureInfo CurrentCulture => CultureInfo . CurrentCulture ;
87
-
88
86
public override CultureInfo CurrentUICulture => CultureInfo . CurrentUICulture ;
89
-
90
87
public override Guid InstanceId { get ; } = Guid . NewGuid ( ) ;
91
-
92
88
public override string Name => nameof ( NullPSHost ) ;
93
-
94
89
public override PSHostUserInterface UI { get ; } = new NullPSHostUI ( ) ;
95
-
96
90
public override Version Version { get ; } = new Version ( 1 , 0 , 0 ) ;
97
-
98
- public override void EnterNestedPrompt ( )
99
- {
100
- // Do nothing
101
- }
102
-
103
- public override void ExitNestedPrompt ( )
104
- {
105
- // Do nothing
106
- }
107
-
108
- public override void NotifyBeginApplication ( )
109
- {
110
- // Do nothing
111
- }
112
-
113
- public override void NotifyEndApplication ( )
114
- {
115
- // Do nothing
116
- }
117
-
118
- public override void SetShouldExit ( int exitCode )
119
- {
120
- // Do nothing
121
- }
91
+ public override void EnterNestedPrompt ( ) { /* Do nothing */ }
92
+ public override void ExitNestedPrompt ( ) { /* Do nothing */ }
93
+ public override void NotifyBeginApplication ( ) { /* Do nothing */ }
94
+ public override void NotifyEndApplication ( ) { /* Do nothing */ }
95
+ public override void SetShouldExit ( int exitCode ) { /* Do nothing */ }
122
96
}
123
97
}
124
-
0 commit comments