Skip to content

Commit 69bce66

Browse files
chunqingchenadityapatwardhan
authored andcommitted
add tests for get-command -ShowCommandInfo (PowerShell#4906)
1 parent d8a075e commit 69bce66

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/powershell/Modules/Microsoft.PowerShell.Core/Pester.Commands.Cmdlets.GetCommand.Tests.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
1414
/bin/chmod 777 "$file1"
1515
/bin/chmod 777 "$file2"
1616
}
17+
$commandInfo = Get-Command Get-Date -ShowCommandInfo
1718
}
1819

1920
It "Test wildcard with drive relative directory path" {
@@ -49,4 +50,52 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
4950
Pop-Location
5051
}
5152

53+
It "Get-Command -ShowCommandInfo property field test" {
54+
$properties = ($commandInfo | Get-Member -MemberType NoteProperty)
55+
$propertiesAsString = $properties.name | out-string
56+
$propertiesAsString | Should MatchExactly 'CommandType'
57+
$propertiesAsString | Should MatchExactly 'Definition'
58+
$propertiesAsString | Should MatchExactly 'Module'
59+
$propertiesAsString | Should MatchExactly 'ModuleName'
60+
$propertiesAsString | Should MatchExactly 'Name'
61+
$propertiesAsString | Should MatchExactly 'ParameterSets'
62+
}
63+
64+
$testcases = @(
65+
@{observed = $commandInfo.Name; testname = "Name"; result = "Get-Date"}
66+
@{observed = $commandInfo.ModuleName; testname = "Name"; result = "Microsoft.PowerShell.Utility"}
67+
@{observed = $commandInfo.Module.Name; testname = "ModuleName"; result = "Microsoft.PowerShell.Utility"}
68+
@{observed = $commandInfo.CommandType; testname = "CommandType"; result = "Cmdlet"}
69+
@{observed = $commandInfo.Definition.Count; testname = "Definition"; result = 1}
70+
)
71+
72+
It "Get-Command -ShowCommandInfo property test - <testname>" -TestCases $testcases{
73+
param (
74+
$observed,
75+
$result
76+
)
77+
$observed | Should BeExactly $result
78+
}
79+
80+
81+
It "Get-Command -ShowCommandInfo ParameterSets property field test" {
82+
$properties = ($commandInfo.ParameterSets[0] | Get-Member -MemberType NoteProperty)
83+
$propertiesAsString = $properties.name | out-string
84+
$propertiesAsString | Should MatchExactly 'IsDefault'
85+
$propertiesAsString | Should MatchExactly 'Name'
86+
$propertiesAsString | Should MatchExactly 'Parameters'
87+
}
88+
89+
It "Get-Command -ShowCommandInfo Parameters property field test" {
90+
$properties = ($commandInfo.ParameterSets[0].Parameters | Get-Member -MemberType NoteProperty)
91+
$propertiesAsString = $properties.name | out-string
92+
$propertiesAsString | Should MatchExactly 'HasParameterSet'
93+
$propertiesAsString | Should MatchExactly 'IsMandatory'
94+
$propertiesAsString | Should MatchExactly 'Name'
95+
$propertiesAsString | Should MatchExactly 'ParameterType'
96+
$propertiesAsString | Should MatchExactly 'Position'
97+
$propertiesAsString | Should MatchExactly 'ValidParamSetValues'
98+
$propertiesAsString | Should MatchExactly 'ValueFromPipeline'
99+
}
100+
52101
}

0 commit comments

Comments
 (0)