Add Parameter count test

This commit is contained in:
Wes Carroll
2019-07-21 11:36:46 -04:00
parent a39f2638d1
commit 5213614299
3 changed files with 17 additions and 1 deletions
+4
View File
@@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[
Describe $global:function -Tag 'Unit', 'Source', 'Built' { Describe $global:function -Tag 'Unit', 'Source', 'Built' {
Context "$global:function::Parameter Unit Tests" { Context "$global:function::Parameter Unit Tests" {
it "$global:function should have exactly 12 parameters defined" {
(get-command $global:function).Parameters.Count | Should -Be 12
}
It "Has a mandatory string array parameter for the settings file to import" { It "Has a mandatory string array parameter for the settings file to import" {
Get-Command $global:function | Should -HaveParameter settingsFile Get-Command $global:function | Should -HaveParameter settingsFile
Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory
+4
View File
@@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[
Describe $global:function -Tag 'Unit', 'Source', 'Built' { Describe $global:function -Tag 'Unit', 'Source', 'Built' {
Context "$global:function::Parameter Unit Tests" { Context "$global:function::Parameter Unit Tests" {
it "$global:function should have exactly 22 parameters defined" {
(get-command $global:function).Parameters.Count | Should -Be 22
}
$ParameterTestCases = @( $ParameterTestCases = @(
@{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
@{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
+9 -1
View File
@@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[
Describe $global:function -Tag 'Unit', 'Source', 'Built' { Describe $global:function -Tag 'Unit', 'Source', 'Built' {
Context "$global:function::Parameter Unit Tests" { Context "$global:function::Parameter Unit Tests" {
it "$global:function should have exactly 20 parameters defined" {
(get-command $global:function).Parameters.Count | Should -Be 20
}
$ParameterTestCases = @( $ParameterTestCases = @(
@{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
@{ParameterName = 'checkpointIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } @{ParameterName = 'checkpointIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
@@ -39,7 +43,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
} }
'Range' { 'ShouldProcess' {
$scriptBlock = (Get-Command $global:function).ScriptBlock $scriptBlock = (Get-Command $global:function).ScriptBlock
$scriptBlock | Should -match 'SupportsShouldProcess' $scriptBlock | Should -match 'SupportsShouldProcess'
$scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
@@ -49,6 +53,10 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.TypeId.Count | Should -Be 2 $attrs.TypeId.Count | Should -Be 2
} }
default {
$true | should be $false -Because "No Validation Selected. Review test cases"
}
} }
} }