2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {
|
2016-09-13 20:31:48 +02:00
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
$command = [System.Management.Automation.PSCommand]::new()
|
2020-01-13 20:34:10 +01:00
|
|
|
$localRunspace = $Host.Runspace
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Null argument exception should be thrown for null PSCommand argument" {
|
2018-05-17 23:42:04 +02:00
|
|
|
{ [System.Management.Automation.HostUtilities]::InvokeOnRunspace($null, $localRunspace) } |
|
|
|
|
Should -Throw -ErrorId "PSArgumentNullException"
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Null argument exception should be thrown for null Runspace argument" {
|
2018-05-17 23:42:04 +02:00
|
|
|
{ [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $null) } |
|
|
|
|
Should -Throw -ErrorId "PSArgumentNullException"
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Describe "InvokeOnRunspace method as nested command" -tags "Feature" {
|
|
|
|
|
|
|
|
It "Method should successfully invoke command as nested on busy runspace" {
|
|
|
|
|
|
|
|
$command = [System.Management.Automation.PSCommand]::new()
|
|
|
|
$command.AddScript('"Hello!"')
|
2020-01-13 20:34:10 +01:00
|
|
|
$currentRunspace = $Host.Runspace
|
2016-09-13 20:31:48 +02:00
|
|
|
|
|
|
|
$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $currentRunspace)
|
|
|
|
|
2018-03-23 18:48:26 +01:00
|
|
|
$results[0] | Should -Be "Hello!"
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-10 00:11:02 +01:00
|
|
|
Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAdminOnWindows" {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-09-13 20:31:48 +02:00
|
|
|
BeforeAll {
|
2016-10-11 00:24:04 +02:00
|
|
|
|
|
|
|
if ($IsWindows) {
|
2016-10-27 20:53:35 +02:00
|
|
|
$script:remoteRunspace = New-RemoteRunspace
|
2016-10-11 00:24:04 +02:00
|
|
|
}
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AfterAll {
|
2016-10-11 00:24:04 +02:00
|
|
|
if ($script:remoteRunspace)
|
|
|
|
{
|
|
|
|
$script:remoteRunspace.Dispose();
|
|
|
|
}
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 00:24:04 +02:00
|
|
|
It "Method should successfully invoke command on remote runspace" -Skip:(!$IsWindows) {
|
2016-09-13 20:31:48 +02:00
|
|
|
|
|
|
|
$command = [System.Management.Automation.PSCommand]::new()
|
|
|
|
$command.AddScript('"Hello!"')
|
|
|
|
|
2016-10-11 00:24:04 +02:00
|
|
|
$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $script:remoteRunspace)
|
2016-09-13 20:31:48 +02:00
|
|
|
|
2018-03-23 18:48:26 +01:00
|
|
|
$results[0] | Should -Be "Hello!"
|
2016-09-13 20:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-08 19:52:02 +01:00
|
|
|
|
2021-04-12 18:32:54 +02:00
|
|
|
Describe 'PromptForCredential' -Tags "CI" {
|
2021-03-08 19:52:02 +01:00
|
|
|
BeforeAll {
|
|
|
|
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('NoPromptForPassword', $true)
|
|
|
|
}
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('NoPromptForPassword', $false)
|
|
|
|
}
|
|
|
|
|
|
|
|
It 'Should accept no targetname' {
|
|
|
|
$out = $Host.UI.PromptForCredential('caption','message','myUser',$null)
|
|
|
|
$out.UserName | Should -BeExactly 'myUser'
|
|
|
|
}
|
|
|
|
|
|
|
|
It 'Should accept targetname as domain' {
|
|
|
|
$out = $Host.UI.PromptForCredential('caption','message','myUser','myDomain')
|
|
|
|
$out.UserName | Should -BeExactly 'myDomain\myUser'
|
|
|
|
}
|
|
|
|
}
|