diff --git a/Tests/Public/New-ZertoPairingToken.Tests.ps1 b/Tests/Public/New-ZertoPairingToken.Tests.ps1 new file mode 100644 index 0000000..51ccce7 --- /dev/null +++ b/Tests/Public/New-ZertoPairingToken.Tests.ps1 @@ -0,0 +1,51 @@ +#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' { + BeforeAll { + $script:ScriptBlock = (Get-Command $global:function).ScriptBlock + } + + Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 13 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 13 + } + + It "Supports 'SupportsShouldProcess'" { + Get-Command $global:function | Should -HaveParameter WhatIf + Get-Command $global:function | Should -HaveParameter Confirm + $script:ScriptBlock | Should -match 'SupportsShouldProcess' + $script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' + } + } + + Context "$global:function::Parameter Functional Tests" { + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { + return (Get-Content -Raw "$global:here\Mocks\PairingToken.json" | ConvertFrom-Json) + } + + It "Returns a Token" { + $Token = New-ZertoPairingToken + $Token | Should -Not -Be $Null + $Token.Token | Should -Be "TH15ISN0T4R3AL70KEN" + } + + It "Returns a ExpirationDate" { + $Token = New-ZertoPairingToken + $Token | Should -Not -Be $Null + $Token.UtcExpirationDate | Should -Be "10/09/2019 12:55 PM" + } + + It "Does not return a taskId if '-whatif' is used" { + $results = New-ZertoPairingToken -WhatIf + $results | Should -BeNullOrEmpty + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 2 + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global