First pass. All code must be in a script block

This commit is contained in:
dfinke
2020-10-31 17:47:07 -04:00
parent 113bf2c95c
commit 6149442bc0
12 changed files with 911 additions and 839 deletions

View File

@@ -1,19 +1,18 @@
[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 {
$scriptPath = $PSScriptRoot
$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.xlsx"
$Outpath = "TestDrive:\"
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")
$script:firstText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsText GridPosition, date
$script: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")
@{n = "date"; e = { [datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#") } } , FinishPosition, GridPosition
$script:ThirdText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsDate "date"
$FourthText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
$script:FourthText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv")
}
Context "Exporting to CSV" {
it "Exported the expected columns to a CSV file " {
@@ -24,7 +23,7 @@ Describe 'ConvertFrom-ExcelSheet / Export-ExcelSheet' {
}
it "Applied AsText, AsDate and Properties correctly " {
$firstText[1] | Should -Match '^"\w+","\d{5}","\d{1,2}","\w+ \w+","[1-9]\d?","\w+","\d{1,2}"$'
$date = $firstText[1] -replace '^.*(\d{5}).*$', '$1'
$date = $firstText[1] -replace '^.*(\d{5}).*$', '$1'
$date = [datetime]::FromOADate($date).toString("D")
$secondText[1] | Should -Belike "*$date*"
$secondText[1] | Should -Match '"0\d","\w+","\d{1,2}"$'
@@ -32,7 +31,7 @@ Describe 'ConvertFrom-ExcelSheet / Export-ExcelSheet' {
$FourthText[1] | Should -Match '^"\w+","([012]\d/|[1-9]/)'
}
}
Context "Export aliased to ConvertFrom" {
Context "Export aliased to ConvertFrom" {
it "Definded the alias name with " {
(Get-Alias Export-ExcelSheet).source | Should -Be "ImportExcel"
(Get-Alias Export-ExcelSheet).Definition | Should -Be "ConvertFrom-ExcelSheet"