2020-03-24 11:08:37 -07:00
# Copyright (c) Microsoft Corporation.
2018-02-13 09:23:53 -08:00
# Licensed under the MIT License.
2016-09-14 15:13:10 -07:00
Describe "SSH Remoting Cmdlet Tests" -Tags "Feature" {
It "Enter-PSSession HostName parameter set should throw error for invalid key path" {
2018-03-23 10:36:11 -07:00
{ Enter-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.EnterPSSessionCommand"
2016-09-14 15:13:10 -07:00
}
It "New-PSSession HostName parameter set should throw error for invalid key path" {
2018-03-23 10:36:11 -07:00
{ New-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.NewPSSessionCommand"
2016-09-14 15:13:10 -07:00
}
It "Invoke-Command HostName parameter set should throw error for invalid key path" {
2019-10-10 20:29:31 +02:00
{ Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock { 1 } } |
2018-03-23 10:36:11 -07:00
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand"
2016-09-14 15:13:10 -07:00
}
2019-10-10 20:29:31 +02:00
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
}
2016-09-14 15:13:10 -07:00
}