diff --git a/src/pester-tests/Get-Event.Tests.ps1 b/src/pester-tests/Get-Event.Tests.ps1 new file mode 100644 index 0000000000..5eee63bba3 --- /dev/null +++ b/src/pester-tests/Get-Event.Tests.ps1 @@ -0,0 +1,33 @@ +Describe "Get-Event" { + + BeforeEach { + ( New-Event -SourceIdentifier PesterTestEvent -sender windows.timer -messagedata "PesterTestMessage" ) + } + + AfterEach { + ( Remove-Event -SourceIdentifier PesterTestEvent -ErrorAction SilentlyContinue ) + } + + Context "Check return type of Get-Event" { + + It "Should return PSEventArgs as return type of Get-Event" { + { ( Get-Event -SourceIdentifier PesterTestEvent ).GetType() | Should Be System.Management.Automation.PSEventArgs } + } + } + + Context "Validate Get-Event can retrieve event" { + + It "Should return at least 1 event" { + { (Get-Event).Count | Should BeGreaterThan 0 } + } + + It "Should return PesterTestMessage as the MessageData" { + { (Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage" } + } + + It "Should return Sender as windows.timer" { + { (Get-Event -SourceIdentifier PesterTimer).Sender | Should be windows.timer } + } + + } +} diff --git a/src/pester-tests/Get-RunspaceDebug.Tests.ps1 b/src/pester-tests/Get-RunspaceDebug.Tests.ps1 new file mode 100644 index 0000000000..7c66ed7363 --- /dev/null +++ b/src/pester-tests/Get-RunspaceDebug.Tests.ps1 @@ -0,0 +1,9 @@ +Describe "Get-RunspaceDebug" { + + Context "Check return types of RunspaceDebug" { + + It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" { + (Get-RunspaceDebug).GetType() | Should Be Microsoft.Powershell.Commands.PSRunspaceDebug + } + } +} diff --git a/src/pester-tests/Import-Alias.Tests.ps1 b/src/pester-tests/Import-Alias.Tests.ps1 new file mode 100644 index 0000000000..9520146877 --- /dev/null +++ b/src/pester-tests/Import-Alias.Tests.ps1 @@ -0,0 +1,27 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Import-Alias" { + $pesteraliasfile = "$here/assets/pesteralias.txt" + + Context "Validate ability to import alias file" { + + It "Should be able to import an alias file successfully" { + { Import-Alias $pesteraliasfile } | Should Not throw + } + + It "Should be able to import file via the Import-Alias alias of ipal" { + { ipal $pesteraliasfile } | Should Not throw + } + + It "Should be able to import an alias file and perform imported aliased echo cmd" { + (Import-Alias $pesteraliasfile) + (pesterecho pestertesting) | Should Be "pestertesting" + } + + It "Should be able to use ipal alias to import an alias file and perform cmd" { + (ipal $pesteraliasfile) + (pesterecho pestertesting) | Should be "pestertesting" + } + + } +} diff --git a/src/pester-tests/Invoke-Expression.Tests.ps1 b/src/pester-tests/Invoke-Expression.Tests.ps1 new file mode 100644 index 0000000000..6606eaed75 --- /dev/null +++ b/src/pester-tests/Invoke-Expression.Tests.ps1 @@ -0,0 +1,31 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Invoke-Expression" { + + Context "Should execute the invoked command validly" { + + It "Should return the echoed text" { + (Invoke-Expression -command "echo pestertest1") | Should be "pestertest1" + } + + It "Should return the echoed text for the alias" { + (iex -command "echo pestertest2") | Should Be "pestertest2" + } + + It "Should return the echoed text from a script" { + $testfile = "$here/assets/echoscript.ps1" + $testcommand = "echo pestertestscript" + $testcommand | Add-Content -Path $testfile + (Invoke-Expression $testfile) | Should Be "pestertestscript" + Remove-Item $testfile + } + + It "Should return the echoed text from a script from the alias" { + $testfile = "$here/assets/echoscript.ps1" + $testcommand = "echo pestertestscript" + $testcommand | Add-Content -Path $testfile + (iex $testfile) | Should Be "pestertestscript" + Remove-Item $testfile + } + } +} diff --git a/src/pester-tests/Measure-Command.Tests.ps1 b/src/pester-tests/Measure-Command.Tests.ps1 new file mode 100644 index 0000000000..16690a1440 --- /dev/null +++ b/src/pester-tests/Measure-Command.Tests.ps1 @@ -0,0 +1,28 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Measure-Command" { + + Context "Validate return types for Measure-Command" { + + It "Should return TimeSpan as the return type" { + (Measure-Command { Get-Date }).GetType() | Should Be timespan + } + } + + Context "Validate that it is executing commands correctly" { + + It "Should return TimeSpan after executing a script" { + (Measure-Command { echo hi }).GetType() | Should Be timespan + } + + It "Should return TimeSpan after executing a cmdlet" { + $pesterscript = "$here/assets/echoscript.ps1" + $testfile = "$here/assets/echoscript.ps1" + $testcommand = "echo pestertestscript" + $testcommand | Add-Content -Path $testfile + + (Measure-Command { $pesterscript }).GetType() | Should Be timespan + Remove-Item $testfile + } + } +} diff --git a/src/pester-tests/Register-EngineEvent.Tests.ps1 b/src/pester-tests/Register-EngineEvent.Tests.ps1 new file mode 100644 index 0000000000..bf5a2b935e --- /dev/null +++ b/src/pester-tests/Register-EngineEvent.Tests.ps1 @@ -0,0 +1,9 @@ +Describe "Register-EngineEvent" { + + Context "Check return type of Register-ObjectEvent" { + It "Should return System.Management.Automation.PSEventJob as return type of Register-EngineEvent" { + ( Register-EngineEvent -SourceIdentifier PesterTestRegister -Action {echo registerengineevent} ).GetType() | Should Be System.Management.Automation.PSEventJob + Unregister-Event -sourceidentifier PesterTestRegister + } + } +} diff --git a/src/pester-tests/Register-ObjectEvent.Tests.ps1 b/src/pester-tests/Register-ObjectEvent.Tests.ps1 new file mode 100644 index 0000000000..0e8d5c8035 --- /dev/null +++ b/src/pester-tests/Register-ObjectEvent.Tests.ps1 @@ -0,0 +1,31 @@ +Describe "Register-ObjectEvent" { + + BeforeEach { + $pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object]) + } + + AfterEach { + Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue + } + + Context "Check return type of Register-ObjectEvent" { + + It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event with the registered sourceidentifier" { + Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).GetType() | Should Be System.Management.Automation.PSEventSubscriber + } + } + + Context "Check Register-ObjectEvent can validly register events"{ + It "Should return source identifier of PesterTimer " { + Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister" + } + + It "Should return an integer greater than 0 for the SubscriptionId" { + Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0 + + } + } +} diff --git a/src/pester-tests/Remove-Event.Tests.ps1 b/src/pester-tests/Remove-Event.Tests.ps1 new file mode 100644 index 0000000000..cd44741e8a --- /dev/null +++ b/src/pester-tests/Remove-Event.Tests.ps1 @@ -0,0 +1,38 @@ +Describe "Remove-Event" { + + BeforeEach{ + New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage" + } + + AfterEach{ + Remove-Event -sourceidentifier PesterTimer -ErrorAction SilentlyContinue + } + + Context "Check Remove-Event can validly remove events" { + + It "Should remove an event given a sourceidentifier" { + { Remove-Event -sourceidentifier PesterTimer } + { Get-Event -ErrorAction SilentlyContinue | Should Not Contain PesterTimer } + } + + It "Should remove an event given an event identifier" { + { $events = Get-Event -sourceidentifier PesterTimer } + { $events = $events.EventIdentifier } + { Remove-Event -EventIdentifier $events } + { $events = Get-Event -ErrorAction SilentlyContinue} + { $events.SourceIdentifier | Should Not Contain "PesterTimer" } + } + + It "Should be able to remove an event given a pipe from Get-Event" { + { Get-Event -sourceidentifier PesterTimer | Remove-Event } + { Get-Event -ErrorAction SilentlyContinue | Should Not Contain "PesterTimer" } + + } + + It "Should NOT remove an event given the whatif flag" { + { Remove-Event -sourceidentifier PesterTimer -whatif } + { $events = Get-Event } + { $events.SourceIdentifier | Should Contain "PesterTimer" } + } + } +} diff --git a/src/pester-tests/Start-Sleep.Tests.ps1 b/src/pester-tests/Start-Sleep.Tests.ps1 new file mode 100644 index 0000000000..43fede7698 --- /dev/null +++ b/src/pester-tests/Start-Sleep.Tests.ps1 @@ -0,0 +1,14 @@ +Describe "Start-Sleep" { + + Context "Validate Start-Sleep works properly" { + It "Should only sleep for at least 3 seconds"{ + $result = Measure-Command { Start-Sleep -s 3 } + $result.Seconds | Should BeGreaterThan 2 + } + + It "Should sleep for at least 3 seconds using the alias" { + $result = Measure-Command { sleep -s 3 } + $result.Seconds | Should BeGreaterThan 2 + } + } +} diff --git a/src/pester-tests/Tee-Object.Tests.ps1 b/src/pester-tests/Tee-Object.Tests.ps1 new file mode 100644 index 0000000000..1fd926b4ac --- /dev/null +++ b/src/pester-tests/Tee-Object.Tests.ps1 @@ -0,0 +1,35 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Tee-Object" { + + Context "Validate Tee-Object is correctly forking output" { + + It "Should return the output to the screen and to the variable" { + $teefile = "$here/assets/testfile.txt" + echo teeobjecttest1 | Tee-Object -variable teeresults + $teeresults | Should Be "teeobjecttest1" + Remove-Item $teefile -ErrorAction SilentlyContinue + } + + It "Should return the output to the screen and to the variable from the alias" { + $teefile = "$here/assets/testfile.txt" + echo teeobjecttest2 | tee -variable teeresults + $teeresults | Should Be "teeobjecttest2" + Remove-Item $teefile -ErrorAction SilentlyContinue + } + + It "Should tee the output to a file" { + $teefile = "$here/assets/testfile.txt" + echo teeobjecttest3 | Tee-Object $teefile + Get-Content $teefile | Should Be "teeobjecttest3" + Remove-Item $teefile -ErrorAction SilentlyContinue + } + + It "Should tee the output to a file using the alias" { + $teefile = "$here/assets/testfile.txt" + echo teeobjecttest4 | tee $teefile + Get-Content $teefile | Should Be "teeobjecttest4" + Remove-item $teefile -ErrorAction SilentlyContinue + } + } +} diff --git a/src/pester-tests/Update-FormatData.Tests.ps1 b/src/pester-tests/Update-FormatData.Tests.ps1 new file mode 100644 index 0000000000..f8c522050c --- /dev/null +++ b/src/pester-tests/Update-FormatData.Tests.ps1 @@ -0,0 +1,15 @@ +Describe "Update-FormatData" { + + Context "Validate Update-FormatData update correctly" { + + It "Should not throw upon reloading previous formatting file" { + { Update-FormatData } | Should Not throw + } + + It "Should validly load formatting data" { + { Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path "outputfile.ps1xml" } + { Update-FormatData -prependPath "outputfile.ps1xml" | Should Not throw } + { Remove-Item "outputfile.ps1xml" -ErrorAction SilentlyContinue } + } + } +} diff --git a/src/pester-tests/Update-TypeData.Tests.ps1 b/src/pester-tests/Update-TypeData.Tests.ps1 new file mode 100644 index 0000000000..611e88d151 --- /dev/null +++ b/src/pester-tests/Update-TypeData.Tests.ps1 @@ -0,0 +1,15 @@ +Describe "Update-TypeData" { + + Context "Validate Update-Type updates correctly" { + + It "Should not throw upon reloading previous formatting file" { + { Update-TypeData } | Should Not throw + } + + It "Should validly load formatting data" { + { Get-TypeData -typename System.Diagnostics.Process | Export-TypeData -Path "outputfile.ps1xml" } + { Update-TypeData -prependPath "outputfile.ps1xml" | Should Not throw } + { Remove-Item "outputfile.ps1xml" -ErrorAction SilentlyContinue } + } + } +} diff --git a/src/pester-tests/Wait-Event.Tests.ps1 b/src/pester-tests/Wait-Event.Tests.ps1 new file mode 100644 index 0000000000..99cbefee15 --- /dev/null +++ b/src/pester-tests/Wait-Event.Tests.ps1 @@ -0,0 +1,9 @@ +Describe "Wait-Event" { + + Context "Validate Wait-Event is waiting for events" { + It "Should verify Wait-Event is waiting for at least a second" { + $waiteventtime = Measure-Command { Wait-Event -timeout 1 } + $waiteventtime.Seconds | Should BeGreaterThan 0 + } + } +} diff --git a/src/pester-tests/assets/pesteralias.txt b/src/pester-tests/assets/pesteralias.txt new file mode 100755 index 0000000000..e375d15fec Binary files /dev/null and b/src/pester-tests/assets/pesteralias.txt differ