22// Licensed under the MIT License.
33
44using System ;
5- using System . Collections . Generic ;
6- using System . Collections . ObjectModel ;
75using System . Globalization ;
86using System . IO ;
9- using System . Management . Automation ;
107using System . Management . Automation . Host ;
118using System . Management . Automation . Runspaces ;
12- using System . Security ;
139using System . Threading ;
14- using System . Threading . Tasks ;
1510using Microsoft . Extensions . Logging ;
16- using Microsoft . Extensions . Logging . Abstractions ;
1711using Microsoft . PowerShell . EditorServices . Hosting ;
1812using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
1913using Microsoft . PowerShell . EditorServices . Test . Shared ;
@@ -23,11 +17,11 @@ namespace Microsoft.PowerShell.EditorServices.Test
2317{
2418 internal static class PsesHostFactory
2519 {
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.
2822
2923 public static readonly ProfilePathInfo TestProfilePaths =
30- new ProfilePathInfo (
24+ new (
3125 Path . GetFullPath (
3226 TestUtilities . NormalizePath ( "../../../../PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1" ) ) ,
3327 Path . GetFullPath (
@@ -58,7 +52,7 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
5852 initialSessionState . ExecutionPolicy = ExecutionPolicy . Bypass ;
5953 }
6054
61- HostStartupInfo testHostDetails = new HostStartupInfo (
55+ HostStartupInfo testHostDetails = new (
6256 "PowerShell Editor Services Test Host" ,
6357 "Test.PowerShellEditorServices" ,
6458 new Version ( "1.0.0" ) ,
@@ -75,50 +69,28 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
7569
7670 var psesHost = new PsesInternalHost ( loggerFactory , null , testHostDetails ) ;
7771
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+ if ( psesHost . TryStartAsync ( new HostStartOptions { LoadProfiles = true } , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) )
74+ {
75+ return psesHost ;
76+ }
7977
80- return psesHost ;
78+ throw new Exception ( "Host didn't start!" ) ;
8179 }
8280 }
8381
8482 internal class NullPSHost : PSHost
8583 {
8684 public override CultureInfo CurrentCulture => CultureInfo . CurrentCulture ;
87-
8885 public override CultureInfo CurrentUICulture => CultureInfo . CurrentUICulture ;
89-
9086 public override Guid InstanceId { get ; } = Guid . NewGuid ( ) ;
91-
9287 public override string Name => nameof ( NullPSHost ) ;
93-
9488 public override PSHostUserInterface UI { get ; } = new NullPSHostUI ( ) ;
95-
9689 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- }
90+ public override void EnterNestedPrompt ( ) { /* Do nothing */ }
91+ public override void ExitNestedPrompt ( ) { /* Do nothing */ }
92+ public override void NotifyBeginApplication ( ) { /* Do nothing */ }
93+ public override void NotifyEndApplication ( ) { /* Do nothing */ }
94+ public override void SetShouldExit ( int exitCode ) { /* Do nothing */ }
12295 }
12396}
124-
0 commit comments