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,6 +1,9 @@
Describe "Read-OleDbData" {
#Requires -Modules Pester
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
Describe "All tests for Read-OleDbData" -Tag "Read-OleDbData" {
BeforeAll {
$tfp = (Get-ChildItem Read-OleDbData.xlsx).fullname # test file path
$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" {
@@ -35,8 +38,7 @@ 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
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestA.sql" -raw)
}
It "should be PSCustomObject" {
$Results.GetType().Name | Should -Be 'PSCustomObject'
@@ -50,8 +52,7 @@ 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
$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
$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
$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
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement (Get-Content "$scriptPath\Read-OleDbData.TestE.sql" -raw)
}
It "should be Object[]" {
$Results.GetType().Name | Should -Be 'Object[]'