forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Service.Tests.ps1
More file actions
43 lines (41 loc) · 1.46 KB
/
Copy pathGet-Service.Tests.ps1
File metadata and controls
43 lines (41 loc) · 1.46 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
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'
}
}
}
}