MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Get-Unique DRT Unit Tests" -Tags "CI" {4 5 BeforeAll {6 $inputArray = "aa","aa","Aa","ba","BA","BA"7 }8 9 It "Command get-unique works with AsString switch" {10 $results = $inputArray | Get-Unique -AsString11 12 $results.Length | Should -Be 413 14 $results[0] | Should -BeExactly "aa"15 $results[1] | Should -BeExactly "Aa"16 $results[2] | Should -BeExactly "ba"17 $results[3] | Should -BeExactly "BA"18 19 $results[0] | Should -BeOfType System.String20 $results[1] | Should -BeOfType System.String21 $results[2] | Should -BeOfType System.String22 $results[3] | Should -BeOfType System.String23 }24 25 It "Command get-unique works with AsString and CaseInsensitive switches" {26 $results = $inputArray | Get-Unique -AsString -CaseInsensitive27 28 $results.Length | Should -Be 229 30 $results[0] | Should -BeExactly "aa"31 $results[1] | Should -BeExactly "ba"32 33 $results[0] | Should -BeOfType System.String34 $results[1] | Should -BeOfType System.String35 }36}37 38Describe "Get-Unique" -Tags "CI" {39 40 BeforeAll {41 $sortedList1 = 1,2,2,3,3,4,542 $expectedOutput1 = 1,2,3,4,543 $collection = "a", "b", "b", "d"44 $expectedOutput2 = "a", "b", "d"45 $collection2 = "a","A", "b", "B"46 $expectedOutput3 = "a", "b"47 }48 49 It "Should be able to use the Get-Unique cmdlet without error with inputObject switch" {50 { Get-Unique -InputObject $sortedList1 } | Should -Not -Throw51 }52 53 It "Should output an array" {54 $result = Get-Unique -InputObject $sortedList155 $result | Should -Not -BeNullOrEmpty56 ,$result | Should -BeOfType System.Array57 }58 59 It "Should output an array of unchanged items when the InputObject switch is used" {60 $actual = Get-Unique -InputObject $sortedList161 $(Compare-Object $actual $sortedList1 -SyncWindow 0).Length | Should -Be 062 }63 64 It "Should accept piped input" {65 { $actualOutput = $sortedList1 | Get-Unique } | Should -Not -Throw66 }67 68 It "Should have the expected output when piped input is used" {69 $actualOutput = $sortedList1 | Get-Unique70 $(Compare-Object $actualOutput $expectedOutput1 -SyncWindow 0).Length | Should -Be 071 }72 73 It "Should be able to input a collection in the inputObject switch" {74 $actual = Get-Unique -InputObject $collection75 $(Compare-Object $actual $collection -SyncWindow 0).Length | Should -Be 076 }77 78 It "Should get the unique items when piped collection input is used" {79 $actual = $collection | Get-Unique80 $(Compare-Object $actual $expectedOutput2 -SyncWindow 0).Length | Should -Be 081 }82 83 It "Should get the unique strings when CaseInsensitive switch is used" {84 $actual = $collection2 | Get-Unique -CaseInsensitive85 $(Compare-Object $actual $expectedOutput3 -SyncWindow 0).Length | Should -Be 086 }87}88 