Add Parameter Tests

This commit is contained in:
Wes Carroll
2019-07-21 20:26:24 -04:00
parent 356572a1f8
commit 7fe361dba7
@@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
Context "$global:function::Parameter Unit Tests" {
it "$global:function should have exactly 14 parameters defined" {
(get-command $global:function).Parameters.Count | Should -Be 14
}
$ParameterTestCases = @(
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
)
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
param($ParameterName, $Type, $Mandatory, $Validation)
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
}
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
param($ParameterName, $Validation)
Switch ($Validation) {
'NotNullOrEmpty' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
}
default {
$true | should be $false -Because "No Validation Selected. Review test cases"
}
}
}
}
Context "$global:function::Parameter Functional Tests" {