Merge pull request 297 from dev/alexjopester into develop

Merge dev/alexjopester to develop
This commit is contained in:
Andy Schwartzmeyer
2015-11-20 04:30:24 +00:00
14 changed files with 294 additions and 0 deletions
+33
View File
@@ -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 }
}
}
}
@@ -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
}
}
}
+27
View File
@@ -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"
}
}
}
@@ -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
}
}
}
@@ -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
}
}
}
@@ -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
}
}
}
@@ -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
}
}
}
+38
View File
@@ -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" }
}
}
}
+14
View File
@@ -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
}
}
}
+35
View File
@@ -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
}
}
}
@@ -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 }
}
}
}
@@ -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 }
}
}
}
+9
View File
@@ -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
}
}
}
Binary file not shown.