2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Get-Unique DRT Unit Tests" -Tags "CI" {
|
2016-04-25 00:34:00 -07:00
|
|
|
It "Command get-unique works with AsString switch" {
|
|
|
|
|
$inputArray = "aa","aa","Aa","ba","BA","BA"
|
2017-01-16 13:31:14 -08:00
|
|
|
$results = $inputArray | Get-Unique -AsString
|
|
|
|
|
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Length | Should -Be 4
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2018-03-23 10:26:23 -07:00
|
|
|
$results[0] | Should -BeExactly "aa"
|
|
|
|
|
$results[1] | Should -BeExactly "Aa"
|
|
|
|
|
$results[2] | Should -BeExactly "ba"
|
|
|
|
|
$results[3] | Should -BeExactly "BA"
|
2016-04-25 00:34:00 -07:00
|
|
|
|
2020-01-24 19:00:37 +00:00
|
|
|
$results[0] | Should -BeOfType System.String
|
|
|
|
|
$results[1] | Should -BeOfType System.String
|
|
|
|
|
$results[2] | Should -BeOfType System.String
|
|
|
|
|
$results[3] | Should -BeOfType System.String
|
2016-04-25 00:34:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Get-Unique" -Tags "CI" {
|
2017-02-16 04:40:51 +04:00
|
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$sortedList1 = 1,2,2,3,3,4,5
|
|
|
|
|
$expectedOutput1 = 1,2,3,4,5
|
|
|
|
|
$collection = "a", "b", "b", "d"
|
|
|
|
|
$expectedOutput2 = "a", "b", "d"
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-16 04:40:51 +04:00
|
|
|
It "Should be able to use the Get-Unique cmdlet without error with inputObject switch" {
|
2018-03-23 10:26:23 -07:00
|
|
|
{ Get-Unique -InputObject $sortedList1 } | Should -Not -Throw
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should output an array" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$result = Get-Unique -InputObject $sortedList1
|
2018-03-23 10:26:23 -07:00
|
|
|
$result | Should -Not -BeNullOrEmpty
|
2020-01-24 19:00:37 +00:00
|
|
|
,$result | Should -BeOfType System.Array
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should output an array of unchanged items when the InputObject switch is used" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$actual = Get-Unique -InputObject $sortedList1
|
2018-03-23 10:26:23 -07:00
|
|
|
$(Compare-Object $actual $sortedList1 -SyncWindow 0).Length | Should -Be 0
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should accept piped input" {
|
2018-03-23 10:26:23 -07:00
|
|
|
{ $actualOutput = $sortedList1 | Get-Unique } | Should -Not -Throw
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should have the expected output when piped input is used" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$actualOutput = $sortedList1 | Get-Unique
|
2018-03-23 10:26:23 -07:00
|
|
|
$(Compare-Object $actualOutput $expectedOutput1 -SyncWindow 0).Length | Should -Be 0
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to input a collection in the inputObject switch" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$actual = Get-Unique -InputObject $collection
|
2018-03-23 10:26:23 -07:00
|
|
|
$(Compare-Object $actual $collection -SyncWindow 0).Length | Should -Be 0
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should get the unique items when piped collection input is used" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$actual = $collection | Get-Unique
|
2018-03-23 10:26:23 -07:00
|
|
|
$(Compare-Object $actual $expectedOutput2 -SyncWindow 0).Length | Should -Be 0
|
2015-10-06 12:29:40 -07:00
|
|
|
}
|
|
|
|
|
}
|