Functions/Get-AllAzureADUsers.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 |
describe "BitTitan.Runbooks.AzureAD/Get-AllAzureADUsers" -Tag "module", "unit" { # Import the function to test . "$($PSScriptRoot)\Get-AllAzureADUsers.ps1" # Declare external functions and mocks function Get-BT_RunbookEnvironment {} function Get-Office365TestEnvironmentAvailableUsers { param ($TestId, [Switch]$ActiveDirectory) } function Get-AzureADUser { param ($All) } $Global:Office365TestRunID = "office365TestRunID" context "when the environment is set to testing" { # Declare mocks mock Get-BT_RunbookEnvironment { return @{ IsTestEnvironment = $true } } mock Get-Office365TestEnvironmentAvailableUsers {} $Global:AzureADUsername = "admin@domain.com" it "returns the test environment users" { # Call the function Get-AllAzureADUsers # Verify the mocks Assert-MockCalled Get-Office365TestEnvironmentAvailableUsers -Times 1 -Exactly -ParameterFilter { $Office365TestRunID -eq "office365TestRunID" -and $ActiveDirectory } -Scope it } } context "when the environment is not set to testing" { # Declare mocks mock Get-BT_RunbookEnvironment { return @{ IsTestEnvironment = $false } } mock Get-AzureADUser {} $Global:AzureADUsername = "admin@domain.com" it "returns the Exchange Online users" { # Call the function Get-AllAzureADUsers # Verify the mocks Assert-MockCalled Get-AzureADUser -Times 1 -Exactly -ParameterFilter { $All -eq $true } -Scope it } } } |