wip: remove param validation

This commit is contained in:
dfinke
2019-07-04 11:40:02 -04:00
parent 4581c2b3e9
commit 6d86108060
2 changed files with 15 additions and 2 deletions

View File

@@ -269,7 +269,7 @@ function Import-Excel {
[Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
[Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
[Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
[ValidateScript( { (Test-Path -Path $_ -PathType Leaf) -and ($_ -match '.xls$|.xlsx$|.xlsm$') })]
# [ValidateScript( { (Test-Path -Path $_ -PathType Leaf) -and ($_ -match '.xls$|.xlsx$|.xlsm$') })]
[String]$Path,
[Parameter(ParameterSetName = "PackageA", Mandatory)]
[Parameter(ParameterSetName = "PackageB", Mandatory)]
@@ -300,6 +300,16 @@ function Import-Excel {
)
begin {
$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 {
<#
.SYNOPSIS
@@ -346,7 +356,6 @@ function Import-Excel {
process {
if ($path) {
$Path = (Resolve-Path $Path).ProviderPath
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'
if ($Password) { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream , $Password }
else { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream }

View File

@@ -19,4 +19,8 @@
$actual = Import-Excel -Path "testRelative.xlsx"
$actual | Should Not Be $null
}
It "Should fail for not found" {
{ Import-Excel -Path "ExcelFileDoesNotExist.xlsx" } | Should Throw "'ExcelFileDoesNotExist.xlsx' file not found"
}
}