forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-EventLog.Tests.ps1
More file actions
31 lines (31 loc) · 2.36 KB
/
Copy pathRemove-EventLog.Tests.ps1
File metadata and controls
31 lines (31 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if ($IsWindows -and !$IsCoreCLR) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
Describe "New-EventLog cmdlet tests" -Tags "CI" {
BeforeEach{
Remove-EventLog -LogName TestLog -ea Ignore
{New-EventLog -LogName TestLog -Source TestSource -ea Stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop} | Should Not Throw
}
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
It "should be able to Remove-EventLog -LogName <string> -ComputerName <string>" -Pending:($True -Or $NonWinAdmin) {
{Remove-EventLog -LogName TestLog -ComputerName $env:COMPUTERNAME -ea Stop} | Should Not Throw
try {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.WriteEventLogCommand"}
try {Get-EventLog -LogName TestLog -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
It "should be able to Remove-EventLog -Source <string> -ComputerName <string>" -Pending:($True -Or $NonWinAdmin) {
{Remove-EventLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea Stop} | Should Not Throw
try {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.WriteEventLogCommand"}
try {Get-EventLog -LogName TestLog -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
}
}