Changes per pull request 182 comments

This commit is contained in:
George Fleming
2015-10-15 10:11:17 -07:00
parent 64f34638c2
commit a352f21316
2 changed files with 57 additions and 35 deletions
+6 -6
View File
@@ -1,14 +1,14 @@
Function GetFileMock () {
$objs = @( [pscustomobject]@{ Size=4533816; Mode="-a---l"; LastWriteTime="9/1/2015 11:15 PM"; Name="explorer.exe" },
[pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" },
[pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" },
[pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" },
[pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" },
[pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" })
[pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" },
[pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" },
[pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" },
[pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" },
[pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" })
return $objs
}
filter addOne() {
filter addOneToSizeProperty() {
$_.Size += 1
$_
}
+51 -29
View File
@@ -2,91 +2,113 @@
Describe "Select-Object" {
BeforeEach {
$dirObject=GetFileMock
$dirObject = GetFileMock
$TestLength = 3
}
It "Handle piped input without error" {
{ $dirObject | Test-Path } | Should Not Throw
{ $dirObject | Select-Object } | Should Not Throw
}
It "-inputObject parameter should treats object as a single object" {
$(Select-Object -inputObject $dirObject -last $TestLength).Length | Should Be $dirObject.Length
It "Should treat input as a single object with the inputObject parameter" {
$result = $(Select-Object -inputObject $dirObject -last $TestLength).Length
$expected = $dirObject.Length
$result | Should Be $expected
}
It "Should be able to use the alias" {
{ $dirObject | select } | Should Not Throw
{ $dirObject | select } | Should Not BeNullOrEmpty
}
It "-First parameter should return correct object" {
It "Should have same result when using alias" {
$result = $dirObject | select
$expected = $dirObject | Select-Object
$result | Should Be $expected
}
It "Should return correct object with First parameter" {
$result = $dirObject | Select-Object -First $TestLength
$result.Length | Should Be $TestLength
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$i].Name
}
}
It "-Last parameter should return correct object" {
It "Should return correct object with Last parameter" {
$result = $dirObject | Select-Object -Last $TestLength
$result.Length | Should Be $TestLength
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name
}
}
It "-Unique parameter should work correctly" {
("a","b","c","a","a","a" | Select-Object -Unique).Length | Should Be 3
It "Should work correctly with Unique parameter" {
$result = ("a","b","c","a","a","a" | Select-Object -Unique).Length
$expected = 3
$result | Should Be $expected
}
It "-Skip parameter should return correct object" {
It "Should return correct object with Skip parameter" {
$result = $dirObject | Select-Object -Skip $TestLength
$result.Length | Should Be ($dirObject.Length - $TestLength)
$result.Length | Should Be ($dirObject.Length - $TestLength)
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$TestLength + $i].Name
}
}
It "-Property parameter should return an object with selected columns" {
It "Should return an object with selected columns" {
$result = $dirObject | Select-Object -Property Name, Size
$result.Length | Should Be $dirObject.Length
$result.Length | Should Be $dirObject.Length
$result[0].Name | Should Be $dirObject[0].Name
$result[0].Size | Should Be $dirObject[0].Size
$result[0].Mode | Should BeNullOrEmpty
}
It "Select-Object should send output to pipe properly" {
It "Should send output to pipe properly" {
{$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw
}
It "-Index parameter should select array indices" {
$firstIndex = 2
It "Should select array indices with Index parameter" {
$firstIndex = 2
$secondIndex = 4
$result = $dirObject | Select-Object -Index $firstIndex, $secondIndex
$result = $dirObject | Select-Object -Index $firstIndex, $secondIndex
$result[0].Name | Should Be $dirObject[$firstIndex].Name
$result[1].Name | Should Be $dirObject[$secondIndex].Name
}
# Note that these two tests will modify original values of $dirObject
It "-First option does not wait when used without -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOne | Select-Object -First $TestLength
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
It "Should not wait when used without -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be $orig2
}
It "-First option does wait when used with -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOne | Select-Object -First $TestLength -Wait
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
It "Should wait when used with -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength -Wait
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be ($orig2 + 1)
}
}