Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1
T
Steve Lee c1c5344a88 Update copyright and license headers (#6134)
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files.

Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks.

Separate PR coming to update contribution document for new source files: #6140

Manually reviewed each change.

Fix #6073
2018-02-13 09:23:53 -08:00

39 lines
1.6 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Event Subscriber Tests" -tags "CI" {
BeforeEach {
Get-EventSubscriber | Unregister-Event
}
AfterEach {
Get-EventSubscriber | Unregister-Event
}
# can't let this case to work
It "Register an event with no action, trigger it and wait for it to be raised." -Pending:$true{
Get-EventSubscriber | should BeNullOrEmpty
$messageData = new-object psobject
$job = Start-Job { Start-Sleep -Seconds 5; 1..5 }
$eventtest = Register-ObjectEvent $job -EventName StateChanged -SourceIdentifier EventSIDTest -Action {} -MessageData $messageData
new-event EventSIDTest
wait-event EventSIDTest
$eventdata = get-event EventSIDTest
$eventdata.MessageData | should Be $messageData
remove-event EventSIDTest
Unregister-Event EventSIDTest
Get-EventSubscriber | should BeNullOrEmpty
}
It "Access a global variable from an event action." {
Get-EventSubscriber | should BeNullOrEmpty
set-variable incomingGlobal -scope global -value globVarValue
$eventtest = register-engineevent -SourceIdentifier foo -Action {set-variable -scope global -name aglobalvariable -value $incomingGlobal}
new-event foo
$getvar = get-variable aglobalvariable -scope global
$getvar.Name | should Be aglobalvariable
$getvar.Value | should Be globVarValue
Unregister-Event foo
Get-EventSubscriber | should BeNullOrEmpty
}
}