mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
* Fix GetType() bad pattern and related issues in tests $var.GetType() can raise an exception in tests so we should check $var before make the call. A large part of the tests does not make this check. I start with searching ".GetType()" but discovered many related issues in tests (reduntant and unneeded tests, "throw" bad pattens, bugs, formattings (sorry!) and so on) - I had to fix them too. * Fix after code review * Second wave of migration GetType() -> BeOfType Removed 'GetType().Name' patterns.
63 lines
2.2 KiB
PowerShell
63 lines
2.2 KiB
PowerShell
Describe "Get-Unique DRT Unit Tests" -Tags "CI" {
|
|
It "Command get-unique works with AsString switch" {
|
|
$inputArray = "aa","aa","Aa","ba","BA","BA"
|
|
$results = $inputArray | Get-Unique -AsString
|
|
|
|
$results.Length | Should Be 4
|
|
|
|
$results[0] | Should Be "aa"
|
|
$results[1] | Should Be "Aa"
|
|
$results[2] | Should Be "ba"
|
|
$results[3] | Should Be "BA"
|
|
|
|
$results[0] | Should BeOfType "System.String"
|
|
$results[1] | Should BeOfType "System.String"
|
|
$results[2] | Should BeOfType "System.String"
|
|
$results[3] | Should BeOfType "System.String"
|
|
}
|
|
}
|
|
|
|
Describe "Get-Unique" -Tags "CI" {
|
|
|
|
BeforeAll {
|
|
$sortedList1 = 1,2,2,3,3,4,5
|
|
$expectedOutput1 = 1,2,3,4,5
|
|
$collection = "a", "b", "b", "d"
|
|
$expectedOutput2 = "a", "b", "d"
|
|
}
|
|
|
|
It "Should be able to use the Get-Unique cmdlet without error with inputObject switch" {
|
|
{ Get-Unique -InputObject $sortedList1 } | Should Not Throw
|
|
}
|
|
|
|
It "Should output an array" {
|
|
$result = Get-Unique -InputObject $sortedList1
|
|
$result | Should Not BeNullOrEmpty
|
|
,$result | Should BeOfType "System.Array"
|
|
}
|
|
|
|
It "Should output an array of unchanged items when the InputObject switch is used" {
|
|
$actual = Get-Unique -InputObject $sortedList1
|
|
$(Compare-Object $actual $sortedList1 -SyncWindow 0).Length | Should Be 0
|
|
}
|
|
|
|
It "Should accept piped input" {
|
|
{ $actualOutput = $sortedList1 | Get-Unique } | Should Not Throw
|
|
}
|
|
|
|
It "Should have the expected output when piped input is used" {
|
|
$actualOutput = $sortedList1 | Get-Unique
|
|
$(Compare-Object $actualOutput $expectedOutput1 -SyncWindow 0).Length | Should Be 0
|
|
}
|
|
|
|
It "Should be able to input a collection in the inputObject switch" {
|
|
$actual = Get-Unique -InputObject $collection
|
|
$(Compare-Object $actual $collection -SyncWindow 0).Length | Should Be 0
|
|
}
|
|
|
|
It "Should get the unique items when piped collection input is used" {
|
|
$actual = $collection | Get-Unique
|
|
$(Compare-Object $actual $expectedOutput2 -SyncWindow 0).Length | Should Be 0
|
|
}
|
|
}
|