Skip to content

Commit b4330f4

Browse files
committed
Improve $PROFILE variable and profile loading test
1 parent 10cff26 commit b4330f4

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

+24-28
Original file line numberDiff line numberDiff line change
@@ -110,37 +110,33 @@ public async Task CanCancelExecutionWithMethod()
110110
[Fact]
111111
public async Task CanResolveAndLoadProfilesForHostId()
112112
{
113-
string[] expectedProfilePaths =
114-
new string[]
115-
{
116-
PsesHostFactory.TestProfilePaths.AllUsersAllHosts,
117-
PsesHostFactory.TestProfilePaths.AllUsersCurrentHost,
118-
PsesHostFactory.TestProfilePaths.CurrentUserAllHosts,
119-
PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost
120-
};
121-
122113
// Load the profiles for the test host name
123114
await psesHost.LoadHostProfilesAsync(CancellationToken.None).ConfigureAwait(true);
124115

125-
// Ensure that all the paths are set in the correct variables
126-
// and that the current user's host profile got loaded
127-
PSCommand psCommand = new PSCommand().AddScript(
128-
"\"$($profile.AllUsersAllHosts) " +
129-
"$($profile.AllUsersCurrentHost) " +
130-
"$($profile.CurrentUserAllHosts) " +
131-
"$($profile.CurrentUserCurrentHost) " +
132-
"$(Assert-ProfileLoaded)\"");
133-
134-
IReadOnlyList<string> result = await psesHost.ExecutePSCommandAsync<string>(psCommand, CancellationToken.None).ConfigureAwait(true);
135-
136-
string expectedString =
137-
string.Format(
138-
"{0} True",
139-
string.Join(
140-
" ",
141-
expectedProfilePaths));
142-
143-
Assert.Equal(expectedString, result[0], ignoreCase: true);
116+
// Ensure that the $PROFILE variable is a string with the value of CurrentUserCurrentHost.
117+
IReadOnlyList<string> profileVariable = await psesHost.ExecutePSCommandAsync<string>(
118+
new PSCommand().AddScript("$PROFILE"),
119+
CancellationToken.None).ConfigureAwait(true);
120+
Assert.Collection(profileVariable,
121+
(p) => Assert.Equal(PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost, p));
122+
123+
// Ensure that all the profile paths are set in the correct note properties.
124+
IReadOnlyList<string> profileProperties = await psesHost.ExecutePSCommandAsync<string>(
125+
new PSCommand().AddScript("$PROFILE | Get-Member -Type NoteProperty"),
126+
CancellationToken.None).ConfigureAwait(true);
127+
128+
Assert.Collection(profileProperties,
129+
(p) => Assert.Equal($"string AllUsersAllHosts={PsesHostFactory.TestProfilePaths.AllUsersAllHosts}", p, ignoreCase: true),
130+
(p) => Assert.Equal($"string AllUsersCurrentHost={PsesHostFactory.TestProfilePaths.AllUsersCurrentHost}", p, ignoreCase: true),
131+
(p) => Assert.Equal($"string CurrentUserAllHosts={PsesHostFactory.TestProfilePaths.CurrentUserAllHosts}", p, ignoreCase: true),
132+
(p) => Assert.Equal($"string CurrentUserCurrentHost={PsesHostFactory.TestProfilePaths.CurrentUserCurrentHost}", p, ignoreCase: true));
133+
134+
// Ensure that the profile was loaded.
135+
IReadOnlyList<bool> profileLoaded = await psesHost.ExecutePSCommandAsync<bool>(
136+
new PSCommand().AddScript("Assert-ProfileLoaded"),
137+
CancellationToken.None).ConfigureAwait(true);
138+
139+
Assert.Collection(profileLoaded, (p) => Assert.True(p));
144140
}
145141

146142
[Fact]

0 commit comments

Comments
 (0)