update tests

This commit is contained in:
Roy Ashbrook
2021-11-08 17:40:33 -05:00
parent d41fbf8a05
commit 5f00f5cbbc

View File

@@ -1,33 +1,43 @@
#Requires -Modules Pester #Requires -Modules Pester
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
$skip = $true Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
$skip = $false
if ($IsLinux -or $IsMacOS) {
$skip = $true
Write-Warning "Read-OleDbData: Linux and MacOs are not supported. Skipping tests."
}
try { try {
$IsMissingACE = $null -eq ((New-Object system.data.oledb.oledbenumerator).GetElements().SOURCES_NAME -like "Microsoft.ACE.OLEDB*") if ((New-Object system.data.oledb.oledbenumerator).GetElements().SOURCES_NAME -notcontains "Microsoft.ACE.OLEDB.12.0") {
if ($IsMissingACE) { $skip = $true
Write-Warning "MICROSOFT.ACE.OLEDB is missing! Tests will be skipped." Write-Warning "Read-OleDbData: Microsoft.ACE.OLEDB.12.0 provider not found. Skipping tests."
} }
$skip = $IsMissingACE $skip = $IsMissingACE
} }
catch { catch {
Write-Warning "Unable to get sources from System.Data.OleDb. Tests will be skipped." $skip = $true
Write-Warning "Read-OleDbData: Calls to System.Data.OleDb failed. Skipping tests."
} }
Describe "Read-OleDbData" -Tag "Read-OleDbData" { Describe "Read-OleDbData" -Tag "Read-OleDbData" {
$PSDefaultParameterValues = @{ 'It:Skip' = $skip } $PSDefaultParameterValues = @{ 'It:Skip' = $skip }
BeforeAll{ BeforeAll {
$scriptPath = $PSScriptRoot $scriptPath = $PSScriptRoot
$tfp = "$scriptPath\Read-OleDbData.xlsx" $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;'" $cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$tfp;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'"
Write-Warning "`$tfp = '$tfp'" if (!$skip) {
Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'" Write-Warning "`$tfp = '$tfp'"
Write-Warning "`$cs = '$cs'" Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
Write-Warning "`$cs = '$cs'"
}
} }
Context "Basic Tests" { Context "Basic Tests" {
It "Should have a valid Test file" { It "Should have a valid Test file" {
Test-Path $tfp | Should -Be $true Test-Path $tfp | Should -Be $true
} }
It "Should have the Read-OleDbData command loaded" { It "Should have the Read-OleDbData command loaded" {
(Get-Command Read-OleDbData) -ne $null | Should -Be $true (Get-Command Read-OleDbData -ErrorAction SilentlyContinue) -ne $null | Should -Be $true
} }
It "Should be able to open spreadsheet" { It "Should be able to open spreadsheet" {
$null = Read-OleDbData -ConnectionString $cs -SqlStatement "select 1" $null = Read-OleDbData -ConnectionString $cs -SqlStatement "select 1"