diff --git a/Tests/Public/Edit-ZertoVra.Tests.ps1 b/Tests/Public/Edit-ZertoVra.Tests.ps1 index b2ee556..c48f099 100644 --- a/Tests/Public/Edit-ZertoVra.Tests.ps1 +++ b/Tests/Public/Edit-ZertoVra.Tests.ps1 @@ -1,6 +1,6 @@ #Requires -Modules Pester $moduleFileName = "ZertoApiWrapper.psd1" -$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$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", "" @@ -15,7 +15,7 @@ Describe $file.BaseName -Tag 'Unit' { } Mock -ModuleName ZertoApiWrapper Get-ZertoVra { - vraInformation = @{ + $vraInformation = @{ DatastoreClusterIdentifier = $null DatastoreClusterName = $null DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore" @@ -60,6 +60,7 @@ Describe $file.BaseName -Tag 'Unit' { } VraVersion = 7.0 } + return $vraInformation } It "is valid Powershell (Has no script errors)" { @@ -69,28 +70,110 @@ Describe $file.BaseName -Tag 'Unit' { $errors | Should -HaveCount 0 } - It "has a mandatory String variable for the vraIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String - {Edit-ZertoVra} + Context "$($File.BaseName)::Parameter Tests" { + + It "has a mandatory String variable for the vraIdentifier" { + Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String + {Edit-ZertoVra} + } + + It "has a non-mandatory String variable for the Bandwidth Group" { + Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter groupName -Type String + } + + it "has a non-mandatory String variable for the staticIp Address" { + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String + } + + it "has a non-mandatory String variable for the default gateway" { + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String + } + + it "has a non-mandatory String variable for the subnetmask" { + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String + } + + it "supports WhatIf" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf -Not -Mandatory + } + + $cases = ` + @{vraIpAddress = "192.168.1.256"}, ` + @{vraIpAddress = "192.168.1"}, ` + @{vraIpAddress = "String"}, ` + @{vraIpAddress = 192.168.1}, ` + @{vraIpAddress = 192.168.1.246}, ` + @{vraIpAddress = 32}, ` + @{vraIpAddress = ""} + It "IpAddress field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw + } + + $cases = ` + @{subnetMask = "192.168.1.256"}, ` + @{subnetMask = "192.168.1"}, ` + @{subnetMask = "String"}, ` + @{subnetMask = 192.168.1}, ` + @{subnetMask = 192.168.1.246}, ` + @{subnetMask = 32}, ` + @{subnetMask = ""} + It "subnetMask field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw + } + + $cases = ` + @{defaultGateway = "192.168.1.256"}, ` + @{defaultGateway = "192.168.1"}, ` + @{defaultGateway = "String"}, ` + @{defaultGateway = 192.168.1}, ` + @{defaultGateway = 192.168.1.246}, ` + @{defaultGateway = 32}, ` + @{defaultGateway = ""} + It "defaultGateway field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw + } + + $cases = ` + @{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""} + + It " does not take empty strings" -TestCases $cases { + param($vraIdentifier, $paramValue, $paramName ) + if ([String]::IsNullOrEmpty($vraIdentifier)) { + {Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw + } else { + {Edit-ZertoVra -vraIdentifier $vraIdentifier -$paramName $paramValue} | should -Throw + } + } } - It "has a non-mandatory String variable for the Bandwidth Group" { - Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter groupName -Type String - } + Context "$($File.BaseName)::Function Tests" { - it "has a non-mandatory String variable for the staticIp Address" { - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String - } + It "Returns a string" { + $results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup" + $results | should not benullorempty + $results | should -BeOfType "String" + $results | Should -BeExactly "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f" + } - it "has a non-mandatory String variable for the default gateway" { - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String - } + it "Supports 'SupportsShouldProcess'" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf + Get-Command $file.BaseName | Should -HaveParameter Confirm + $file | Should -FileContentMatch 'SupportsShouldProcess' + $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + } - it "has a non-mandatory String variable for the default gateway" { - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String } + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra } \ No newline at end of file diff --git a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 index 83a2672..0b5ef84 100644 --- a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 @@ -84,3 +84,4 @@ function Edit-ZertoVra { # Nothing to Do } } +#TODO: Refactor \ No newline at end of file