Update Invoke-ZARestRequest.Tests.ps1
This commit is contained in:
@@ -8,33 +8,44 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
|||||||
|
|
||||||
Context "$global:function::Parameter Unit Tests" {
|
Context "$global:function::Parameter Unit Tests" {
|
||||||
|
|
||||||
it "have a mandatory string parameter for the URI Variable" {
|
$testCases = @(
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter uri -Mandatory -Type String
|
@{ParameterName = 'uri'; Type = 'String'; Mandatory = $true; TestName = 'URI' }
|
||||||
|
@{ParameterName = 'method'; Type = 'String'; Mandatory = $false; TestName = 'Method' }
|
||||||
|
@{ParameterName = 'body'; Type = 'String'; Mandatory = $false; TestName = 'Body' }
|
||||||
|
@{ParameterName = 'contentType'; Type = 'String'; Mandatory = $false; TestName = 'contentType' }
|
||||||
|
)
|
||||||
|
|
||||||
|
It "Parameter present and Type test for: <TestName> " -TestCases $testCases {
|
||||||
|
param($parameterName, $type, $Mandatory)
|
||||||
|
Get-Command $global:function | Should -HaveParameter $parameterName -Type $type
|
||||||
|
if ($Mandatory) {
|
||||||
|
Get-Command $global:function | Should -HaveParameter $parameterName -Mandatory
|
||||||
|
} else {
|
||||||
|
Get-Command $global:function | Should -HaveParameter $parameterName -Not -Mandatory
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
it "have a non-mandatory string parameter for the Method Variable, default to 'GET'" {
|
It "Method parameter default is 'GET'" {
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Type String
|
Get-Command $global:function | Should -HaveParameter Method -DefaultValue "GET"
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Not -Mandatory
|
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -DefaultValue "GET"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it "have a non-mandatory string parameter for the Body variable" {
|
It "ContentType parameter default is 'application/json'" {
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Type String
|
Get-Command $global:function | Should -HaveParameter contentType -DefaultValue "application/json"
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Not -Mandatory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it "have a non-mandatory string parameter for the contentType variable" {
|
$NotNullOrEmptyTests = @(
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Type String
|
@{ParameterName = 'uri'; TestName = 'Uri' }
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Not -Mandatory
|
@{ParameterName = 'body'; TestName = 'Body' }
|
||||||
Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -DefaultValue "application/json"
|
@{ParameterName = 'contentType'; TestName = 'ContentType' }
|
||||||
|
)
|
||||||
|
|
||||||
|
It "<TestName> parameter does not accecpt a null or empty value" -TestCases $NotNullOrEmptyTests {
|
||||||
|
param($parameterName)
|
||||||
|
$parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters[$parameterName]
|
||||||
|
$parameterInfo.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||||
}
|
}
|
||||||
|
|
||||||
it "uri variable does not accecpt a null or empty variable" {
|
It "method parametert only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" {
|
||||||
{ Invoke-ZARestRequest -uri $null } | Should Throw
|
|
||||||
{ Invoke-ZARestRequest -uri "" } | Should Throw
|
|
||||||
}
|
|
||||||
|
|
||||||
it "method variable only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" {
|
|
||||||
$parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters['method']
|
$parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters['method']
|
||||||
$parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
$parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||||
$validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }
|
$validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }
|
||||||
@@ -44,16 +55,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
|||||||
$validateSet.ValidValues -contains 'DELETE' | Should -BeTrue
|
$validateSet.ValidValues -contains 'DELETE' | Should -BeTrue
|
||||||
$validateSet.ValidValues.Count | Should -Be 4
|
$validateSet.ValidValues.Count | Should -Be 4
|
||||||
}
|
}
|
||||||
|
|
||||||
it "body variable does not accecpt a null or empty variable" {
|
|
||||||
{ Invoke-ZARestRequest -uri "connect" -body $null } | Should Throw
|
|
||||||
{ Invoke-ZARestRequest -uri "connect" -body "" } | Should Throw
|
|
||||||
}
|
|
||||||
|
|
||||||
it "accecpt variable does not accecpt a null or empty variable" {
|
|
||||||
{ Invoke-ZARestRequest -uri "connect" -accecpt $null } | Should Throw
|
|
||||||
{ Invoke-ZARestRequest -uri "connect" -accecpt "" } | Should Throw
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "$global:function::Function Unit Tests" {
|
Context "$global:function::Function Unit Tests" {
|
||||||
@@ -64,26 +65,26 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
|||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
Set-Variable -Name zaHeaders -Scope Script -Value (@{ "Accept" = "application/json" })
|
Set-Variable -Name zaHeaders -Scope Script -Value (@{ "Accept" = "application/json" })
|
||||||
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks
|
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-Date).Ticks
|
||||||
}
|
}
|
||||||
|
|
||||||
it "runs when called" {
|
It "runs when called" {
|
||||||
Invoke-ZARestRequest -uri "myuri" | Should Be "Ran Command"
|
Invoke-ZARestRequest -uri "myuri" | Should Be "Ran Command"
|
||||||
}
|
}
|
||||||
|
|
||||||
it "throws when the last action was over 60 minutes ago" {
|
It "throws when the last action was over 60 minutes ago" {
|
||||||
$script:zaLastActionTime = (get-date).AddMinutes(-61).Ticks
|
$script:zaLastActionTime = (Get-Date).AddMinutes(-61).Ticks
|
||||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw
|
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Authorization Token has Expired."
|
||||||
}
|
}
|
||||||
|
|
||||||
it "throws when the zaHeaders variable does not exits" {
|
It "throws when the zaHeaders variable does not exits" {
|
||||||
Remove-Variable -Name zaHeaders -Scope Script
|
Remove-Variable -Name zaHeaders -Scope Script
|
||||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw
|
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist."
|
||||||
}
|
}
|
||||||
|
|
||||||
it "throws when the zaLastActionTime variable does not exits" {
|
It "throws when the zaLastActionTime variable does not exist" {
|
||||||
Remove-Variable -Name zaLastActionTime -Scope Script
|
Remove-Variable -Name zaLastActionTime -Scope Script
|
||||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw
|
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist."
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1
|
Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1
|
||||||
|
|||||||
Reference in New Issue
Block a user