Tests relocated and updated. All passing.

This commit is contained in:
Roy Ashbrook
2021-10-29 21:58:05 -04:00
parent 9417b25af1
commit e8c3d96f43
7 changed files with 19 additions and 23 deletions

View File

@@ -1,10 +1,13 @@
Describe "Read-OleDbData" {
BeforeAll{
$tfp = (Get-ChildItem Read-OleDbData.xlsx).fullname # test file path
#Requires -Modules Pester
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
Describe "All tests for Read-OleDbData" -Tag "Read-OleDbData" {
BeforeAll {
$scriptPath = $PSScriptRoot
$tfp = "$scriptPath\Read-OleDbData.xlsx"
$cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$tfp;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'"
}
Context "When Read-OleDbData.xlsx and we want sheet1 a1" {
BeforeAll{
BeforeAll {
$sql = "select ROUND(F1) as [A1] from [sheet1`$A1:A1]"
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
}
@@ -19,7 +22,7 @@ Describe "Read-OleDbData" {
}
}
Context "When Read-OleDbData.xlsx and we want sheet2 a1" {
BeforeAll{
BeforeAll {
$sql = "select ROUND(F1) as [A1] from [sheet2`$A1:A1]"
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
}
@@ -34,9 +37,8 @@ Describe "Read-OleDbData" {
}
}
Context "When Read-OleDbData.xlsx and we want a1 on sheet3 and sql is in a file" {
BeforeAll{
$sql = Get-Content .\Read-OleDbData.TestA.sql -raw
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
BeforeAll {
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestA.sql" -raw)
}
It "should be PSCustomObject" {
$Results.GetType().Name | Should -Be 'PSCustomObject'
@@ -49,9 +51,8 @@ Describe "Read-OleDbData" {
}
}
Context "When Read-OleDbData.xlsx, we want a1 on sheets1-7, want to validate the values match properly, and sql is in a file" {
BeforeAll{
$sql = Get-Content .\Read-OleDbData.TestB.sql -raw
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
BeforeAll {
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestB.sql" -raw)
}
It "should be PSCustomObject" {
$Results[0].GetType().Name | Should -Be 'PSCustomObject'
@@ -65,23 +66,20 @@ Describe "Read-OleDbData" {
}
}
Context "When Read-OleDbData.xlsx, select range sheet1 A1:E10, and sql is in a file" {
#note, this spreadsheet doesn't have the fields populated other than A1, so it will, correctly, return only one value
BeforeAll{
$sql = Get-Content .\Read-OleDbData.TestC.sql -raw
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
BeforeAll {
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestC.sql" -raw)
}
It "should be PSCustomObject" {
$Results.GetType().Name | Should -Be 'PSCustomObject'
}
#note, this spreadsheet doesn't have the fields populated other than A1, so it will, correctly, return only one value
It "should have length of 1" {
@($Results).length | Should -Be 1
}
}
Context "When Read-OleDbData.xlsx, select a1 from all sheets as a single record, and sql is in a file" {
#note, this spreadsheet doesn't have the fields populated other than A1, so it will, correctly, return only one value
BeforeAll{
$sql = Get-Content .\Read-OleDbData.TestD.sql -raw
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
BeforeAll {
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestD.sql" -raw)
}
It "should be PSCustomObject" {
$Results.GetType().Name | Should -Be 'PSCustomObject'
@@ -94,10 +92,8 @@ Describe "Read-OleDbData" {
}
}
Context "When Read-OleDbData.xlsx, select a1 from all sheets as a single record multiple times to create a range, and sql is in a file" {
#note, this spreadsheet doesn't have the fields populated other than A1, so it will, correctly, return only one value
BeforeAll{
$sql = Get-Content .\Read-OleDbData.TestE.sql -raw
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement $sql
BeforeAll {
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestE.sql" -raw)
}
It "should be Object[]" {
$Results.GetType().Name | Should -Be 'Object[]'