forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup-Object.Tests.ps1
More file actions
107 lines (79 loc) · 3.54 KB
/
Copy pathGroup-Object.Tests.ps1
File metadata and controls
107 lines (79 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Describe "Group-Object DRT Unit Tests" -Tags "CI" {
It "Test for CaseSensitive switch" {
$testObject = 'aA', 'aA', 'AA', 'AA'
$results = $testObject | Group-Object -CaseSensitive
$results.Count | Should Be 2
$results.Name.Count | Should Be 2
$results.Group.Count | Should Be 4
$results.Name | Should Be aA,AA
$results.Group | Should Be aA,aA,AA,AA
,$results | Should BeOfType "System.Array"
}
}
Describe "Group-Object" -Tags "CI" {
BeforeAll {
$testObject = Get-ChildItem
}
It "Should be called using an object as piped without error with no switches" {
{$testObject | Group-Object } | Should Not Throw
}
It "Should be called using the InputObject without error with no other switches" {
{ Group-Object -InputObject $testObject } | Should Not Throw
}
It "Should return three columns- count, name, and group" {
$actual = Group-Object -InputObject $testObject
$actual.Count | Should BeGreaterThan 0
$actual.Name.Count | Should BeGreaterThan 0
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should use the group alias" {
{ Group-Object -InputObject $testObject } | Should Not Throw
}
It "Should create a collection when the inputObject parameter is used" {
$actualParam = Group-Object -InputObject $testObject
$actualParam.Group.Gettype().Name | Should Be 'Collection`1'
}
It "Should return object of 'GroupInfo' type" {
$actualParam = Group-Object -InputObject $testObject
$actualParam | Should BeOfType "Microsoft.PowerShell.Commands.GroupInfo"
}
It "Should output an array when piped input is used" {
$actual = $testObject | Group-Object
,$actual | Should BeOfType "System.Array"
}
It "Should have the same output between the group alias and the group-object cmdlet" {
$actualAlias = Group-Object -InputObject $testObject
$actualCmdlet = Group-Object -InputObject $testObject
$actualAlias.Name[0] | Should Be $actualCmdlet.Name[0]
$actualAlias.Group[0] | Should Be $actualCmdlet.Group[0]
}
It "Should be able to use the property switch without error" {
{ $testObject | Group-Object -Property Attributes } | Should Not Throw
$actual = $testObject | Group-Object -Property Attributes
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should be able to use the property switch on multiple properties without error" {
{ $testObject | Group-Object -Property Attributes, Length }
$actual = $testObject | Group-Object -Property Attributes, Length
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should be able to omit members of a group using the NoElement switch without error" {
{ $testObject | Group-Object -NoElement } | Should Not Throw
($testObject | Group-Object -NoElement).Group | Should BeNullOrEmpty
}
It "Should be able to output a hashtable datatype" {
$actual = $testObject | Group-Object -AsHashTable
$actual | Should Not BeNullOrEmpty
$actual | Should BeOfType "System.Collections.Hashtable"
}
It "Should be able to access when output as hash table" {
$actual = $testObject | Group-Object -AsHashTable
$actual.Keys | Should Not BeNullOrEmpty
}
It "Should throw when attempting to use AsString without AsHashTable" {
{ $testObject | Group-Object -AsString } | Should Throw
}
It "Should not throw error when using AsString when the AsHashTable was added" {
{ $testObject | Group-Object -AsHashTable -AsString } | Should Not Throw
}
}