2016-03-04 23:48:30 +01:00
|
|
|
Describe "Group-Object" {
|
2015-10-06 22:37:45 +02:00
|
|
|
$testObject = Get-ChildItem
|
|
|
|
|
|
|
|
It "Should be called using an object as piped without error with no switches" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{$testObject | Group-Object } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be called using the InputObject without error with no other switches" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Group-Object -InputObject $testObject } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should return three columns- count, name, and group" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = Group-Object -InputObject $testObject
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.Count | Should BeGreaterThan 0
|
|
|
|
$actual.Name.Count | Should BeGreaterThan 0
|
|
|
|
$actual.Group.Count | Should BeGreaterThan 0
|
2015-10-06 22:37:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Should use the group alias" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ group -InputObject $testObject } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should create a collection when the inputObject parameter is used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualParam = Group-Object -InputObject $testObject
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualParam.Group.GetType().Name | Should Be "Collection``1"
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should output an array when piped input is used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = $testObject | Group-Object
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.Group.GetType().BaseType | Should Be Array
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output between the group alias and the group-object cmdlet" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualAlias = group -InputObject $testObject
|
|
|
|
$actualCmdlet = Group-Object -InputObject $testObject
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualAlias.Name[0] | Should Be $actualCmdlet.Name[0]
|
|
|
|
$actualAlias.Group[0] | Should Be $actualCmdlet.Group[0]
|
2015-10-06 22:37:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to use the property switch without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | Group-Object -Property Attributes } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = $testObject | Group-Object -Property Attributes
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.Group.Count | Should BeGreaterThan 0
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to use the property switch on multiple properties without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | Group-Object -Property Attributes, Length }
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = $testObject | Group-Object -Property Attributes, Length
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.Group.Count | Should BeGreaterThan 0
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to omit members of a group using the NoElement switch without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | Group-Object -NoElement } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
($testObject | Group-Object -NoElement).Group | Should BeNullOrEmpty
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to output a hashtable datatype" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = $testObject | Group-Object -AsHashTable
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.GetType().Name | Should be "Hashtable"
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to access when output as hash table" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = $testObject | Group-Object -AsHashTable
|
2015-10-06 22:37:45 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual.Keys | Should Not BeNullOrEmpty
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should throw when attempting to use AsString without AsHashTable" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | Group-Object -AsString } | Should Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should not throw error when using AsString when the AsHashTable was added" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | Group-Object -AsHashTable -AsString } | Should Not Throw
|
2015-10-06 22:37:45 +02:00
|
|
|
}
|
|
|
|
}
|