Merge pull request #1022 from PowerShell/ImportCSVV2Tests
Add Unit Test for Import-Csv
This commit is contained in:
commit
0d3f980795
|
@ -27,19 +27,19 @@ Describe "Import-Csv" {
|
|||
$testContent = $($(Import-Csv $testCsv -Header $header) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 3
|
||||
|
||||
# the original csv file doesn't contain the headers
|
||||
$originalContent.IndexOf($header[0]) | Should Be -1
|
||||
$originalContent.IndexOf($header[0]) | Should Be -1
|
||||
|
||||
# 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]
|
||||
}
|
||||
# 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]
|
||||
}
|
||||
|
||||
It "Should be able to use the alias without error" {
|
||||
It "Should be able to use the alias without error" {
|
||||
{ Import-Csv $testCsv } | Should Not Throw
|
||||
}
|
||||
}
|
||||
|
||||
It "Should have the same output between the alias and the full cmdlet name" {
|
||||
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
|
||||
|
||||
|
@ -47,5 +47,27 @@ It "Should have the same output between the alias and the full cmdlet name" {
|
|||
$alias[1] | Should Be $cmdlet[1]
|
||||
$alias[2] | Should Be $cmdlet[2]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Import-Csv DRT Unit Tests" -Tags DRT {
|
||||
BeforeAll {
|
||||
$fileToGenerate = Join-Path $TestDrive -ChildPath "importCSVTest.csv"
|
||||
$psObject = [pscustomobject]@{ "First" = "1"; "Second" = "2" }
|
||||
}
|
||||
|
||||
It "Test import-csv with a delimiter parameter" {
|
||||
$delimiter = ';'
|
||||
$psObject | Export-Csv -Path $fileToGenerate -Delimiter $delimiter
|
||||
$returnObject = Import-Csv -Path $fileToGenerate -Delimiter $delimiter
|
||||
$returnObject.First | Should Be 1
|
||||
$returnObject.Second | Should Be 2
|
||||
}
|
||||
|
||||
It "Test import-csv with UseCulture parameter" {
|
||||
$psObject | Export-Csv -Path $fileToGenerate -UseCulture
|
||||
$returnObject = Import-Csv -Path $fileToGenerate -UseCulture
|
||||
$returnObject.First | Should Be 1
|
||||
$returnObject.Second | Should Be 2
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue