Functions/Get-AllAzureADUsers.Tests.ps1
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 } } } |