Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1
T
2016-10-27 16:37:50 -07:00

44 lines
1.5 KiB
PowerShell

Describe "Get-Service cmdlet tests" -Tags "CI" {
# Service cmdlet is currently working on windows only
# So skip the tests on non-Windows
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if ( -not $IsWindows ) {
$PSDefaultParameterValues["it:skip"] = $true
}
}
# Restore the defaults
AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
$testCases =
@{ data = $null; value = 'null' },
@{ data = [String]::Empty; value = 'empty string' }
Context 'Check null or empty value to the -Name parameter' {
It 'Should throw if <value> is passed to -Name parameter' -TestCases $testCases {
param($data)
try {
$null = Get-Service -Name $data -ErrorAction Stop
throw 'Expected error on previous command'
}
catch {
$_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand'
}
}
}
Context 'Check null or empty value to the -Name parameter via pipeline' {
It 'Should throw if <value> is passed through pipeline to -Name parameter' -TestCases $testCases {
param($data)
try {
$null = Get-Service -Name $data -ErrorAction Stop
throw 'Expected error on previous command'
}
catch {
$_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand'
}
}
}
}