Tests/Get-Tenant.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
$projectRoot = Split-Path -Path $PSScriptRoot; . "$projectRoot\_functionReference.ps1"; Describe "Get-Tenant" { #setup objects $tenantList = New-Object System.Collections.ArrayList; $tenant1 = New-Object -TypeName Microsoft.Azure.Commands.Profile.Models.PSAzureTenant; $tenant1.Id = "1234"; $tenant1.Directory = "live.com"; $tenant2 = New-Object -TypeName Microsoft.Azure.Commands.Profile.Models.PSAzureTenant; $tenant2.Id = "5434"; $tenant2.Directory = "live.com"; $tenantList.Add($tenant1); $tenantList.Add($tenant2); #mock functions Mock -CommandName Get-AzureRmTenant { return $tenantList }; Mock -CommandName Set-AzureRmContext -MockWith {}; Mock -CommandName Get-ActiveDirectory -MockWith {}; Mock -CommandName Get-Subscription -MockWith {}; Mock -CommandName Add-Log -MockWith {}; Mock -CommandName Write-Progress -MockWith {}; Mock -CommandName Out-Error -MockWith {}; Context "When not specified all tenants are processed" { Get-Tenant; It "Sets the context for each tenant"{ Assert-MockCalled -CommandName Set-AzureRmContext -Times 2 -Exactly; } It "Calls active directory scan for each tenant"{ Assert-MockCalled -CommandName Get-ActiveDirectory -Times 2 -Exactly; } It "Calls subscriptions scan for each tenant"{ Assert-MockCalled -CommandName Get-Subscription -Times 2 -Exactly; } } Context "When specified only specified tenants are processed" { #specify a tenant $tenants = @("1234"); Get-Tenant; It "Only sets context for specified tenant"{ Assert-MockCalled -CommandName Set-AzureRmContext -Times 1 -Exactly; } It "Only calls active directory scan for specified tenant"{ Assert-MockCalled -CommandName Get-ActiveDirectory -Times 1 -Exactly; } It "Only calls subscriptions scan for specified tenant"{ Assert-MockCalled -CommandName Get-Subscription -Times 1 -Exactly; } } } |