From fd1619351edc8eca8b8dc3faa9ea6257ddca952e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:51:13 -0400 Subject: [PATCH] Update Parameter Tests --- Tests/Public/Get-ZertoEvent.Tests.ps1 | 103 ++++++++++++++++++++++ ZertoApiWrapper/Public/Get-ZertoEvent.ps1 | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Get-ZertoEvent.Tests.ps1 b/Tests/Public/Get-ZertoEvent.Tests.ps1 index e6e6083..b257e26 100644 --- a/Tests/Public/Get-ZertoEvent.Tests.ps1 +++ b/Tests/Public/Get-ZertoEvent.Tests.ps1 @@ -5,7 +5,110 @@ $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 28 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 28 + } + $ParameterTestCases = @( + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpg'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'eventType'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'entityType'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'userName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'category'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'eventCategory'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'eventId'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'categories'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'entities'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'types'; Type = 'Switch'; Mandatory = $true; Validation = $null } + ) + + 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 + } + + 'Set' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + } + + $null { + $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" + } + } + } + + It "entityType parameter only accecpts 4 different values" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 4 + } + + It "entityType parameter accecpts 'VPG' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VPG' + } + + It "entityType parameter accecpts 'VRA' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VRA' + } + + It "entityType parameter accecpts 'Unknown' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Unknown' + } + + It "entityType parameter accecpts 'Site' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Site' + } + + It "category parameter only accecpts 3 different values" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 3 + } + + It "category parameter accecpts 'All' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All' + } + + It "category parameter accecpts 'events' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events' + } + + It "category parameter accecpts 'alerts' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts' + } + + It "eventCategory parameter only accecpts 3 different values" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 3 + } + + It "eventCategory parameter accecpts 'All' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All' + } + + It "eventCategory parameter accecpts 'events' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events' + } + + It "eventCategory parameter accecpts 'alerts' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts' + } } Context "$global:function::Parameter Functional Tests" { diff --git a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 index 1c45ee8..76584f6 100644 --- a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 @@ -69,7 +69,7 @@ function Get-ZertoEvent { ParameterSetName = "filter", HelpMessage = "The type of event to return. This filter behaves in the same way as the eventCategory filter. Possible Values are: Possible Values are: 'All', 'Events', 'Alerts'" )] - [ValidateNotNullOrEmpty()] + [ValidateSet('All','Events','Alerts')] [string]$category, [Parameter( ParameterSetName = "filter",