Tests/Authentication.Tests.ps1
using namespace System.Collections.Generic BeforeAll { $TMModuleDirectory = (Get-ChildItem $PSScriptRoot | Select-Object -First 1).Directory.Parent Import-Module "$TMModuleDirectory\TransitionManager.psm1" -Force . $TMModuleDirectory\Classes\TransitionManager.Classes.ps1 $ValidSessions = [List[TMSession]]::new() $Global:TMSessions = @{} $SessionsWithVersions = @{ tmad61 = '6.1.2.3' tmad62 = '6.2.3.4' other61 = '6.1.6.9' some60 = '6.0.0.1' ya61 = '6.1.6.6' } foreach ($ServerName in $SessionsWithVersions.Keys) { $Session = [TMSession]::new($ServerName, "$ServerName.transitionmanager.net", $true) $Session.TMVersion = $SessionsWithVersions.$ServerName $ValidSessions.Add($Session) } $ValidSessions.Item(0).Name = 'Default' foreach ($Session in $ValidSessions) { $Global:TMSessions.Add($Session.Name, $Session) } $NonExistingName = 'this-is-a-name-that-does-not-exist' $SingleVersion = '6.1.2.3' $MultipleVersions = '6.1*' $MajorVersion = '6*' $NonExistingVersion = '4.0.6.8' $SingleServerMatch = $ValidSessions.Item(0).TMServer $Multiple61ServerMatch = '*61' $MultipleTMADServerMatch = 'tmad*' } Describe 'Get-TMSession byObject' { It 'Returns the provided valid TMSession' { foreach ($ValidSession in $ValidSessions) { $Session = Get-TMSession -TMSession $ValidSession $Session.GetType().Name | Should -EQ 'TMSession' } } It 'Throws on invalid TMSession' { { Get-TMSession -TMSession ([TMSession]::new('my session name', 'my server', $true <# AllowInsecureSSL #>)) } | Should -Throw } } Describe 'Get-TMSession by Name' { It 'Returns the valid, specified session' { foreach ($ValidSession in $ValidSessions) { $Session = Get-TMSession -Name $ValidSession.Name $Session.GetType().Name | Should -EQ 'TMSession' $Session.Count | Should -EQ 1 } } It 'Returns all sessiones specified by name' { $Sessions = Get-TMSession -Name $ValidSessions.Name $Sessions.Count | Should -EQ $ValidSessions.Count foreach ($Session in $Sessions) { $Session.GetType().Name | Should -EQ 'TMSession' } } It 'Throws if the one specified session is not found' { { Get-TMSession -Name $NonExistingName } | Should -Throw } } Describe 'Get-TMSession by Version' { It 'Returns one valid session speicified by Version' { $Session = Get-TMSession -Version $SingleVersion $Session.GetType().Name | Should -EQ 'TMSession' $Session.Count | Should -EQ 1 } It 'Returns all sessions matching major and minor' { $Sessions = Get-TMSession -Version $MultipleVersions $Sessions.GetType().Name | Should -EQ 'TMSession[]' } It 'Returns all sessions matching major' { $Sessions = Get-TMSession -Version $MajorVersion $Sessions.Count | Should -EQ $ValidSessions.Count } It 'Throws if the one specified session is not found' { { Get-TMSession -Version $NonExistingVersion } | Should -Throw } } Describe 'Get-TMSession by Server' { It 'Returns a single session by matching server' { $Session = Get-TMSession -Server $SingleServerMatch $Session.GetType().Name | Should -EQ 'TMSession' $Session.Count | Should -EQ $ValidSessions.Where({$_.TMServer -eq $SingleServerMatch}).Count } It 'Returns all sessions matching the server name ending in 61' { $Sessions = Get-TMSession -Server $Multiple61ServerMatch $Sessions.GetType().Name | Should -EQ 'TMSession[]' $Sessions.Count | Should -EQ $ValidSessions.Where({$_.TMServer -like "$Multiple61ServerMatch*"}).Count } It 'Returns all sessions matching the server name starting with "tmad"' { $Sessions = Get-TMSession -Server $MultipleTMADServerMatch $Sessions.GetType().Name | Should -EQ 'TMSession[]' $Sessions.Count | Should -EQ $ValidSessions.Where({$_.TMServer -like "$MultipleTMADServerMatch*"}).Count } It 'Throws if the specified server is invalid' { { Get-TMSession -Server $NonExistingName } | Should -Throw } } |