2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-09-09 12:48:55 -07:00
|
|
|
Describe "Get-Runspace cmdlet tests" -Tag "CI" {
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$CurrentRunspace = $ExecutionContext.Host.Runspace
|
|
|
|
|
$ExpectedInstanceId = $CurrentRunspace.InstanceId
|
|
|
|
|
$ExpectedId = $currentRunspace.Id
|
|
|
|
|
}
|
|
|
|
|
It "Get-Runspace should return the current runspace" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$runspace = Get-Runspace |Sort-Object -Property id | Select-Object -First 1
|
2018-03-23 10:26:23 -07:00
|
|
|
$runspace.InstanceId | Should -Be $ExpectedInstanceId
|
2016-09-09 12:48:55 -07:00
|
|
|
}
|
|
|
|
|
It "Get-Runspace with runspace InstanceId should return the correct runspace" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$runspace = Get-Runspace -InstanceId $CurrentRunspace.InstanceId
|
2018-03-23 10:26:23 -07:00
|
|
|
$runspace.InstanceId | Should -Be $ExpectedInstanceId
|
2016-09-09 12:48:55 -07:00
|
|
|
}
|
2016-09-13 12:21:01 -07:00
|
|
|
It "Get-Runspace with runspace name should return the correct runspace" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$runspace = Get-Runspace -Name $currentRunspace.Name
|
2018-03-23 10:26:23 -07:00
|
|
|
$runspace.InstanceId | Should -Be $ExpectedInstanceId
|
2016-09-13 12:21:01 -07:00
|
|
|
}
|
2016-09-09 12:48:55 -07:00
|
|
|
It "Get-Runspace with runspace Id should return the correct runspace" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$runspace = Get-Runspace -Id $CurrentRunspace.Id
|
2018-03-23 10:26:23 -07:00
|
|
|
$runspace.InstanceId | Should -Be $ExpectedInstanceId
|
2017-01-16 13:31:14 -08:00
|
|
|
}
|
2016-09-09 12:48:55 -07:00
|
|
|
Context "Multiple Runspaces" {
|
|
|
|
|
BeforeAll {
|
2020-05-07 13:00:30 +01:00
|
|
|
$runspaceCount = @(Get-Runspace).count
|
2016-09-09 12:48:55 -07:00
|
|
|
$r1 = [runspacefactory]::CreateRunspace()
|
|
|
|
|
$r1.Open()
|
|
|
|
|
$r2 = [runspacefactory]::CreateRunspace()
|
|
|
|
|
}
|
|
|
|
|
AfterAll {
|
|
|
|
|
$r1.Dispose()
|
|
|
|
|
$r2.Dispose()
|
|
|
|
|
}
|
2016-09-12 16:41:30 -07:00
|
|
|
It "Get-Runspace should return the new runspaces" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$result = Get-Runspace
|
2016-09-12 16:41:30 -07:00
|
|
|
# if the ids don't match, we'll get null passed to should
|
2018-03-23 10:26:23 -07:00
|
|
|
$result.id | Where-Object {$_ -eq $r1.id } | Should -Be $r1.id
|
|
|
|
|
$result.id | Where-Object {$_ -eq $r2.id } | Should -Be $r2.id
|
2016-09-09 12:48:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|