From b4b2f35e2197e72d45ca96c88537a9fcda1a7975 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Wed, 18 May 2016 02:02:36 -0700 Subject: [PATCH 1/3] Add Unit Test for Export-Csv --- test/powershell/Export-Csv.Tests.ps1 | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/powershell/Export-Csv.Tests.ps1 b/test/powershell/Export-Csv.Tests.ps1 index 8a50e372b..ec41322b9 100644 --- a/test/powershell/Export-Csv.Tests.ps1 +++ b/test/powershell/Export-Csv.Tests.ps1 @@ -64,3 +64,39 @@ Describe "Export-Csv" { Remove-Item $aliasObject -Force } } + +Describe "Export-Csv DRT Unit Tests" -Tags DRT{ + $filePath = Join-Path $TestDrive -ChildPath "test.csv" + $newLine = [environment]::NewLine + It "Test basic function works well" { + $input = [pscustomobject]@{ "P1" = "V11"; "P2" = "V12"; "P3" = "V13" } + $input | Export-Csv -Path $filePath -NoTypeInformation + $results = Import-Csv $filePath + $results.P1 | Should Be "V11" + $results.P2 | Should Be "V12" + $results.P3 | Should Be "V13" + } + + It "Test if it works with special character" { + $v3 = "abc" + $newLine + "foo" + $input = [pscustomobject]@{ "P1" = " "; "P2" = "abc,foo"; "P3" = $v3} + $input | Export-Csv -Path $filePath -NoTypeInformation + $results = Import-Csv $filePath + $results.P1 | Should Be " " + $results.P2 | Should Be "abc,foo" + $results.P3 | Should Be $v3 + } + + It "Test force switch works well" { + $input = [pscustomobject]@{ "P1" = "first" } + $input | Export-Csv -Path $filePath + + $input = [pscustomobject]@{ "P2" = "second" } + $input | Export-Csv -Path $filePath -Force + $results = Import-Csv $filePath + + $results.P2 | Should be "second" + $property = $results | Get-Member | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } + $property -notcontains "P1" | Should Be $true + } +} From 64b249d64706ba96ae84e1b997c65969a3e880da Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 19 May 2016 19:37:49 -0700 Subject: [PATCH 2/3] Fixed CR Issues --- test/powershell/Export-Csv.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Export-Csv.Tests.ps1 b/test/powershell/Export-Csv.Tests.ps1 index ec41322b9..3acbc931a 100644 --- a/test/powershell/Export-Csv.Tests.ps1 +++ b/test/powershell/Export-Csv.Tests.ps1 @@ -97,6 +97,6 @@ Describe "Export-Csv DRT Unit Tests" -Tags DRT{ $results.P2 | Should be "second" $property = $results | Get-Member | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } - $property -notcontains "P1" | Should Be $true + $property | should not be P1 } } From 93e78e533afb4d45753ad3e453757e0411022fd1 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Fri, 20 May 2016 02:27:44 -0700 Subject: [PATCH 3/3] Added a V2 TC --- test/powershell/Export-Csv.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/Export-Csv.Tests.ps1 b/test/powershell/Export-Csv.Tests.ps1 index 3acbc931a..f5009ff10 100644 --- a/test/powershell/Export-Csv.Tests.ps1 +++ b/test/powershell/Export-Csv.Tests.ps1 @@ -99,4 +99,16 @@ Describe "Export-Csv DRT Unit Tests" -Tags DRT{ $property = $results | Get-Member | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } $property | should not be P1 } + + It "Test export-csv with a useculture flag" { + $outputFilesDir = Join-Path $TestDrive -ChildPath "Monad" + $fileToGenerate = Join-Path $outputFilesDir -ChildPath "CSVTests.csv" + $delimiter = (Get-Culture).TextInfo.ListSeparator + New-Item -Path $outputFilesDir -ItemType Directory -Force + Get-Item -Path $outputFilesDir| Export-Csv -Path $fileToGenerate -UseCulture -NoTypeInformation + $contents = Get-Content -Path $fileToGenerate + $contents.Count | Should Be 2 + $contents[0].Contains($delimiter) | Should Be $true + $contents[1].Contains($delimiter) | Should Be $true + } }