add tests for get-command -ShowCommandInfo (#4906)

This commit is contained in:
Chunqing Chen 2017-10-02 10:54:06 -07:00 committed by Aditya Patwardhan
parent d8a075e484
commit 69bce66cf8

View file

@ -14,6 +14,7 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
/bin/chmod 777 "$file1"
/bin/chmod 777 "$file2"
}
$commandInfo = Get-Command Get-Date -ShowCommandInfo
}
It "Test wildcard with drive relative directory path" {
@ -49,4 +50,52 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
Pop-Location
}
It "Get-Command -ShowCommandInfo property field test" {
$properties = ($commandInfo | Get-Member -MemberType NoteProperty)
$propertiesAsString = $properties.name | out-string
$propertiesAsString | Should MatchExactly 'CommandType'
$propertiesAsString | Should MatchExactly 'Definition'
$propertiesAsString | Should MatchExactly 'Module'
$propertiesAsString | Should MatchExactly 'ModuleName'
$propertiesAsString | Should MatchExactly 'Name'
$propertiesAsString | Should MatchExactly 'ParameterSets'
}
$testcases = @(
@{observed = $commandInfo.Name; testname = "Name"; result = "Get-Date"}
@{observed = $commandInfo.ModuleName; testname = "Name"; result = "Microsoft.PowerShell.Utility"}
@{observed = $commandInfo.Module.Name; testname = "ModuleName"; result = "Microsoft.PowerShell.Utility"}
@{observed = $commandInfo.CommandType; testname = "CommandType"; result = "Cmdlet"}
@{observed = $commandInfo.Definition.Count; testname = "Definition"; result = 1}
)
It "Get-Command -ShowCommandInfo property test - <testname>" -TestCases $testcases{
param (
$observed,
$result
)
$observed | Should BeExactly $result
}
It "Get-Command -ShowCommandInfo ParameterSets property field test" {
$properties = ($commandInfo.ParameterSets[0] | Get-Member -MemberType NoteProperty)
$propertiesAsString = $properties.name | out-string
$propertiesAsString | Should MatchExactly 'IsDefault'
$propertiesAsString | Should MatchExactly 'Name'
$propertiesAsString | Should MatchExactly 'Parameters'
}
It "Get-Command -ShowCommandInfo Parameters property field test" {
$properties = ($commandInfo.ParameterSets[0].Parameters | Get-Member -MemberType NoteProperty)
$propertiesAsString = $properties.name | out-string
$propertiesAsString | Should MatchExactly 'HasParameterSet'
$propertiesAsString | Should MatchExactly 'IsMandatory'
$propertiesAsString | Should MatchExactly 'Name'
$propertiesAsString | Should MatchExactly 'ParameterType'
$propertiesAsString | Should MatchExactly 'Position'
$propertiesAsString | Should MatchExactly 'ValidParamSetValues'
$propertiesAsString | Should MatchExactly 'ValueFromPipeline'
}
}