Tests/Get-Tenant.Tests.ps1
$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; } } } |