From fee7cd9723d11bf93f69900e9176e142eee7ad9d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 18:16:25 -0400 Subject: [PATCH] Add Parameter Validation Tests --- Tests/Public/Get-ZAAlert.Tests.ps1 | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAAlert.Tests.ps1 b/Tests/Public/Get-ZAAlert.Tests.ps1 index e6e6083..9695510 100644 --- a/Tests/Public/Get-ZAAlert.Tests.ps1 +++ b/Tests/Public/Get-ZAAlert.Tests.ps1 @@ -6,6 +6,47 @@ 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 = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'limitTo'; Type = 'int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " 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 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "LimitTo Parameter should have a Min value of 1" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1 + } + + It "LimitTo Parameter should have a Max value of 1000000" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 1000000 + } } Context "$global:function::Parameter Functional Tests" {