forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStop-Computer.Tests.ps1
More file actions
58 lines (50 loc) · 2.19 KB
/
Copy pathStop-Computer.Tests.ps1
File metadata and controls
58 lines (50 loc) · 2.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
# note these will manipulate private data in the PowerShell engine which will
# enable us to not actually stop the system, but return right before we do
$stopTesthook = "TestStopComputer"
$stopTesthookResultName = "TestStopComputerResults"
$DefaultResultValue = 0
try
{
# set up for testing
$PSDefaultParameterValues["it:skip"] = ! $IsWindows
Enable-Testhook -testhookName $stopTesthook
Describe "Stop-Computer" -Tag Feature {
# if we throw in BeforeEach, the test will fail and the stop will not be called
BeforeEach {
if ( ! (Test-TesthookIsSet -testhookName $stopTesthook) ) {
throw "Testhook '${stopTesthook}' is not set"
}
}
AfterEach {
Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue
}
It "Should stop the local computer" {
Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue
Stop-Computer -ErrorAction Stop| Should BeNullOrEmpty
}
It "Should support -Computer parameter" {
Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue
$computerNames = "localhost","${env:COMPUTERNAME}"
Stop-Computer -Computer $computerNames -ErrorAction Stop| Should BeNullOrEmpty
}
It "Should support WsmanAuthentication types" {
$authChoices = "Default","Basic","Negotiate","CredSSP","Digest","Kerberos"
foreach ( $auth in $authChoices ) {
Stop-Computer -WsmanAuthentication $auth | Should BeNullOrEmpty
}
}
Context "Stop-Computer Error Conditions" {
It "Should return the proper error when it occurs" {
Set-TesthookResult -testhookName $stopTesthookResultName -Value 0x300000
Stop-Computer -ErrorVariable StopError 2>$null
$StopError.Exception.Message | Should match 0x300000
}
}
}
}
finally
{
$PSDefaultParameterValues.Remove("it:skip")
Disable-Testhook -testhookName $stopTesthook
Set-TesthookResult -testhookName $stopTesthookResultName -Value $DefaultResultValue
}