2017-03-29 19:11:02 +02:00
|
|
|
|
Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {
|
2016-09-13 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$command = [System.Management.Automation.PSCommand]::new()
|
|
|
|
|
$localRunspace = $host.Runspace
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Null argument exception should be thrown for null PSCommand argument" {
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
[System.Management.Automation.HostUtilities]::InvokeOnRunspace($null, $localRunspace)
|
|
|
|
|
throw "InvokeOnRunspace method did not throw expected PSArgumentNullException exception"
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
$_.FullyQualifiedErrorId | Should Be "PSArgumentNullException"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Null argument exception should be thrown for null Runspace argument" {
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
[System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $null)
|
|
|
|
|
throw "InvokeOnRunspace method did not throw expected PSArgumentNullException exception"
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
$_.FullyQualifiedErrorId | Should Be "PSArgumentNullException"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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!"')
|
|
|
|
|
$currentRunspace = $host.Runspace
|
|
|
|
|
|
|
|
|
|
$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $currentRunspace)
|
|
|
|
|
|
|
|
|
|
$results[0] | Should Be "Hello!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Describe "InvokeOnRunspace method on remote runspace" -tags "Feature" {
|
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
|
|
|
|
|
|
|
|
|
$results[0] | Should Be "Hello!"
|
|
|
|
|
}
|
|
|
|
|
}
|