mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
updating tests
This commit is contained in:
@@ -1,42 +1,42 @@
|
||||
#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
|
||||
# $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
|
||||
# }
|
||||
|
||||
|
||||
Write-Warning "`$tfp = '$tfp'"
|
||||
Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
|
||||
Write-Warning "`$IsMissingACE = '$IsMissingACE'"
|
||||
# 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 }
|
||||
# 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
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
#Requires -Modules Pester
|
||||
$scriptPath = $PSScriptRoot
|
||||
Import-Module $scriptPath\..\..\ImportExcel.psd1 -Force
|
||||
$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;'"
|
||||
$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. Please see https://www.microsoft.com/en-us/download/details.aspx?id=54920"
|
||||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
|
||||
$skip = $true
|
||||
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 = $IsMissingACE
|
||||
}
|
||||
Write-Warning "`$tfp = '$tfp'"
|
||||
Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
|
||||
Write-Warning "`$cs = '$cs'"
|
||||
Write-Warning "`$IsMissingACE = '$IsMissingACE'"
|
||||
$skip = ($IsLinux -or $IsMacOS) -and $IsMissingACE
|
||||
catch {
|
||||
Write-Warning "Unable to get sources from System.Data.OleDb. Tests will be skipped."
|
||||
}
|
||||
|
||||
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;'"
|
||||
Write-Warning "`$tfp = '$tfp'"
|
||||
Write-Warning "`Test-Path $tfp = '$(Test-Path $tfp)'"
|
||||
Write-Warning "`$cs = '$cs'"
|
||||
}
|
||||
Context "Basic Tests" {
|
||||
It "should be able to open spreadsheet" {
|
||||
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 be able to open spreadsheet" {
|
||||
$null = Read-OleDbData -ConnectionString $cs -SqlStatement "select 1"
|
||||
$true | Should -Be $true
|
||||
}
|
||||
It "should return PSCustomObject for single result" {
|
||||
It "Should return PSCustomObject for single result" {
|
||||
#multiple records will come back as Object[], but not going to test for that
|
||||
$Results = Read-OleDbData -ConnectionString $cs -SqlStatement "select 1"
|
||||
$Results.GetType().Name | Should -Be 'PSCustomObject'
|
||||
|
||||
Reference in New Issue
Block a user