Skip to content

Commit 5cd6b86

Browse files
vercellonevexx32
authored andcommitted
🔧 Fixes #191 AboutPSObjects (#228)
* fixes #191 AboutPSObjects * reorder static arrays alphabetically * changes requested by @vexx32 * single line feed before EOF * fix-count-ienumerable * varying property types comment * Moved varying PropertyTypes comment
1 parent 2b01ba4 commit 5cd6b86

1 file changed

Lines changed: 37 additions & 24 deletions

File tree

PSKoans/Koans/Constructs and Patterns/AboutPSObjects.Koans.ps1

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,53 @@ Describe 'PSObject' {
2727
The .PSObject member contains many properties, but the .PSObject property itself does not
2828
actually register for tab-completion, though its child properties do.
2929
#>
30-
$PSObjectProperties = ($Object.PSObject | Get-Member -MemberType Properties).Name
30+
$PSObjectProperties = ($Object.PSObject | Get-Member -MemberType Properties).Name | Sort-Object
3131

3232
@(
3333
'BaseObject'
34-
'__'
34+
'____'
3535
'Members'
3636
'Methods'
37-
'__'
38-
'__'
37+
'____'
38+
'____'
3939
) | Should -Be $PSObjectProperties
4040
}
4141

4242
It "details the base object's properties and methods" {
4343
$PropertyNames = @(
44-
__
44+
'Count'
45+
'IsFixedSize'
46+
'____'
47+
'____'
48+
'____'
4549
'LongLength'
46-
__
50+
'____'
4751
'SyncRoot'
48-
__
49-
'IsFixedSize'
50-
__
51-
'Count'
5252
)
53-
$PropertyNames | Should -Be $Object.PSObject.Properties.Name
53+
$PropertyNames | Should -Be $Object.PSObject.Properties.Name | Sort-Object
5454

5555
$Methods = $Object.PSObject.Methods
56-
__ | Should -Be $Methods.Count
57-
$Methods['__'].Name | Should -Be 'Length'
56+
__ | Should -Be $Methods.ForEach{$_}.Count
57+
$Methods['____'].Name | Should -Be 'get_Length'
5858
}
5959

6060
It "can be found on any object in PowerShell" {
6161
# Even an empty collection holds some meaning
6262
$Empty = @()
6363

6464
# Native .NET objects have their standard properties mapped to PSObject properties for easy access
65-
$Empty.PSObject.Properties.Name | Should -Not -BeNullOrEmpty
66-
@('__', '__', '__', '__', 'IsReadOnly', '__', '__', 'IsSynchronised', '__') | Should -Be $Empty.PSObject.Properties.Name
65+
$PropertyNames = $Empty.PSObject.Properties.Name | Sort-Object
66+
$PropertyNames | Should -Not -BeNullOrEmpty
67+
@(
68+
'____',
69+
'____',
70+
'IsReadOnly',
71+
'IsSynchronized',
72+
'____',
73+
'____',
74+
'____',
75+
'____'
76+
) | Should -Be $PropertyNames
6777
__ | Should -Be $Empty.IsReadOnly
6878
}
6979

@@ -79,10 +89,10 @@ Describe 'PSObject' {
7989
Thorns = $true
8090
}
8191

82-
@('__', '__', '__') | Should -Be $Object.PSObject.Properties.Name
92+
@('____', '____', '____') | Should -Be $Object.PSObject.Properties.Name
8393
# Collections come in many shapes and sizes - what type is this one?
84-
'__' | Should -Be $Object.PSObject.Properties.GetType().Name
85-
'__' | Should -Be $Object.PSObject.Properties['Flower'].MemberType
94+
'____' | Should -Be $Object.PSObject.Properties.GetType().Name
95+
'____' | Should -Be $Object.PSObject.Properties['Flower'].MemberType
8696
}
8797

8898
It "details where the properties originate from" {
@@ -91,13 +101,15 @@ Describe 'PSObject' {
91101
Add-Member -InputObject $Object -MemberType NoteProperty -Name 'TestProperty' -Value __
92102

93103
$Object.TestProperty | Should -Be 12
94-
'__' | Should -Be $Object.PSObject.Properties['TestProperty'].MemberType
104+
'____' | Should -Be $Object.PSObject.Properties['TestProperty'].MemberType
95105

96106
$PropertyTypes = $Object.PSObject.Properties |
97107
Group-Object -Property MemberType |
98-
Select-Object -ExpandProperty Name
108+
Select-Object -ExpandProperty Name |
109+
Sort-Object
99110

100-
@( '__', '__' ) | Should -Be $PropertyTypes
111+
# There may be varying property types depending on your PowerShell version
112+
@( '____', '____', '____' ) | Should -Be $PropertyTypes
101113
}
102114

103115
It "can find derivative properties" {
@@ -108,12 +120,13 @@ Describe 'PSObject' {
108120
}
109121
Add-Member -InputObject $Name -MemberType NoteProperty -Name 'Surname' -Value 'Sylph'
110122

111-
'__' | Should -Be $Name.Letters[3]
123+
'____' | Should -Be $Name.Letters[3]
112124

113125
$PropertyTypes = $Name.PSObject.Properties |
114126
Group-Object -Property MemberType |
115-
ForEach-Object -MemberName Name
127+
ForEach-Object -MemberName Name |
128+
Sort-Object
116129

117-
@( '__', '__', '__') | Should -Be $PropertyTypes
130+
@( '____', '____', '____', '____') | Should -Be $PropertyTypes
118131
}
119132
}

0 commit comments

Comments
 (0)