diff --git a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs index d534f13a9..18d2e5467 100644 --- a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs +++ b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs @@ -6,9 +6,11 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.PowerShell.EditorServices.Hosting; using Microsoft.PowerShell.EditorServices.Services.PowerShell.Console; using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution; using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host; +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility; using Xunit; namespace Microsoft.PowerShell.EditorServices.Test.Console @@ -141,6 +143,23 @@ public async Task CanResolveAndLoadProfilesForHostId() Assert.Equal(expectedString, result[0], ignoreCase: true); } + [Fact] + public async Task CanHandleNoProfiles() + { + // Call LoadProfiles with profile paths that won't exist, and assert that it does not + // throw PSInvalidOperationException (which it previously did when it tried to invoke an + // empty command). + ProfilePathInfo emptyProfilePaths = new("", "", "", ""); + await psesHost.ExecuteDelegateAsync( + "LoadProfiles", + executionOptions: null, + (pwsh, _) => { + pwsh.LoadProfiles(emptyProfilePaths); + Assert.Empty(pwsh.Commands.Commands); + }, + CancellationToken.None).ConfigureAwait(true); + } + [Fact] public async Task CanLoadPSReadLine() {