Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/New-EventLog.Tests.ps1
T
Klaudia Algiz 2df9aac811 Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests (#6682)
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
2018-05-17 14:42:04 -07:00

56 lines
2.9 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "New-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$defaultParamValues = $PSdefaultParameterValues.Clone()
$IsNotSkipped = ($IsWindows -and !$IsCoreCLR)
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
}
AfterAll {
$global:PSDefaultParameterValues = $defaultParamValues
}
BeforeEach {
if ($IsNotSkipped) {
Remove-EventLog -LogName TestLog -ErrorAction Ignore
}
}
It "should be able to create a New-EventLog with a -Source parameter" -Skip:($True) {
{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
$result.Count | Should -Be 1
}
It "should be able to create a New-EventLog with a -ComputerName parameter" -Skip:($True) {
{New-EventLog -LogName TestLog -Source TestSource -ComputerName $env:COMPUTERNAME -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
$result.Count | Should -Be 1
$result.EventID | Should -Be 1
}
It "should be able to create a New-EventLog with a -CategoryResourceFile parameter" -Skip:($True) {
{New-EventLog -LogName TestLog -Source TestSource -CategoryResourceFile "CategoryMessageFile" -ErrorAction Stop} | Should -Not -Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 2 -ErrorAction Stop} | Should -Not -Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should -Be 1
$result.EventID | Should -Be 2
}
It "should be able to create a New-EventLog with a -MessageResourceFile parameter" -Skip:($True) {
{New-EventLog -LogName TestLog -Source TestSource -MessageResourceFile "ResourceMessageFile" -ErrorAction Stop} | Should -Not -Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 3 -ErrorAction Stop} | Should -Not -Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should -Be 1
$result.EventID | Should -Be 3
}
It "should be able to create a New-EventLog with a -ParameterResourceFile parameter" -Skip:($True) {
{New-EventLog -LogName TestLog -Source TestSource -ParameterResourceFile "ParameterMessageFile" -ErrorAction Stop} | Should -Not -Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 4 -ErrorAction Stop} | Should -Not -Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should -Be 1
$result.EventID | Should -Be 4
}
}