From 07de073bf137b1650ddc9d46b2497a7d4cf2af6d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 24 Oct 2019 07:25:38 -0400 Subject: [PATCH] Create Invoke-ZertoEvacuateVra.Tests.ps1 --- .../Public/Invoke-ZertoEvacuateVra.Tests.ps1 | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Tests/Public/Invoke-ZertoEvacuateVra.Tests.ps1 diff --git a/Tests/Public/Invoke-ZertoEvacuateVra.Tests.ps1 b/Tests/Public/Invoke-ZertoEvacuateVra.Tests.ps1 new file mode 100644 index 0000000..c518f90 --- /dev/null +++ b/Tests/Public/Invoke-ZertoEvacuateVra.Tests.ps1 @@ -0,0 +1,53 @@ +#Requires -Modules Pester +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] + +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 16 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 16 + } + + $ParameterTestCases = @( + @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty'; ParameterSet = @('hostName') } + @{ParameterName = 'vraName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' ; ParameterSet = @('vraName') } + @{ParameterName = 'vraIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' ; ParameterSet = @('vraIdentifier') } + ) + + 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 + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + } + } + + It " parameter is part of the correct ParameterSet(s)" -TestCases $ParameterTestCases { + param($ParameterName, $ParameterSet) + $commandParameterSets = (Get-Command $global:function).Parameters[$ParameterName].ParameterSets + foreach ($Set in $ParameterSet) { + $commandParameterSets.ContainsKey($Set) | Should -BeTrue + } + } + } + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global