From 5d92442488437244f3c3e615eb698ddc88c0d33f Mon Sep 17 00:00:00 2001 From: jhoneill Date: Wed, 30 Oct 2019 17:38:09 +0000 Subject: [PATCH] New tests for import -asText and send-SQL -Force --- __tests__/InputItemParameter.tests.ps1 | 30 ++++++++++++++++++- .../Set-Row_Set-Column-SetFormat.tests.ps1 | 30 +++++++++---------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/__tests__/InputItemParameter.tests.ps1 b/__tests__/InputItemParameter.tests.ps1 index f85739b..b572f80 100644 --- a/__tests__/InputItemParameter.tests.ps1 +++ b/__tests__/InputItemParameter.tests.ps1 @@ -16,6 +16,9 @@ Describe "Exporting with -Inputobject" { export-excel -Path $path -InputObject $results -WorksheetName Sheet1 -RangeName "Whole" export-excel -Path $path -InputObject $DataTable -WorksheetName Sheet2 -AutoNameRange Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet3 -TableName "Data" + $DataTable.Rows.Clear() + Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet4 -force + Send-SQLDataToExcel -path $path -DataTable ([System.Data.DataTable]::new('Test2')) -WorkSheetname Sheet5 -force $excel = Open-ExcelPackage $path $sheet = $excel.Sheet1 } @@ -60,7 +63,7 @@ Describe "Exporting with -Inputobject" { } $sheet = $excel.Sheet3 Context "Table of processes via Send-SQLDataToExcel" { - it "Put the correct rows and columns into the sheet " { + it "Put the correct data rows and columns into the sheet " { $sheet.Dimension.Rows | should be ($results.Count + 1) $sheet.Dimension.Columns | should be 5 $sheet.cells["A1"].Value | should be "Name" @@ -76,4 +79,29 @@ Describe "Exporting with -Inputobject" { $sheet.Cells["E11"].Style.Numberformat.NumFmtID | should be 22 } } + $Sheet = $excel.Sheet4 + Context "Zero row Data Table sent with Send-SQLDataToExcel -Force" { + it "Put the correct data headers into the sheet " { + $sheet.Dimension.Rows | should be 1 + $sheet.Dimension.Columns | should be 5 + $sheet.cells["A1"].Value | should be "Name" + $sheet.cells["E1"].Value | should be "StartTime" + $sheet.cells["A3"].Value | should beNullOrEmpty + } + } + $Sheet = $excel.Sheet5 + Context "Zero column data table handled by Send-SQLDataToExcel -Force" { + it "Put Created a blank Sheet " { + $sheet.Dimension | should beNullOrEmpty + } + } + Close-ExcelPackage $excel + Context "Import As Text returns text values" { + $x = import-excel $path -WorksheetName sheet3 -AsText | Select-Object -last 1 + it "Had fields of type string, not date or int " { + $x.Handles.GetType().Name | should be "String" + $x.StartTime.GetType().Name | should be "String" + } + } + } \ No newline at end of file diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index 2b6bac0..f2d71c7 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -323,36 +323,36 @@ Describe "AutoNameRange data with a single property name" { Remove-Item $xlfile -ErrorAction SilentlyContinue } - it "Should have a single item as a named range" { - $excel = ConvertFrom-Csv @" + it "Should have a single item as a named range " { + $excel = ConvertFrom-Csv @" Sold 1 2 3 4 -"@ | Export-Excel $xlfile -PassThru -AutoNameRange +"@ | Export-Excel $xlfile -PassThru -AutoNameRange - $ws = $excel.Workbook.Worksheets["Sheet1"] + $ws = $excel.Workbook.Worksheets["Sheet1"] - $ws.Names.Count | Should Be 1 - $ws.Names[0].Name | Should Be 'Sold' - } + $ws.Names.Count | Should Be 1 + $ws.Names[0].Name | Should Be 'Sold' + } - it "Should have a more than a single item as a named range" { - $excel = ConvertFrom-Csv @" + it "Should have a more than a single item as a named range " { + $excel = ConvertFrom-Csv @" Sold,ID 1,a 2,b 3,c 4,d -"@ | Export-Excel $xlfile -PassThru -AutoNameRange +"@ | Export-Excel $xlfile -PassThru -AutoNameRange - $ws = $excel.Workbook.Worksheets["Sheet1"] + $ws = $excel.Workbook.Worksheets["Sheet1"] - $ws.Names.Count | Should Be 2 - $ws.Names[0].Name | Should Be 'Sold' - $ws.Names[1].Name | Should Be 'ID' - } + $ws.Names.Count | Should Be 2 + $ws.Names[0].Name | Should Be 'Sold' + $ws.Names[1].Name | Should Be 'ID' + } } Describe "Table Formatting" {