mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
33
__tests__/ConvertFrom-ExcelSheet.Tests.ps1
Normal file
33
__tests__/ConvertFrom-ExcelSheet.Tests.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
||||
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent
|
||||
$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.xlsx"
|
||||
$Outpath = "TestDrive:\"
|
||||
|
||||
Describe 'ConvertFrom-ExcelSheet / Export-ExcelSheet' {
|
||||
BeforeAll {
|
||||
ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath
|
||||
$firstText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
|
||||
ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsText GridPosition,date
|
||||
$SecondText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
|
||||
ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsText "GridPosition" -Property driver,
|
||||
@{n="date"; e={[datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#")}} , FinishPosition, GridPosition
|
||||
$ThirdText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
|
||||
}
|
||||
Context "Exporting to CSV" {
|
||||
it "Exported the expected columns to a CSV file " {
|
||||
$firstText[0] | should be '"Race","Date","FinishPosition","Driver","GridPosition","Team","Points"'
|
||||
$SecondText[0] | should be '"Race","Date","FinishPosition","Driver","GridPosition","Team","Points"'
|
||||
$ThirdText[0] | should be '"Driver","date","FinishPosition","GridPosition"'
|
||||
}
|
||||
it "Applied ASText and Properties correctly " {
|
||||
$firstText[1] | should match '^"\w+","\d{5}","\d{1,2}","\w+ \w+","[1-9]\d?","\w+","\d{1,2}"$'
|
||||
$secondText[1] | should match '^"\w+","\d\d \w{3,} \d{4}","\d","\w+ \w+","0\d","\w+","\d{1,2}"$'
|
||||
$ThirdText[1] | should match '^"\w+ \w+","#\d\d/\d\d/\d{4}#","\d","0\d"$'
|
||||
}
|
||||
}
|
||||
Context "Export aliased to ConvertFrom" {
|
||||
it "Applied ASText and Properties correctly " {
|
||||
(Get-Alias Export-ExcelSheet).source | should be "ImportExcel"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user