Tests for New-WinEvent (#4384)

* New-WinEvent tests

* PR feedback

* PR feedback 2

* PR feedback 3

* PR feedback 4

* PR feedback 5
This commit is contained in:
Andrew 2017-08-07 14:24:12 -07:00 committed by Aditya Patwardhan
parent 24cf216607
commit 0b7451bda3

View File

@ -0,0 +1,49 @@
Describe 'New-WinEvent' -Tags "CI" {
Context "New-WinEvent tests" {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if ( ! $IsWindows ) {
$PSDefaultParameterValues["it:skip"] = $true
}
$ProviderName = 'Microsoft-Windows-PowerShell'
$SimpleEventId = 40962
$ComplexEventId = 32868
}
AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
It 'Simple New-WinEvent without any payload' {
New-WinEvent -ProviderName $ProviderName -Id $SimpleEventId -Version 1
$filter = @{ ProviderName = $ProviderName; Id = $SimpleEventId}
(Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0
}
It 'No provider found error' {
{ New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorId 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand'
}
It 'EmptyProviderName error' {
{ New-WinEvent -ProviderName $null -Id 0 } | ShouldBeErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewWinEventCommand'
}
It 'IncorrectEventId error' {
{ New-WinEvent $ProviderName -Id 999999 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand'
}
It 'IncorrectEventVersion error' {
{ New-WinEvent -ProviderName $ProviderName -Id $SimpleEventId -Version 99 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand'
}
It 'PayloadMismatch error' {
$logPath = join-path $TestDrive 'testlog1.txt'
# this will print the warning with expected event template to the file
New-WinEvent -ProviderName $ProviderName -Id $ComplexEventId *> $logPath
Get-Content $logPath -Raw | Should Match 'data name="FragmentPayload"'
}
}
}