Tests/Public/Teams/Get-TeamsTeamAndChannel.Tests.ps1
# Module: TeamsFunctions # Function: Test # Author: David Eberhardt # Updated: 24-JUL-2022 InModuleScope TeamsFunctions { BeforeAll { # Mocking basic connection commands to avoid connectivity related errors Mock Assert-AzureADConnection { return $true } Mock Assert-MicrosoftTeamsConnection { return $true } Mock Test-MicrosoftTeamsConnection { return $true } # Splatting Parameters $Params = @{ WarningAction = 'SilentlyContinue' InformationAction = 'SilentlyContinue' ErrorAction = 'Stop' } # Dot Sourcing Mock Objects . "$(Get-ParentDirectoryPath -TargetParentDirectory 'Tests' -DirectoryName $PSScriptRoot)\Public\Testing-MockedObjects.ps1" } Describe -Tags ('Unit', 'Acceptance') "Function 'Get-TeamsTeamAndChannel'" { Context 'Team not found' { BeforeEach { Mock Get-Team { throw } } It 'should return neither a Team Object nor a Channel Object - with ParameterSet Team' { $TeamObject = $ChannelObject = $null $Team = 'Trunk Company' $Channel = 'General' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = 'Trunk Company' $Channel = '19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = 'General' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = '19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty } It 'should return neither a Team Object nor a Channel Object - with ParameterSet String' { $TeamObject = $ChannelObject = $null $Identity = 'Trunk Company\General' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = 'Trunk Company\19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\General' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject.GroupId | Should -BeNullOrEmpty $ChannelObject.Id | Should -BeNullOrEmpty } } Context 'Team found but Channel not found' { BeforeEach { # Using Testing-MockedObjects.ps1: $TeamGood Mock Get-Team { return $TeamGood } Mock Get-TeamChannel { return } } It 'should return a Team Object but not a Channel Object - with ParameterSet Team' { $TeamObject = $ChannelObject = $null $Team = 'Night Watch' $Channel = 'Bribes' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = 'Night Watch' $Channel = '19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = 'Bribes' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = '19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty } It 'should return a Team Object but not a Channel Object - with ParameterSet String' { $TeamObject = $ChannelObject = $null $Identity = 'Night Watch\Bribes' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = 'Night Watch\19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\Bribes' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity @Params } | Should -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String $Identity -ErrorAction SilentlyContinue $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -BeNullOrEmpty } } Context 'Team and Channel found - with ParameterSet Team' { BeforeEach { # Using Testing-MockedObjects.ps1: $TeamGood and $TeamChannelGood # $TeamChannelGood returns three Objects and narrows down to one Mock Get-Team { return $TeamGood } Mock Get-TeamChannel { return $TeamChannelGood } } It 'should find a Team by Name and a Channel by Name and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Team = 'Night Watch' $Channel = 'Night Watch - Duty Roster' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Name and a Channel by Id and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Team = 'Night Watch' $Channel = '19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Id and a Channel by Name and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = 'Night Watch - Duty Roster' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Id and a Channel by Id and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Team = '6c105977-d636-419a-b5f3-4885375e432a' $Channel = '19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -Team $Team -Channel $Channel @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } } Context 'Team and Channel found - with ParameterSet String' { BeforeEach { # Using Testing-MockedObjects.ps1: $TeamGood and $ChannelGood # $ChannelGood returns one Object as `Get-TeamTeamsChannel -String` is defined to find an exact object Mock Get-Team { return $TeamGood } Mock Get-TeamChannel { return $ChannelGood } } It 'should find a Team by Name and a Channel by Name and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Identity = 'Night Watch\Night Watch - Duty Roster' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Name and a Channel by Id and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Identity = 'Night Watch\19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Id and a Channel by Name and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\Night Watch - Duty Roster' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } It 'should find a Team by Id and a Channel by Id and return a Team Object and a Channel object' { $TeamObject = $ChannelObject = $null $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2' { $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params} | Should -Not -Throw $TeamObject, $ChannelObject = Get-TeamsTeamAndChannel -String "$Identity" @Params $TeamObject.GroupId | Should -Be $TeamGood.GroupId $ChannelObject.Id | Should -Be $ChannelGood.Id } } } } |