Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/Stop-Computer.Tests.ps1
T
xtqqczze 743983390e Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace

```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```

* Capitalise and apply hyphen to 'Not' parameter

```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```

* Capitalise and apply hyphen to 'Be' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```

* Capitalise and apply hyphen to 'BeExactly' parameter

$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'

* Capitalise and apply hyphen to 'BeGreaterThan' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```

* Use 'BeTrue' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```

* Use 'BeFalse' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```

* Capitalise and apply hyphen to 'Match' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```

* Capitalise and apply hyphen to 'Throw' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```

* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```

* Capitalise 'Because' parameter

```powershell
$_ -ireplace '\s-because\b',' -Because'
```

* Fix 'BeNullOrEmpty'
2020-01-11 20:41:59 +05:00

62 lines
2.3 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# 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
}