diff --git a/test/PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1 b/test/PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1 index ef37455fa..925cd85b4 100644 --- a/test/PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1 +++ b/test/PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1 @@ -1,3 +1,7 @@ -function Assert-ProfileLoaded { +if (-not $PROFILE) { + throw +} + +function Assert-ProfileLoaded { return $true -} \ No newline at end of file +} diff --git a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs index 18d2e5467..b3cd602b6 100644 --- a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs +++ b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs @@ -110,37 +110,34 @@ public async Task CanCancelExecutionWithMethod() [Fact] public async Task CanResolveAndLoadProfilesForHostId() { - string[] expectedProfilePaths = - new string[] - { - PsesHostFactory.TestProfilePaths.AllUsersAllHosts, - PsesHostFactory.TestProfilePaths.AllUsersCurrentHost, - PsesHostFactory.TestProfilePaths.CurrentUserAllHosts, - PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost - }; - // Load the profiles for the test host name await psesHost.LoadHostProfilesAsync(CancellationToken.None).ConfigureAwait(true); - // Ensure that all the paths are set in the correct variables - // and that the current user's host profile got loaded - PSCommand psCommand = new PSCommand().AddScript( - "\"$($profile.AllUsersAllHosts) " + - "$($profile.AllUsersCurrentHost) " + - "$($profile.CurrentUserAllHosts) " + - "$($profile.CurrentUserCurrentHost) " + - "$(Assert-ProfileLoaded)\""); - - IReadOnlyList result = await psesHost.ExecutePSCommandAsync(psCommand, CancellationToken.None).ConfigureAwait(true); - - string expectedString = - string.Format( - "{0} True", - string.Join( - " ", - expectedProfilePaths)); - - Assert.Equal(expectedString, result[0], ignoreCase: true); + // Ensure that the $PROFILE variable is a string with the value of CurrentUserCurrentHost. + IReadOnlyList profileVariable = await psesHost.ExecutePSCommandAsync( + new PSCommand().AddScript("$PROFILE"), + CancellationToken.None).ConfigureAwait(true); + + Assert.Collection(profileVariable, + (p) => Assert.Equal(PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost, p)); + + // Ensure that all the profile paths are set in the correct note properties. + IReadOnlyList profileProperties = await psesHost.ExecutePSCommandAsync( + new PSCommand().AddScript("$PROFILE | Get-Member -Type NoteProperty"), + CancellationToken.None).ConfigureAwait(true); + + Assert.Collection(profileProperties, + (p) => Assert.Equal($"string AllUsersAllHosts={PsesHostFactory.TestProfilePaths.AllUsersAllHosts}", p, ignoreCase: true), + (p) => Assert.Equal($"string AllUsersCurrentHost={PsesHostFactory.TestProfilePaths.AllUsersCurrentHost}", p, ignoreCase: true), + (p) => Assert.Equal($"string CurrentUserAllHosts={PsesHostFactory.TestProfilePaths.CurrentUserAllHosts}", p, ignoreCase: true), + (p) => Assert.Equal($"string CurrentUserCurrentHost={PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost}", p, ignoreCase: true)); + + // Ensure that the profile was loaded. The profile also checks that $PROFILE was defined. + IReadOnlyList profileLoaded = await psesHost.ExecutePSCommandAsync( + new PSCommand().AddScript("Assert-ProfileLoaded"), + CancellationToken.None).ConfigureAwait(true); + + Assert.Collection(profileLoaded, (p) => Assert.True(p)); } [Fact]