Use -HaveCount instead of -Be in Where-Object.Tests.ps1. (#7379)

This commit is contained in:
Sergey Vasin
2018-07-31 08:51:42 +05:00
committed by Ilya
parent fcc519bb08
commit 58ac08c60a
@@ -27,118 +27,118 @@ Describe "Where-Object" -Tags "CI" {
It "Where-Object -Not Prop" {
$Result = $Computers | Where-Object -Not 'IPAddress'
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object -FilterScript {$true -ne $_.Prop}' {
$Result = $Computers | Where-Object -FilterScript {$true -ne $_.IPAddress}
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It "Where-Object Prop" {
$Result = $Computers | Where-Object 'IPAddress'
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object -FilterScript {$true -eq $_.Prop}' {
$Result = $Computers | Where-Object -FilterScript {$true -eq $_.IPAddress}
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object -FilterScript {$_.Prop -contains Value}' {
$Result = $Computers | Where-Object -FilterScript {$_.Drives -contains 'D'}
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object Prop -contains Value' {
$Result = $Computers | Where-Object Drives -contains 'D'
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object -FilterScript {$_.Prop -in $Array}' {
$Array = 'SPC-1234','BGP-5678'
$Result = $Computers | Where-Object -FilterScript {$_.ComputerName -in $Array}
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object $Array -in Prop' {
$Array = 'SPC-1234','BGP-5678'
$Result = $Computers | Where-Object ComputerName -in $Array
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object -FilterScript {$_.Prop -ge 2}' {
$Result = $Computers | Where-Object -FilterScript {$_.NumberOfCores -ge 2}
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object Prop -ge 2' {
$Result = $Computers | Where-Object NumberOfCores -ge 2
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object -FilterScript {$_.Prop -gt 2}' {
$Result = $Computers | Where-Object -FilterScript {$_.NumberOfCores -gt 2}
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object Prop -gt 2' {
$Result = $Computers | Where-Object NumberOfCores -gt 2
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object -FilterScript {$_.Prop -le 2}' {
$Result = $Computers | Where-Object -FilterScript {$_.NumberOfCores -le 2}
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object Prop -le 2' {
$Result = $Computers | Where-Object NumberOfCores -le 2
$Result.Count | Should -Be 2
$Result | Should -HaveCount 2
}
It 'Where-Object -FilterScript {$_.Prop -lt 2}' {
$Result = $Computers | Where-Object -FilterScript {$_.NumberOfCores -lt 2}
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object Prop -lt 2' {
$Result = $Computers | Where-Object NumberOfCores -lt 2
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object -FilterScript {$_.Prop -Like Value}' {
$Result = $Computers | Where-Object -FilterScript {$_.ComputerName -like 'MGC-9101'}
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object Prop -like Value' {
$Result = $Computers | Where-Object ComputerName -like 'MGC-9101'
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object -FilterScript {$_.Prop -Match Pattern}' {
$Result = $Computers | Where-Object -FilterScript {$_.ComputerName -match '^MGC.+'}
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object Prop -like Value' {
$Result = $Computers | Where-Object ComputerName -match '^MGC.+'
$Result.Count | Should -Be 1
$Result | Should -HaveCount 1
}
It 'Where-Object should handle dynamic (DLR) objects' {
$dynObj = [TestDynamic]::new()
$Result = $dynObj, $dynObj | Where FooProp -eq 123
$Result.Count | Should -Be 2
$Result = $dynObj, $dynObj | Where-Object FooProp -eq 123
$Result | Should -HaveCount 2
$Result[0] | Should -Be $dynObj
$Result[1] | Should -Be $dynObj
}
It 'Where-Object should handle dynamic (DLR) objects, even without property name hint' {
$dynObj = [TestDynamic]::new()
$Result = $dynObj, $dynObj | Where HiddenProp -eq 789
$Result.Count | Should -Be 2
$Result = $dynObj, $dynObj | Where-Object HiddenProp -eq 789
$Result | Should -HaveCount 2
$Result[0] | Should -Be $dynObj
$Result[1] | Should -Be $dynObj
}