Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1
T
Ilya 409ab7443f Fix GetType() bad pattern and related issues in tests (#3134)
* Fix GetType() bad pattern and related issues in tests

$var.GetType() can raise an exception in tests so we should check $var
before make the call. A large part of the tests does not make this
check.
I start with searching ".GetType()" but discovered many related issues
in tests (reduntant and unneeded tests, "throw" bad pattens, bugs,
formattings (sorry!) and so on) - I had to fix them too.

* Fix after code review
* Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
2017-02-15 16:40:51 -08:00

38 lines
1.6 KiB
PowerShell

Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') {
It "Should support -IncludeUserName" {
(Get-Process powershell -IncludeUserName | Select-Object -First 1).UserName | Should Match $env:USERNAME
}
}
Describe "Get-Process" -Tags "CI" {
# These tests are no good, please replace!
BeforeAll {
$ps = Get-Process
}
It "Should return a type of Object[] for Get-Process cmdlet" -Pending:$IsOSX {
,$ps | Should BeOfType "System.Object[]"
}
It "Should have not empty Name flags set for Get-Process object" -Pending:$IsOSX {
$ps | foreach-object { $_.Name | Should Not BeNullOrEmpty }
}
}
Describe "Get-Process Formatting" -Tags "Feature" {
It "Should not have Handle in table format header" {
$types = "System.Diagnostics.Process","System.Diagnostics.Process#IncludeUserName"
foreach ($type in $types)
{
$formatData = Get-FormatData -TypeName $type -PowerShellVersion $PSVersionTable.PSVersion
$tableControls = $formatData.FormatViewDefinition | Where-Object {$_.Control -is "System.Management.Automation.TableControl"}
foreach ($tableControl in $tableControls)
{
$tableControl.Control.Headers.Label -match "Handle*" | Should BeNullOrEmpty
# verify that rows without headers isn't the handlecount (as PowerShell will create a header that matches the property name)
$tableControl.Control.Rows.Columns.DisplayEntry.Value -eq "HandleCount" | Should BeNullOrEmpty
}
}
}
}