1. General summary of the issue
Easiest shown by demonstration:
$a = @{ One = 1; Two = 2 }
$b = $a.Keys
$b | Should -Be $a.Keys
Note that $a.Keys is of type [System.Collections.Hashtable+KeyCollection]
When done with an [ordered] hashtable, the keys property is of type [System.Collections.Specialized.OrderedDictionary+OrderedDictionaryKeyValueCollection] but the same issue is reflected.
$a = [ordered]@{ One = 1; Two = 2 }
$b = $a.Keys
$b | Should -Be $a.Keys
@( 'One', 'Two' ) | Should -Be $a.Keys
2. Describe Your Environment
Pester version : 4.4.0 \\hct-byn-fs01\FolderRedirections\Joel\My Documents\WindowsPowerShell\Modules\Pester\4.4.0\Pester.psd1
PowerShell version : 5.1.17134.407
OS version : Microsoft Windows NT 10.0.17134.0
3. Expected Behavior
In general use, these collections behave essentially as arrays with string contents. I'm sure the difference is an implementation detail in .NET / .NET Core.
I would generally expect flat collections like this to be enumerated in a similar manner to true arrays to retrieve their contents, at least in the absence of the -BeExactly switch. (Such a switch should probably attempt to verify the type of the original collection where possible, but that may not be easily accessible due to the pipeline enumeration of collections.)
4.Current Behavior
Assertion fails, displaying the following error:
Expected @('One', 'Two'), but got @('One', 'Two').
At \\hct-byn-fs01\FolderRedirections\Joel\My
Documents\WindowsPowerShell\Modules\Pester\4.4.0\Functions\Assertions\Should.ps1:206 char:9
+ throw ( New-ShouldErrorRecord -Message $testResult.FailureMes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collections.Hashtable:Hashtable) [], Exception
+ FullyQualifiedErrorId : PesterAssertionFailed
Looks very similar to #1154, but stems from a different (but possibly related) cause, I think.
5. Possible Solution
In the absence of -BeExactly or some such similar specific switch, it should enumerate the collection and compare the contents, I would expect, based on its behaviour of similar flat collections.
6. Context
vexx32/PSKoans#124
1. General summary of the issue
Easiest shown by demonstration:
Note that
$a.Keysis of type[System.Collections.Hashtable+KeyCollection]When done with an
[ordered]hashtable, the keys property is of type[System.Collections.Specialized.OrderedDictionary+OrderedDictionaryKeyValueCollection]but the same issue is reflected.2. Describe Your Environment
3. Expected Behavior
In general use, these collections behave essentially as arrays with string contents. I'm sure the difference is an implementation detail in .NET / .NET Core.
I would generally expect flat collections like this to be enumerated in a similar manner to true arrays to retrieve their contents, at least in the absence of the
-BeExactlyswitch. (Such a switch should probably attempt to verify the type of the original collection where possible, but that may not be easily accessible due to the pipeline enumeration of collections.)4.Current Behavior
Assertion fails, displaying the following error:
Looks very similar to #1154, but stems from a different (but possibly related) cause, I think.
5. Possible Solution
In the absence of
-BeExactlyor some such similar specific switch, it should enumerate the collection and compare the contents, I would expect, based on its behaviour of similar flat collections.6. Context
vexx32/PSKoans#124