From 72cca702e8fb7942fba1363633f107a3272b2afe Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 28 Jul 2017 15:21:14 -0700 Subject: [PATCH 1/6] New-WinEvent tests --- .../New-WinEvent.Tests.ps1 | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 new file mode 100644 index 00000000000..d5259cb6e5b --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -0,0 +1,33 @@ +Describe 'New-WinEvent' -Tags "CI" { + + Context "New-WinEvent tests" { + + It 'Simple New-WinEvent' -Skip:(-not $IsWindows) { + New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload + $filter = @{ ProviderName = 'Microsoft-Windows-PowerShell'; Id = 40962} + (Get-WinEvent -filterHashtable $filter).Count -gt 0 | Should be $true + } + + It 'No provider found error' -Skip:(-not $IsWindows) { + { New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorID 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand' + } + + It 'EmptyProviderName error' -Skip:(-not $IsWindows) { + { New-WinEvent -ProviderName $null -Id 0 } | ShouldBeErrorID 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewWinEventCommand' + } + + It 'IncorrectEventId error' -Skip:(-not $IsWindows) { + { New-WinEvent Microsoft-Windows-PowerShell -Id 999999 } | ShouldBeErrorID 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + } + + It 'IncorrectEventVersion error' -Skip:(-not $IsWindows) { + { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 99 } | ShouldBeErrorID 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + } + + It 'PayloadMismatch error' -Skip:(-not $IsWindows) { + $logPath = join-path $TestDrive 'testlog1.txt' + New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 32868 *> $logPath # this will print the warning with expected event template to the file + Get-Content $logPath -Raw | Should Match 'data name="FragmentPayload"' + } + } +} From 6411500212008f58935b62356fcd0fb4d87f411f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 31 Jul 2017 16:19:58 -0700 Subject: [PATCH 2/6] PR feedback --- .../New-WinEvent.Tests.ps1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 index d5259cb6e5b..f09200dcd47 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -5,28 +5,29 @@ Describe 'New-WinEvent' -Tags "CI" { It 'Simple New-WinEvent' -Skip:(-not $IsWindows) { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload $filter = @{ ProviderName = 'Microsoft-Windows-PowerShell'; Id = 40962} - (Get-WinEvent -filterHashtable $filter).Count -gt 0 | Should be $true + (Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0 } It 'No provider found error' -Skip:(-not $IsWindows) { - { New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorID 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand' + { New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorId 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand' } It 'EmptyProviderName error' -Skip:(-not $IsWindows) { - { New-WinEvent -ProviderName $null -Id 0 } | ShouldBeErrorID 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewWinEventCommand' + { New-WinEvent -ProviderName $null -Id 0 } | ShouldBeErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewWinEventCommand' } It 'IncorrectEventId error' -Skip:(-not $IsWindows) { - { New-WinEvent Microsoft-Windows-PowerShell -Id 999999 } | ShouldBeErrorID 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + { New-WinEvent Microsoft-Windows-PowerShell -Id 999999 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' } It 'IncorrectEventVersion error' -Skip:(-not $IsWindows) { - { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 99 } | ShouldBeErrorID 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 99 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' } It 'PayloadMismatch error' -Skip:(-not $IsWindows) { $logPath = join-path $TestDrive 'testlog1.txt' - New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 32868 *> $logPath # this will print the warning with expected event template to the file + # this will print the warning with expected event template to the file + New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 32868 *> $logPath Get-Content $logPath -Raw | Should Match 'data name="FragmentPayload"' } } From 7da758f99efec41b75fe3cb1ac428cf712d9ddb5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 31 Jul 2017 16:35:37 -0700 Subject: [PATCH 3/6] PR feedback 2 --- .../New-WinEvent.Tests.ps1 | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 index f09200dcd47..b1133075830 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -2,29 +2,40 @@ Describe 'New-WinEvent' -Tags "CI" { Context "New-WinEvent tests" { - It 'Simple New-WinEvent' -Skip:(-not $IsWindows) { + BeforeAll { + $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() + if ( ! $IsWindows ) { + $PSDefaultParameterValues["it:skip"] = $true + } + } + + AfterAll { + $global:PSDefaultParameterValues = $originalDefaultParameterValues + } + + It 'Simple New-WinEvent' { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload $filter = @{ ProviderName = 'Microsoft-Windows-PowerShell'; Id = 40962} (Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0 } - It 'No provider found error' -Skip:(-not $IsWindows) { + It 'No provider found error' { { New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorId 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand' } - It 'EmptyProviderName error' -Skip:(-not $IsWindows) { + It 'EmptyProviderName error' { { New-WinEvent -ProviderName $null -Id 0 } | ShouldBeErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewWinEventCommand' } - It 'IncorrectEventId error' -Skip:(-not $IsWindows) { + It 'IncorrectEventId error' { { New-WinEvent Microsoft-Windows-PowerShell -Id 999999 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' } - It 'IncorrectEventVersion error' -Skip:(-not $IsWindows) { + It 'IncorrectEventVersion error' { { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 99 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' } - It 'PayloadMismatch error' -Skip:(-not $IsWindows) { + It 'PayloadMismatch error' { $logPath = join-path $TestDrive 'testlog1.txt' # this will print the warning with expected event template to the file New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 32868 *> $logPath From fe2df53a2068071d81658333da744b863ba92cd5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 1 Aug 2017 12:15:51 -0700 Subject: [PATCH 4/6] PR feedback 3 --- .../New-WinEvent.Tests.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 index b1133075830..b1ebb83d854 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -7,6 +7,10 @@ Describe 'New-WinEvent' -Tags "CI" { if ( ! $IsWindows ) { $PSDefaultParameterValues["it:skip"] = $true } + + $ProviderName = 'Microsoft-Windows-PowerShell' + $SimpleEventId = 40962 + $ComplexEventId = 32868 } AfterAll { @@ -14,8 +18,8 @@ Describe 'New-WinEvent' -Tags "CI" { } It 'Simple New-WinEvent' { - New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload - $filter = @{ ProviderName = 'Microsoft-Windows-PowerShell'; Id = 40962} + New-WinEvent -ProviderName $ProviderName -Id $SimpleEventId -Version 1 # simple event without any payload + $filter = @{ ProviderName = $ProviderName; Id = $SimpleEventId} (Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0 } @@ -28,17 +32,17 @@ Describe 'New-WinEvent' -Tags "CI" { } It 'IncorrectEventId error' { - { New-WinEvent Microsoft-Windows-PowerShell -Id 999999 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + { New-WinEvent $ProviderName -Id 999999 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' } It 'IncorrectEventVersion error' { - { New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 99 } | ShouldBeErrorId 'Microsoft.PowerShell.Commands.EventWriteException,Microsoft.PowerShell.Commands.NewWinEventCommand' + { 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 Microsoft-Windows-PowerShell -Id 32868 *> $logPath + New-WinEvent -ProviderName $ProviderName -Id $ComplexEventId *> $logPath Get-Content $logPath -Raw | Should Match 'data name="FragmentPayload"' } } From b3d408c4e60d4ffe5dee71ab4582b2175a36dce6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 1 Aug 2017 12:24:07 -0700 Subject: [PATCH 5/6] PR feedback 4 --- .../Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 index b1ebb83d854..c2bbed31796 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -18,7 +18,8 @@ Describe 'New-WinEvent' -Tags "CI" { } It 'Simple New-WinEvent' { - New-WinEvent -ProviderName $ProviderName -Id $SimpleEventId -Version 1 # simple event without any payload + # simple event without any payload + New-WinEvent -ProviderName $ProviderName -Id $SimpleEventId -Version 1 $filter = @{ ProviderName = $ProviderName; Id = $SimpleEventId} (Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0 } From 6d8d616b515d6ab4f02195c8ce1ea33fa9e08e80 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 4 Aug 2017 11:58:35 -0700 Subject: [PATCH 6/6] PR feedback 5 --- .../Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 index c2bbed31796..f74d0235a0c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/New-WinEvent.Tests.ps1 @@ -17,8 +17,7 @@ Describe 'New-WinEvent' -Tags "CI" { $global:PSDefaultParameterValues = $originalDefaultParameterValues } - It 'Simple New-WinEvent' { - # simple event without any payload + 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