Tests/Unit/Public/Find-GraphGroup.Tests.ps1
# Module: Orbit.Groups # Function: Test # Author: David Eberhardt # Updated: 03-JUN 2023 # 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.Groups' { BeforeAll { Mock Assert-GraphConnection -MockWith { $true } -ModuleName Orbit.Groups Mock Test-GraphConnection -MockWith { $true } -ModuleName Orbit.Groups Mock Get-MgGroup -MockWith { $MgGroupAll } -ParameterFilter { $All } # Splatting Parameters $Params = @{ WarningAction = 'SilentlyContinue' InformationAction = 'SilentlyContinue' } # Dot Sourcing Mock Objects . "$(Split-Path -Parent ((Split-Path -Parent $PsScriptRoot) -split 'Tests')[0])\Orbit\Tests\Testing-MockedObjects.ps1" } Context 'Input' { # Pipeline, Position, etc. } Context 'Execution' { # Code Logic } Context 'Output' { #Properties, Values, Types } Context 'not finding anything' { It "should return <Expected> for '<Identity>'" -ForEach @( @{ Identity = 'RoundWorld Observers'; Expected = $null } @{ Identity = 'RoundWorldObservers@discworld.onmicrosoft.com'; Expected = $null } @{ Identity = 'RoundWorldObservers'; Expected = $null } @{ Identity = 'fe5c659f-b00e-41c9-98bb-265fa437eabe'; Expected = $null } ) { Find-GraphGroup -Identity "$Identity" | Should -Be $Expected } } Context 'Finding Group1' { It "should return Group1 for '<Identity>'" -ForEach @( @{ Identity = 'Committee for Equal Heights'; Expected = $MgGroupGood1 } @{ Identity = 'baa40d88-cd83-4a24-8cd9-1846b28388fa'; Expected = $MgGroupGood1 } @{ Identity = 'equalheights@discworld.onmicrosoft.com'; Expected = $MgGroupGood1 } @{ Identity = 'noHeightDiscrimination'; Expected = $MgGroupGood1 } ) { $Group = Find-GraphGroup -Identity "$Identity" # $Group.Count | Should -Be 1 $Group.Identity | Should -Be $Expected.Identity # $Group.DisplayName | Should -Be $Expected.DisplayName # $Group.Mail | Should -Be $Expected.Mail # $Group.MailNickName | Should -Be $Expected.MailNickName } } Context 'Finding Group2' { It "should return Group2 for '<Identity>'" -ForEach @( @{ Identity = 'Ankh Morpork Watch - Night Watch'; Expected = $MgGroupGood2 } @{ Identity = 'c3a541b6-d0a8-4899-a171-2c25dbb12436'; Expected = $MgGroupGood2 } @{ Identity = 'nightwatch@discworld.onmicrosoft.com'; Expected = $MgGroupGood2 } @{ Identity = 'AMnightwatch'; Expected = $MgGroupGood2 } ) { $Group = Find-GraphGroup -Identity "$Identity" # $Group.Count | Should -Be 1 $Group.Identity | Should -Be $Expected.Identity # $Group.DisplayName | Should -Be $Expected.DisplayName # $Group.Mail | Should -Be $Expected.Mail # $Group.MailNickName | Should -Be $Expected.MailNickName } } } } |