diff --git a/Pester/Functions/Get-VmcSddc.tests.ps1 b/Pester/Functions/Get-VmcSddc.tests.ps1 index 7d848a3..de27e79 100644 --- a/Pester/Functions/Get-VmcSddc.tests.ps1 +++ b/Pester/Functions/Get-VmcSddc.tests.ps1 @@ -7,33 +7,20 @@ Describe "$functionName" -Tag 'Unit' { $global:DefaultVMCServers = $true - $display_name = "MockedDisplayName" - $user_name = "MockedUserName" - $OrgName = "MockedOrgName" - $created = "MockedDate" $OrgId = "Mocked OrgID" $name = "MockedSDDCName" $Notname = "NotTheName" - $id = "MockedId" $Service = "com.vmware.vmc.orgs.sddcs" $MockedList = [PSCustomObject]@{ - "display_name" = $display_name "name" = $name - "created" = $created - "user_name" = $user_name - "id" = $id } $MockedList2 = [PSCustomObject]@{ - "display_name" = $display_name "name" = $Notname - "created" = $created - "user_name" = $user_name - "id" = $id } $object = @( - @{"Id" = $Id} + @{"Id" = 1} ) $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList } @@ -81,7 +68,7 @@ Describe "$functionName" -Tag 'Unit' { It "gets the SDDC details via list method and returns the properties" { $object = [PSCustomObject]@{} $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList } - $(Get-VMCSDDC -Org $OrgId).display_name | Should -be $display_name + $(Get-VMCSDDC -Org $OrgId).name | Should -be $name } # Testing the multiple SDDC response It "gets the SDDC details of the SDDC supplied and returns the properties" { diff --git a/Pester/Functions/Get-VmcTask.tests.ps1 b/Pester/Functions/Get-VmcTask.tests.ps1 new file mode 100644 index 0000000..f54e944 --- /dev/null +++ b/Pester/Functions/Get-VmcTask.tests.ps1 @@ -0,0 +1,78 @@ +#Requires -Modules Pester, VMware.VMC +$functionName = $MyInvocation.MyCommand.Name.TrimEnd(".Tests.ps1") +Import-Module -Name VMware.VimAutomation.Cis.Core + +Describe "$functionName" -Tag 'Unit' { + . "$PSScriptRoot/Shared.ps1" + + $global:DefaultVMCServers = $true + + $OrgId = "Mocked OrgID" + $name = "MockedSDDCName" + $Notname = "NotTheName" + $id = "MockedId" + $Service = "com.vmware.vmc.orgs.tasks" + + $MockedList = [PSCustomObject]@{ + "name" = $name + } + $MockedList2 = [PSCustomObject]@{ + "name" = $Notname + } + + $object = @( + @{"Id" = $Id} + ) + $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList } + + $MockedArray = @($MockedList, $MockedList2) + + Mock -CommandName Get-VMCService -MockWith { $object } + + Mock -CommandName Get-VMCOrg { $object } + + Context "Sanity checking" { + $command = Get-Command -Name $functionName + + defParam $command 'Org' + } + + Context "Behavior testing" { + + It "calls Get-VMCOrg with the Org name supplied" { + { Get-VMCTask -Org $name} | Should Not Throw + Assert-MockCalled -CommandName Get-VMCOrg -Times 1 -Scope It -ParameterFilter { $name -eq $name } + } + + # Testing with single "Org" so assert call twice. + It "calls get-service to com.vmware.vmc.orgs.tasks" { + { Get-VMCTask -Org $OrgId } | Should Not Throw + Assert-MockCalled -CommandName Get-VMCService -Times 1 -Scope It -ParameterFilter { $name -eq $Service } + } + + # Testing with two "Orgs" so assert call twice. + It "calls get-service to com.vmware.vmc.orgs.tasks" { + $object = @( + @{"Id" = 1} + @{"Id" = 2} + ) + $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedArray } + { Get-VMCTask -Org $OrgId } | Should Not Throw + Assert-MockCalled -CommandName Get-VMCService -Times 2 -Scope It -ParameterFilter { $name -eq $Service } + } + + # Testing a single SDDC response + It "gets the task details via list method and returns the properties" { + $object = [PSCustomObject]@{} + $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList } + $(Get-VMCTask -Org $OrgId).name | Should -be $name + } + # Testing the multiple SDDC response + It "gets the task details of the SDDC supplied and returns the properties" { + $object = @{} + $object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedArray } + $(Get-VMCTask -Org $OrgId)[0].name | Should -be $name + $(Get-VMCTask -Org $OrgId)[1].name | Should -be $Notname + } + } +}