File size: 1,605 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "SSH Remoting Cmdlet Tests" -Tags "Feature" {

    It "Enter-PSSession HostName parameter set should throw error for invalid key path" {
        { Enter-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
            Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.EnterPSSessionCommand"
    }

    It "New-PSSession HostName parameter set should throw error for invalid key path" {
        { New-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
            Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.NewPSSessionCommand"
    }

    It "Invoke-Command HostName parameter set should throw error for invalid key path" {
        { Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock { 1 } } |
            Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand"
    }

    It "Invoke-Command should support positional parameter ScriptBlock when using parameter set '<ParameterSetName>'" -TestCases @{ParameterSetName = 'SSHHost' }, @{ParameterSetName = 'SSHHostHashParam' } {
        param ([string]$ParameterSetName)
        $commandInfo = Get-Command -Name Invoke-Command
        $sshParameterSet = $commandInfo.ParameterSets | Where-Object { $_.Name -eq $ParameterSetName }
        $scriptBlockPosition = $sshParameterSet.Parameters | Where-Object { $_.Name -eq 'ScriptBlock' } | Select-Object -ExpandProperty Position
        $scriptBlockPosition | Should -Be 1
    }
}