PSRdSessions.Tests.ps1
<#
.SYNOPSIS TEST TDD RDS .DESCRIPTION Unblock-File .EXAMPLE While ($true) {$test = Invoke-Pester -CodeCoverage .\RDS.Tests.ps1 -PassThru; $test.FailedCount; start-sleep -s 15} .EXAMPLE https://github.com/pester/Pester/wiki/Should Be BeExactly BeGreaterThan BeGreaterOrEqual BeIn BeLessThan BeLessOrEqual BeLike BeLikeExactly BeOfType BeTrue BeFalse HaveCount Contain Exist FileContentMatch FileContentMatchExactly FileContentMatchMultiline Match MatchExactly Throw BeNullOrEmpty .NOTES Alopez 2017 Em@il : alban.lopez@gmail.com require https://github.com/pester/Pester https://github.com/pester/Pester/wiki/Should Get-ChildItem C:\Users\alopez\Documents\WindowsPowerShell\Modules\Pester\ -Recurse | Unblock-File #> $psd1 = $MyInvocation.MyCommand.Source -replace ('\.Tests\.ps1', '.psd1') $psd1 | Import-Module -wa 0 -Force #Get-ChildItem $("$($MyInvocation.MyCommand.Path)\RDS.Tests.ps1" -replace('\.Tests\.ps1', '*.psm1')) | %{Import-Module $_.FullName -Force} write-center $psd1 function global:Write-LogStep {} function global:Write-Color {} Describe "Module - Testing Manifest File (.psd1)" { Context "Manifest" { It "Test-ModuleManifest $psd1" { {Test-ModuleManifest $psd1 -ea Stop} | Should -not -Throw } $Manifest = Test-ModuleManifest $psd1 -ea 0 It "Manifest Version" { $Manifest.Version -ge [version]'1.0.0.0' | Should -BeTrue } It "Manifest commands" { $Manifest.ExportedCommands.count | Should -not -BeNullOrEmpty } } } Describe "Tools" { Context "Convert-RdSession" { $RDSessions = [Cassia.TerminalServicesManager]::new().GetRemoteServer('vdiv03') $RDSessions.Open() $sessions = $RDSessions.GetSessions() It "Convert-RdSession not Throw" { {$sessions[1] | Convert-RdSession} | should -Not -Throw } It "Convert-RdSession not Throw" { ($sessions | Convert-RdSession -ResolveIp -DetailsTimeOut 10)[0] | should -BeOfType [object] } } Context 'Test-TcpPort' { It 'Test-TcpPort - <Item>' -TestCase @( @{Item = 'vdiv05.coaxis-asp.com'; Result = $false}, @{Item = 'ovfs7.open.adds'; Result = $true}, @{Item = 'badName.open.adds'; Result = $false} ) { param($Item,$Result) $Item | Test-TcpPort -port 22 -Quick | Should -be $Result } } Context 'Test-TcpPort' { It 'Test-TcpPort - <Item>' -TestCase @( @{Item = 'vdiv05.coaxis-asp.com';}, @{Item = 'ovfs7.open.adds';}, @{Item = 'badName.open.adds';} ) { param($Item) Test-TcpPort $Item -port 22 -ConfirmIfDown | Should -BeOfType [Object] } } Context 'Open-RdSession' { It 'Open-RdSession not throw' { {'vdiv03','vdiv05' | Open-RdSession -Credential (Get-CredentialByRegistry (whoami.exe))} | Should -not -Throw } } } Describe "kernel" { Context 'Get-RdComputer' { It 'Get-RdComputer not throw' { {Get-RdComputer -ComputerName 'vdiv03'} | Should -not -Throw } $RDComputer = 'vdiv03','vdiv05' | Get-RdComputer It 'Get-RdComputer - Type' { $RDComputer | Should -beOfType [Cassia.Impl.TerminalServer] } It 'Get-RdComputer - isOpen' { ($RDComputer | Get-RdComputer).isOpen | Should -be @($true, $true) } It 'Get-RdComputer - Dragonfly' { ([PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $true Port445 = $true } | Get-RdComputer).isOpen | Should -be $true } It 'Get-RdComputer - Dragonfly error' { [PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $false Port445 = $false } | Get-RdComputer | Should -beOfType [Hashtable] } } Context "Get-RdSession" { It "Get-RdSession not Throw" { {[PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $true Port445 = $true } | Get-RdSession} | should -Not -Throw } It "Get-RdSession not Throw" { {'vdiv05.coaxis-asp.com' | Get-RdSession} | should -Not -Throw } $Session = 'ovfs7.open.adds' | get-rdcomputer | Get-RdSession It "Get-RdSession ovfs7.open.adds Type" { $session.State | should -Be 'Linux' } $Session = 'FakeComputer' | Get-RdSession It "Get-RdSession padmin1 Type" { $session.State | should -Be 'HS' } $Session = 'vdiv05.coaxis-asp.com' | Get-RdSession -Identity '*alopez' It "Get-RdSession vdiv05.coaxis-asp.com Type" { $session | should -BeOfType [Cassia.Impl.TerminalServicesSession] } It "Get-RdSession vdiv05.coaxis-asp.com" { $session.Server.servername | should -Be 'vdiv05.coaxis-asp.com' } } Context 'Request-RdSession' { It 'Request-RdSession not throw' { {[PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $true Port445 = $true } | Request-RdSession -id 'personne'} | Should -not -Throw } $Request = 'vdiv03' | Request-RdSession -identity '*alopez' -TimeOut 1 It 'Request-RdSession - Type' { $Request | Should -beOfType [Cassia.Impl.TerminalServicesSession] } It 'Request-RdSession - username' { $Request.username | Should -be 'alopez' } It 'Request-RdSession - answer' { $Request.answer | Should -be 'TimeOut' } } Context 'Send-RdSession' { It 'Send-RdSession not throw' { {[PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $true Port445 = $true } | Send-RdSession -id 'personne'} | Should -not -Throw } $send = 'vdiv03' | Send-RdSession -identity '*alopez' It 'Send-RdSession - Type' { $send | Should -beOfType [Cassia.Impl.TerminalServicesSession] } It 'Send-RdSession - username' { $send.username | Should -be 'alopez' } } Context 'Stop-RdSession' { It 'Stop-RdSession not throw' { {[PSCustomObject]@{ ComputerName = 'vdiv03' IP = '10.48.4.212' Port22 = $false Port135 = $true Port445 = $true } | Stop-RdSession -Identity 'personne'} | Should -not -Throw } It 'Stop-RdSession - Type' { 'vdiv03' | Stop-RdSession -Identity '*\alopez' | Should -beOfType [Cassia.Impl.TerminalServicesSession] } It 'Stop-RdSession - username' { ('vdiv05' | Stop-RdSession -Identity '*\alopez').username | Should -be 'alopez' } } } Describe "Man" { Context "CodeFuntion" { It "Build-Readme.md" { {Build-Readme.md '*.psm1' -MarkDownFileName 'README.md'} | Should -Not -Throw } } } # $psd1 | Import-Module -wa 0 -Force Import-Module BrightModule -function Write-LogStep,Write-Color |