From 809f9af60de3cc16f91ce85948df18bdb95e7f96 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 26 Aug 2020 16:08:28 -0400 Subject: [PATCH] Create Get-ZertoAzureResource function tests --- Tests/Public/Get-ZertoAzureResource.Tests.ps1 | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Tests/Public/Get-ZertoAzureResource.Tests.ps1 diff --git a/Tests/Public/Get-ZertoAzureResource.Tests.ps1 b/Tests/Public/Get-ZertoAzureResource.Tests.ps1 new file mode 100644 index 0000000..2e5a4f0 --- /dev/null +++ b/Tests/Public/Get-ZertoAzureResource.Tests.ps1 @@ -0,0 +1,56 @@ +#Requires -Modules Pester +$global:here = (Split-Path -Parent $PSCommandPath) +$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0] + +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $global:function).ScriptBlock + } + + Context "$global:function::Parameter Unit Tests" { + + It "$global:function should have exactly 17 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 17 + } + + $ParameterTestCases = @( + @{ParameterName = 'siteName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'SiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'SecurityGroup'; Type = 'Switch'; Mandatory = $true; Validation = 'None' } + @{ParameterName = 'Subnet'; Type = 'Switch'; Mandatory = $true; Validation = 'None' } + @{ParameterName = 'Network'; Type = 'Switch'; Mandatory = $true; Validation = 'None' } + @{ParameterName = 'VmInstanceType'; Type = 'Switch'; Mandatory = $true; Validation = 'None' } + + ) + + 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) { + 'None' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Count | Should -Be 3 + } + + '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::Functional Unit Tests" { + + } +} +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global