Remove test, put check in begin block

This commit is contained in:
dfinke
2019-07-04 11:59:15 -04:00
parent 7faa27a3b3
commit 25fb76d9b7
2 changed files with 14 additions and 12 deletions

View File

@@ -300,6 +300,16 @@ function Import-Excel {
) )
begin { begin {
$sw = [System.Diagnostics.Stopwatch]::StartNew() $sw = [System.Diagnostics.Stopwatch]::StartNew()
# $Path = (Resolve-Path $Path).ProviderPath
$resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue)
if ($resolvedPath) {
$Path = $resolvedPath.ProviderPath
}
else {
throw "'$($Path)' file not found"
}
Function Get-PropertyNames { Function Get-PropertyNames {
<# <#
.SYNOPSIS .SYNOPSIS
@@ -346,14 +356,6 @@ function Import-Excel {
process { process {
if ($path) { if ($path) {
# $Path = (Resolve-Path $Path).ProviderPath
$resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue)
if ($resolvedPath) {
$Path = $resolvedPath.ProviderPath
}
else {
throw "'$($Path)' file not found"
}
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite' $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'
if ($Password) { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream , $Password } if ($Password) { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream , $Password }

View File

@@ -19,10 +19,10 @@
$actual | Should Not Be $null $actual | Should Not Be $null
} }
It "Should read with PSScriptRoot" { # It "Should read with PSScriptRoot" {
$actual = Import-Excel -Path "$PSScriptRoot\$($script:xlfileName)" # $actual = Import-Excel -Path "$PSScriptRoot\$($script:xlfileName)"
$actual | Should Not Be $null # $actual | Should Not Be $null
} # }
It "Should read with just a file name and resolve to cwd" { It "Should read with just a file name and resolve to cwd" {
$actual = Import-Excel -Path "$($script:xlfileName)" $actual = Import-Excel -Path "$($script:xlfileName)"