From 27694899390daecac9605cea7b30e708210d8c73 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:27:11 -0400 Subject: [PATCH] Create Parameter Tests --- Tests/Public/Get-ZATask.Tests.ps1 | 40 +++++++++++++++++++++++++++++ Tests/Public/Get-ZAVolume.Tests.ps1 | 32 +++++++++++++++++++++-- Tests/Public/Get-ZAVpg.Tests.ps1 | 30 ++++++++++++++++++++-- Tests/Public/Get-ZAzOrg.Tests.ps1 | 4 ++- 4 files changed, 101 insertions(+), 5 deletions(-) diff --git a/Tests/Public/Get-ZATask.Tests.ps1 b/Tests/Public/Get-ZATask.Tests.ps1 index e6e6083..7e712d4 100644 --- a/Tests/Public/Get-ZATask.Tests.ps1 +++ b/Tests/Public/Get-ZATask.Tests.ps1 @@ -5,7 +5,47 @@ $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 = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'limitTo'; Type = 'Int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'taskIdentifier'; 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 "Interval Parameter should have a Min value of 1" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1 + } + + It "Interval 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" { diff --git a/Tests/Public/Get-ZAVolume.Tests.ps1 b/Tests/Public/Get-ZAVolume.Tests.ps1 index e6e6083..c4b6a8c 100644 --- a/Tests/Public/Get-ZAVolume.Tests.ps1 +++ b/Tests/Public/Get-ZAVolume.Tests.ps1 @@ -5,11 +5,39 @@ $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 15 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 15 + } - } + $ParameterTestCases = @( + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'clusterIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'datastoreIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) - Context "$global:function::Parameter Functional Tests" { + 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 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + Context "$global:function::Parameter Functional Tests" { + + } } } diff --git a/Tests/Public/Get-ZAVpg.Tests.ps1 b/Tests/Public/Get-ZAVpg.Tests.ps1 index e6e6083..ae44aa0 100644 --- a/Tests/Public/Get-ZAVpg.Tests.ps1 +++ b/Tests/Public/Get-ZAVpg.Tests.ps1 @@ -5,11 +5,37 @@ $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 13 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 13 + } - } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) - Context "$global:function::Parameter Functional Tests" { + 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 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + Context "$global:function::Parameter Functional Tests" { + + } } } diff --git a/Tests/Public/Get-ZAzOrg.Tests.ps1 b/Tests/Public/Get-ZAzOrg.Tests.ps1 index e6e6083..8ac00f2 100644 --- a/Tests/Public/Get-ZAzOrg.Tests.ps1 +++ b/Tests/Public/Get-ZAzOrg.Tests.ps1 @@ -5,7 +5,9 @@ $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 11 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 11 + } } Context "$global:function::Parameter Functional Tests" {