-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Expand file tree
/
Copy pathHostUtilities.Tests.ps1
More file actions
98 lines (76 loc) · 3.19 KB
/
Copy pathHostUtilities.Tests.ps1
File metadata and controls
98 lines (76 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {
BeforeAll {
$command = [System.Management.Automation.PSCommand]::new()
$localRunspace = $Host.Runspace
}
It "Null argument exception should be thrown for null PSCommand argument" {
{ [System.Management.Automation.HostUtilities]::InvokeOnRunspace($null, $localRunspace) } |
Should -Throw -ErrorId "PSArgumentNullException"
}
It "Null argument exception should be thrown for null Runspace argument" {
{ [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $null) } |
Should -Throw -ErrorId "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","RequireAdminOnWindows" {
BeforeAll {
$skipTest = (Test-IsWinWow64) -or !$IsWindows
if ($skipTest) {
return
}
$script:remoteRunspace = New-RemoteRunspace
}
AfterAll {
if ($script:remoteRunspace)
{
$script:remoteRunspace.Dispose();
}
}
It "Method should successfully invoke command on remote runspace" -Skip:$skipTest {
$command = [System.Management.Automation.PSCommand]::new()
$command.AddScript('"Hello!"')
$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $script:remoteRunspace)
$results[0] | Should -Be "Hello!"
}
}
Describe 'PromptForCredential' -Tags "CI" {
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'
}
}
Describe 'PushRunspaceLocalFailure' -Tags 'CI' {
It 'Should throw an exception when pushing a local runspace' {
$runspace = [RunspaceFactory]::CreateRunspace()
try {
$runspace.Open()
$exc = { $Host.PushRunspace($runspace) } | Should -Throw -PassThru
$exc.Exception.InnerException | Should -BeOfType ([System.ArgumentException])
[string]$exc | Should -BeLike "*PushRunspace can only push a remote runspace. (Parameter 'runspace')*"
}
finally {
$runspace.Dispose()
}
}
}