2016-03-04 23:48:30 +01:00
|
|
|
Describe "Import-Csv" {
|
2016-03-04 23:42:08 +01:00
|
|
|
$testCsv = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestCsv.csv
|
2015-10-20 21:17:42 +02:00
|
|
|
|
|
|
|
It "Should be able to call without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Import-Csv $testCsv } | Should Not Throw
|
2015-10-20 21:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to assign to a variable" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual = Import-Csv $testCsv
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual | Should Not BeNullOrEmpty
|
|
|
|
$actual.GetType().BaseType | Should Be array
|
2015-10-20 21:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the data from the csv file" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualContent = $(Get-Content $testCsv)[0]
|
|
|
|
$testContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualContent.IndexOf($testContent) | Should BeGreaterThan -1
|
2015-10-20 21:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to prepend a custom header" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$header = "test1","test2","test3"
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$originalContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$testContent = $($(Import-Csv $testCsv -Header $header) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 3
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
# the original csv file doesn't contain the headers
|
|
|
|
$originalContent.IndexOf($header[0]) | Should Be -1
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
# but it does with the -Header switch!
|
|
|
|
$testContent[0] | Should Be $header[0]
|
|
|
|
$testContent[1] | Should Be $header[1]
|
|
|
|
$testContent[2] | Should Be $header[2]
|
|
|
|
}
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
It "Should be able to use the alias without error" {
|
|
|
|
{ Import-Csv $testCsv } | Should Not Throw
|
|
|
|
}
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
It "Should have the same output between the alias and the full cmdlet name" {
|
|
|
|
$alias = $($(ipcsv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
|
|
|
|
$cmdlet = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$alias[0] | Should Be $cmdlet[0]
|
|
|
|
$alias[1] | Should Be $cmdlet[1]
|
|
|
|
$alias[2] | Should Be $cmdlet[2]
|
2015-10-20 21:17:42 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
}
|
2015-10-20 21:17:42 +02:00
|
|
|
}
|