Update Tests to TestCases
This commit is contained in:
@@ -1,42 +1,32 @@
|
|||||||
#Requires -Modules Pester
|
#Requires -Modules Pester
|
||||||
#Region - Test Setup
|
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
|
||||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
|
||||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
|
||||||
$file = Get-ChildItem "$here\$sut"
|
|
||||||
$modulePath = $here -replace "Public", ""
|
|
||||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
|
||||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
|
||||||
Import-Module $moduleFile -Force
|
|
||||||
#EndRegion
|
|
||||||
|
|
||||||
Describe $file.BaseName -Tag 'Unit' {
|
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||||
|
|
||||||
It "is valid Powershell (Has no script errors)" {
|
Context "$global:function::Parameter Unit Tests" {
|
||||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
|
||||||
$errors = $null
|
$ParameterTestCases = @(
|
||||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
@{ParameterName = 'OutputFile'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||||
$errors | Should -HaveCount 0
|
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||||
|
)
|
||||||
|
|
||||||
|
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||||
|
param($ParameterName, $Type, $Mandatory)
|
||||||
|
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||||
|
}
|
||||||
|
|
||||||
|
it "<ParameterName> has <Validation> validation set" -TestCases $ParameterTestCases {
|
||||||
|
param($ParameterName)
|
||||||
|
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||||
|
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
Context "$global:function::Function Unit Tests" {
|
||||||
It "has a mantatory string parameter for the output file" {
|
|
||||||
Get-Command $file.BaseName | Should -HaveParameter OutputFile -Type String -Mandatory
|
|
||||||
}
|
|
||||||
|
|
||||||
It "has a non-mandatory string array parameter for vpgName(s) to export" {
|
|
||||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[]
|
|
||||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Not -Mandatory
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Output File does not take null or empty string" {
|
|
||||||
{ Export-ZertoVpg -outputFile "" } | Should -Throw
|
|
||||||
{ Export-ZertoVpg -outputFile $null } | Should -Throw
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Vpg Name parameter does not take null or empty string" {
|
|
||||||
{ Export-ZertoVpg -outputFile ".\ExportedInfo.csv" -vpgName = "" } | Should -Throw
|
|
||||||
{ Export-ZertoVpg -outputFile ".\ExportedInfo.csv" -vpgName = $null } | Should -Throw
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Remove-Variable -Name function -Scope Global
|
||||||
|
Remove-Variable -Name here -Scope Global
|
||||||
|
|||||||
Reference in New Issue
Block a user