# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. 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 is passed to -Name parameter' -TestCases $testCases { param($data) { $null = Get-Service -Name $data -ErrorAction Stop } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' } } Context 'Check null or empty value to the -Name parameter via pipeline' { It 'Should throw if is passed through pipeline to -Name parameter' -TestCases $testCases { param($data) { $null = Get-Service -Name $data -ErrorAction Stop } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' } } It "GetServiceCommand can be used as API for '' with ''" -TestCases @( @{ parameter = "DisplayName" ; value = "foo" }, @{ parameter = "Include" ; value = "foo","bar" }, @{ parameter = "Exclude" ; value = "bar","foo" }, @{ parameter = "InputObject" ; script = { Get-Service | Select-Object -First 1 } }, @{ parameter = "Name" ; value = "foo","bar" } ) { param($parameter, $value, $script) if ($script -ne $null) { $value = & $script } $getservicecmd = [Microsoft.PowerShell.Commands.GetServiceCommand]::new() $getservicecmd.$parameter = $value $getservicecmd.$parameter | Should -BeExactly $value } It "Get-Service filtering works for '