mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Since DCOM is not supported in corefx there was a great deal of dead code in the computer cmdlets. This PR removes all vestiges of DCOM support from: - Rename-Computer - Restart-Computer - Stop-Computer removing about 4500 lines of dead code. Also, tests are updated to provide more complete coverage. I also removed test-connection completely to make way for @iSazonov upcoming PR to improve coverage in tests, I created some test hook code which will test the cmdlet code without actually calling the WMI method to restart/rename/stop the system
59 lines
2.2 KiB
PowerShell
59 lines
2.2 KiB
PowerShell
# 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
|
|
}
|