Tests/Unit/Public/Users/Test-GraphUser.Tests.ps1
# Module: Orbit.Users # Function: Test # Author: David Eberhardt # Updated: 11-OCT-2020 # Script Analyzer Exceptions #[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification = 'Context Boundaries')] # Unit Tests Describe -Tags ('Unit', 'Acceptance') "Function '$(((Split-Path -Leaf $PsCommandPath) -replace '\.Tests\.', '.') -replace '\.ps1', '')'" { InModuleScope -ModuleName 'Orbit.Users' { BeforeAll { # Mocking basic connection commands to avoid connectivity related errors Mock Assert-GraphConnection -MockWith { $true } Mock Test-GraphConnection -MockWith { $true } Mock Assert-MicrosoftTeamsConnection -MockWith { $true } Mock Test-MicrosoftTeamsConnection -MockWith { $true } # Dot Sourcing Mock Objects . "$(Split-Path -Parent ((Split-Path -Parent $PsScriptRoot) -split 'Tests')[0])\Orbit\Tests\Testing-MockedObjects.ps1" } AfterAll { #Remove-Module Orbit* -Force -ErrorAction SilentlyContinue } Context 'Input' { # Pipeline, Position, etc. } Context 'Execution' { # Code Logic } Context 'Output' { #Properties, Values, Types } # Old Contexts Context 'GraphUser - Querying Microsoft Graph (User not found)' { BeforeEach { # Mocking basic connection commands to avoid connectivity related errors Mock Assert-GraphConnection -MockWith { $true } Mock Test-GraphConnection -MockWith { $true } Mock Assert-MicrosoftTeamsConnection -MockWith { $true } Mock Test-MicrosoftTeamsConnection -MockWith { $true } Mock Get-MgUser -MockWith { $null } } It 'Should return boolean false if no object is found' { Test-GraphUser -UserPrincipalName 'ReacherGilt@discworld.onmicrosoft.com' | Should -BeFalse } } Context 'GraphUser - Querying Microsoft Graph (User found)' { BeforeEach { # Mocking basic connection commands to avoid connectivity related errors Mock Assert-GraphConnection -MockWith { $true } Mock Test-GraphConnection -MockWith { $true } Mock Assert-MicrosoftTeamsConnection -MockWith { $true } Mock Test-MicrosoftTeamsConnection -MockWith { $true } Mock Get-MgUser { return $GraphUserUserGood1 } } It 'Should return boolean true if an object is found' { Test-GraphUser -UserPrincipalName 'SamVimes@discworld.onmicrosoft.com' | Should -BeTrue } } } } |