add back invoke tests, sync skip methods

This commit is contained in:
Roy Ashbrook
2021-11-08 17:57:44 -05:00
parent 9daefc2925
commit 9ba20b8ec8
2 changed files with 44 additions and 46 deletions

View File

@@ -1,42 +1,46 @@
# #Requires -Modules Pester
# $scriptPath = $PSScriptRoot
# Import-Module $scriptPath\..\..\ImportExcel.psd1 -Force
# $tfp = "$scriptPath\Read-OleDbData.xlsx"
# $skip = $IsLinux -or $IsMacOS #init default, not supported on mac or linux
# try {
# $IsMissingACE = $null -eq ((New-Object system.data.oledb.oledbenumerator).GetElements().SOURCES_NAME -like "Microsoft.ACE.OLEDB*")
# if ($IsMissingACE) {
# Write-Warning "MICROSOFT.ACE.OLEDB is missing! Tests will be skipped."
# }
# $skip = $skip -and $IsMissingACE
# }
# catch {
# Write-Warning "Unable to get sources from System.Data.OleDb. Tests will be skipped."
# $skip = $true #this will fail if the call to get the sources fails, usually means System.Data.OleDb isn't installed/supported
# }
#Requires -Modules Pester
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
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."
}else{
try {
if ((New-Object system.data.oledb.oledbenumerator).GetElements().SOURCES_NAME -notcontains "Microsoft.ACE.OLEDB.12.0") {
$skip = $true
Write-Warning "Read-OleDbData: Microsoft.ACE.OLEDB.12.0 provider not found. Skipping tests."
}
}
catch {
$skip = $true
Write-Warning "Read-OleDbData: Calls to System.Data.OleDb failed. Skipping tests."
}
}
# Write-Warning "`$tfp = '$tfp'"
# Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
# Write-Warning "`$IsMissingACE = '$IsMissingACE'"
# Describe "Invoke-ExcelQuery" -Tag "Invoke-ExcelQuery" {
# $PSDefaultParameterValues = @{ 'It:Skip' = $skip }
# Context "Basic Checks" {
# It "Should have a valid Test file" {
# Test-Path $tfp | Should -Be $true
# }
# It "Should have the Read-OleDbData command loaded" {
# (Get-Command Read-OleDbData) -ne $null | Should -Be $true
# }
# It "Should have the Invoke-ExcelQuery command loaded" {
# (Get-Command Invoke-ExcelQuery) -ne $null | Should -Be $true
# }
# }
# Context "Sheet1`$A1" {
# It "Should return 1 result with a value of 1" {
# $Results = Invoke-ExcelQuery $tfp "select ROUND(F1) as [A1] from [sheet1`$A1:A1]"
# @($Results).length + $Results.A1 | Should -Be 2
# }
# }
# }
Describe "Invoke-ExcelQuery" -Tag "Invoke-ExcelQuery" {
$PSDefaultParameterValues = @{ 'It:Skip' = $skip }
BeforeAll {
$tfp = "$PSScriptRoot\Read-OleDbData.xlsx"
}
Context "Basic Checks" {
It "Should have a valid Test file" {
Test-Path $tfp | Should -Be $true
}
It "Should have the Read-OleDbData command loaded" {
(Get-Command Read-OleDbData) -ne $null | Should -Be $true
}
It "Should have the Invoke-ExcelQuery command loaded" {
(Get-Command Invoke-ExcelQuery) -ne $null | Should -Be $true
}
}
Context "Sheet1`$A1" {
It "Should return 1 result with a value of 1" {
$Results = Invoke-ExcelQuery $tfp "select ROUND(F1) as [A1] from [sheet1`$A1:A1]"
@($Results).length + $Results.A1 | Should -Be 2
}
}
}

View File

@@ -19,18 +19,12 @@ if ($IsLinux -or $IsMacOS) {
Write-Warning "Read-OleDbData: Calls to System.Data.OleDb failed. Skipping tests."
}
}
Describe "Read-OleDbData" -Tag "Read-OleDbData" {
$PSDefaultParameterValues = @{ 'It:Skip' = $skip }
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;'"
if (!$skip) {
Write-Warning "`$tfp = '$tfp'"
Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
Write-Warning "`$cs = '$cs'"
}
}
Context "Basic Tests" {
It "Should have a valid Test file" {