From 5213614299aae9f85202c099cf5ceec6bc405d3f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:36:46 -0400 Subject: [PATCH] Add Parameter count test --- Tests/Public/Import-ZertoVpg.Tests.ps1 | 4 ++++ Tests/Public/Install-ZertoVra.Tests.ps1 | 4 ++++ Tests/Public/Invoke-ZertoFailover.Tests.ps1 | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Import-ZertoVpg.Tests.ps1 b/Tests/Public/Import-ZertoVpg.Tests.ps1 index 4fd59b3..f0f8969 100644 --- a/Tests/Public/Import-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Import-ZertoVpg.Tests.ps1 @@ -5,6 +5,10 @@ $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 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" { Get-Command $global:function | Should -HaveParameter settingsFile Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory diff --git a/Tests/Public/Install-ZertoVra.Tests.ps1 b/Tests/Public/Install-ZertoVra.Tests.ps1 index e14e10f..03cb03d 100644 --- a/Tests/Public/Install-ZertoVra.Tests.ps1 +++ b/Tests/Public/Install-ZertoVra.Tests.ps1 @@ -5,6 +5,10 @@ $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 22 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 22 + } + $ParameterTestCases = @( @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } diff --git a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 index fab5802..11dd2f9 100644 --- a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 @@ -5,6 +5,10 @@ $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 20 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 20 + } + $ParameterTestCases = @( @{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; 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 } - 'Range' { + 'ShouldProcess' { $scriptBlock = (Get-Command $global:function).ScriptBlock $scriptBlock | Should -match 'SupportsShouldProcess' $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.TypeId.Count | Should -Be 2 } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } } }