From 7aa2951a6233570b40391a32c70fb4da7d0a8095 Mon Sep 17 00:00:00 2001 From: sethvs Date: Sun, 8 Apr 2018 14:22:03 +0300 Subject: [PATCH 1/2] Fix Clear-EventLog.Tests.ps1 --- .../Clear-EventLog.Tests.ps1 | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 index 2cab4021103..c3229c805ae 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 @@ -13,20 +13,27 @@ Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') { It "should be able to Clear-EventLog" -Pending:($True) { Remove-EventLog -LogName TestLog -ea Ignore - {New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop} | Should -Not -Throw - {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Not -Throw - {$result=Get-EventLog -LogName TestLog} | Should -Not -Throw - ($result.Count) | Should -Be 1 - {Clear-EventLog -LogName TestLog} | Should -Not -Throw - $result=Get-EventLog -LogName TestLog -ea Ignore - ($result.Count) | Should -Be 0 - {Remove-EventLog -LogName TestLog -ErrorAction Stop} | Should -Not -Throw + { New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop } | Should -Not -Throw + { Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Not -Throw + { Get-EventLog -LogName TestLog } | Should -Not -Throw + $result = Get-EventLog -LogName TestLog + $result.Count | Should -Be 1 + { Clear-EventLog -LogName TestLog } | Should -Not -Throw + $result = Get-EventLog -LogName TestLog -ErrorAction Ignore + $result.Count | Should -Be 0 + { Remove-EventLog -LogName TestLog -ErrorAction Stop } | Should -Not -Throw } - It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Pending:($True) { - Remove-EventLog -LogName MissingTestLog -ea Ignore - { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand" + + It "should throw 'The Log name 'MissingTestLog' does not exist' exception message when asked to clear a log that does not exist" -Pending:($True) { + Remove-EventLog -LogName MissingTestLog -ErrorAction Ignore + { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExpectedMessage 'The Log name "MissingTestLog" does not exist' } + It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True) { + { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExceptionType "System.InvalidOperationException" + } + + It "should throw 'Microsoft.PowerShell.Commands.ClearEventLogCommand' ErrorId when asked to clear a log that does not exist" -Pending:($True) { { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand" } } From 41b3b2e6d2eda1c8983f5ff34f3ebd8217c3a2fb Mon Sep 17 00:00:00 2001 From: sethvs Date: Mon, 9 Apr 2018 18:02:47 +0300 Subject: [PATCH 2/2] Remove -ExpectedMessage test. --- .../Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 index c3229c805ae..df5407f1677 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 @@ -24,11 +24,6 @@ Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') { { Remove-EventLog -LogName TestLog -ErrorAction Stop } | Should -Not -Throw } - It "should throw 'The Log name 'MissingTestLog' does not exist' exception message when asked to clear a log that does not exist" -Pending:($True) { - Remove-EventLog -LogName MissingTestLog -ErrorAction Ignore - { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExpectedMessage 'The Log name "MissingTestLog" does not exist' - } - It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True) { { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExceptionType "System.InvalidOperationException" }