2016-03-04 23:48:30 +01:00
|
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
|
|
|
|
Describe "ConvertFrom-Csv" {
|
|
|
|
$testObject = "a", "1"
|
|
|
|
$testcsv = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath TestCsv2.csv
|
|
|
|
$testName = "Zaphod BeebleBrox"
|
|
|
|
$testColumns = @"
|
2016-03-04 23:52:27 +01:00
|
|
|
a,b,c
|
|
|
|
1,2,3
|
2016-03-04 23:48:30 +01:00
|
|
|
"@
|
|
|
|
It "Should be able to be called" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ ConvertFrom-Csv -InputObject $testObject } | Should Not Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to pipe" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testObject | ConvertFrom-Csv } | Should Not Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have expected results when using piped inputs" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$csvContent = Get-Content $testcsv
|
|
|
|
$actualresult = $csvContent | ConvertFrom-Csv
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualresult.GetType().BaseType.Name | Should Be "Array"
|
|
|
|
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
#Should have a name property in the result
|
|
|
|
$actualresult[0].Name | Should Be $testName
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to set a delimiter" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should actually delimit the output" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$csvContent = Get-Content $testcsv
|
|
|
|
$actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";"
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualresult.GetType().BaseType.Name | Should Be "Array"
|
|
|
|
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
# ConvertFrom-Csv takes the first line of the input as a header by default
|
|
|
|
$actualresult.Length | Should Be $($csvContent.Length - 1)
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to have multiple columns" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualData = $testColumns | ConvertFrom-Csv
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualLength | Should Be 3
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
}
|