mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Unify pester test syntax for the arguments of -BeOfType (#11558)
This commit is contained in:
@@ -52,7 +52,7 @@ Describe "Basic Alias Provider Tests" -Tags "CI" {
|
||||
|
||||
It "Test executing the new alias" {
|
||||
$result = Invoke-Expression $testAliasName
|
||||
$result | Should -BeOfType [DateTime]
|
||||
$result | Should -BeOfType DateTime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -289,8 +289,8 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
}
|
||||
|
||||
It "Can get an appx package item" -Skip:$skipTest {
|
||||
Get-Item $pkgDir\Calculator.exe -ErrorAction Stop | Should -BeOfType [System.IO.FileInfo]
|
||||
Get-Item -Path $pkgDir -ErrorAction Stop | Should -BeOfType [System.IO.DirectoryInfo]
|
||||
Get-Item $pkgDir\Calculator.exe -ErrorAction Stop | Should -BeOfType System.IO.FileInfo
|
||||
Get-Item -Path $pkgDir -ErrorAction Stop | Should -BeOfType System.IO.DirectoryInfo
|
||||
Get-ChildItem -Path $pkgDir -ErrorAction Stop | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ Describe 'FileSystem Provider Formatting' -Tag "CI","RequireAdminOnWindows" {
|
||||
New-Item -Path $modeTestDir -Name $itemName -ItemType $itemType
|
||||
}
|
||||
|
||||
$item | Should -BeOfType "System.IO.FileSystemInfo"
|
||||
$item | Should -BeOfType System.IO.FileSystemInfo
|
||||
|
||||
$actualMode = [Microsoft.PowerShell.Commands.FileSystemProvider]::Mode($item)
|
||||
$actualMode | Should -BeExactly $expectedMode
|
||||
|
||||
+11
-11
@@ -1008,7 +1008,7 @@ try {
|
||||
|
||||
It "Verify type returned by Get-ComputerInfo" {
|
||||
$computerInfo = Get-ComputerInfo
|
||||
$computerInfo | Should -BeOfType 'Microsoft.PowerShell.Commands.ComputerInfo'
|
||||
$computerInfo | Should -BeOfType Microsoft.PowerShell.Commands.ComputerInfo
|
||||
}
|
||||
|
||||
It "Verify progress records in Get-ComputerInfo" {
|
||||
@@ -1075,7 +1075,7 @@ try {
|
||||
$expectedProperties = @("BiosBIOSVersion")
|
||||
$propertyFilter = "BiosBIOSVersion"
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be 1
|
||||
$computerInfoWithProp.$propertyFilter | Should -Be $expected.$propertyFilter
|
||||
}
|
||||
@@ -1088,7 +1088,7 @@ try {
|
||||
$expectedProperties = @("BiosBIOSVersion","BiosBuildNumber","BiosCaption")
|
||||
$propertyFilter = @("BiosBIOSVersion","BiosBuildNumber","BiosCaption")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be 3
|
||||
foreach($property in $propertyFilter) {
|
||||
$ComputerInfoWithProp.$property | Should -Be $Expected.$property
|
||||
@@ -1103,7 +1103,7 @@ try {
|
||||
$expectedProperties = $null
|
||||
$propertyFilter = @("BiosBIOSVersionXXX")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be 0
|
||||
}
|
||||
|
||||
@@ -1115,7 +1115,7 @@ try {
|
||||
$expectedProperties = $null
|
||||
$propertyFilter = @("BiosBIOSVersionXXX","InvalidProperty1","InvalidProperty2","InvalidProperty3")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be 0
|
||||
}
|
||||
|
||||
@@ -1127,7 +1127,7 @@ try {
|
||||
$expectedProperties = @("BiosCodeSet","BiosCurrentLanguage","BiosDescription")
|
||||
$propertyFilter = @("InvalidProperty1","BiosCodeSet","BiosCurrentLanguage","BiosDescription")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
$realProperties = $propertyFilter | Where-Object { $_ -notmatch "^InvalidProperty[0-9]+" }
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count
|
||||
foreach ( $property in $realProperties )
|
||||
@@ -1144,7 +1144,7 @@ try {
|
||||
$expectedProperties = @("BiosCodeSet","BiosCurrentLanguage","BiosDescription")
|
||||
$propertyFilter = @("BiosCodeSet","InvalidProperty1","BiosCurrentLanguage","BiosDescription","InvalidProperty2")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
$realProperties = $propertyFilter | Where-Object { $_ -notmatch "^InvalidProperty[0-9]+" }
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count
|
||||
foreach ( $property in $realProperties )
|
||||
@@ -1161,7 +1161,7 @@ try {
|
||||
$expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage")
|
||||
$propertyFilter = @("BiosC*")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count
|
||||
foreach ( $property in $expectedProperties )
|
||||
{
|
||||
@@ -1177,7 +1177,7 @@ try {
|
||||
$expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage","CsCaption")
|
||||
$propertyFilter = @("BiosC*","CsCaption")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count
|
||||
foreach ( $property in $expectedProperties )
|
||||
{
|
||||
@@ -1193,7 +1193,7 @@ try {
|
||||
$expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage","CsCaption")
|
||||
$propertyFilter = @("CsCaption","InvalidProperty1","BiosC*")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count
|
||||
foreach ( $property in $expectedProperties )
|
||||
{
|
||||
@@ -1209,7 +1209,7 @@ try {
|
||||
$expectedProperties = $null
|
||||
$propertyFilter = @("BiosBIOSVersionX*")
|
||||
$computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter
|
||||
$computerInfoWithProp | Should -BeOfType [pscustomobject]
|
||||
$computerInfoWithProp | Should -BeOfType pscustomobject
|
||||
@($computerInfoWithProp.psobject.properties).count | Should -Be 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ Describe "Get-Content" -Tags "CI" {
|
||||
$content = (Get-Content -Path $testPath)
|
||||
$content | Should -BeExactly $testString
|
||||
$content.Count | Should -Be 1
|
||||
$content | Should -BeOfType "System.String"
|
||||
$content | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Should deliver an array object when listing a file with multiple lines and the correct information from a file" {
|
||||
$content = (Get-Content -Path $testPath2)
|
||||
@(Compare-Object $content $testString2.Split($nl) -SyncWindow 0).Length | Should -Be 0
|
||||
,$content | Should -BeOfType "System.Array"
|
||||
,$content | Should -BeOfType System.Array
|
||||
}
|
||||
|
||||
It "Should be able to return a specific line from a file" {
|
||||
@@ -119,7 +119,7 @@ baz
|
||||
$expected = 'foo'
|
||||
|
||||
$actual = Get-Content -Path $testPath -Tail $tailCount -Encoding $encodingName
|
||||
$actual | Should -BeOfType [string]
|
||||
$actual | Should -BeOfType string
|
||||
$actual.Length | Should -Be $tailCount
|
||||
$actual[0] | Should -BeExactly $expected
|
||||
}
|
||||
@@ -224,7 +224,7 @@ baz
|
||||
Get-Content -Path $testPath | Should -BeExactly $testString
|
||||
Get-Content -Path $testPath -Stream hello | Should -BeExactly "World"
|
||||
$item = Get-Item -Path $testPath -Stream hello
|
||||
$item | Should -BeOfType 'System.Management.Automation.Internal.AlternateStreamData'
|
||||
$item | Should -BeOfType System.Management.Automation.Internal.AlternateStreamData
|
||||
$item.Stream | Should -BeExactly "hello"
|
||||
Clear-Content -Path $testPath -Stream hello
|
||||
Get-Content -Path $testPath -Stream hello | Should -BeNullOrEmpty
|
||||
|
||||
@@ -15,14 +15,14 @@ Describe "Get-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {
|
||||
It "should return an array of eventlogs objects when called with -AsString parameter" -Pending:($true) {
|
||||
{ $result=Get-EventLog -AsString -ErrorAction Stop } | Should -Not -Throw
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
,$result | Should -BeOfType "System.Array"
|
||||
,$result | Should -BeOfType System.Array
|
||||
$result | Should -BeExactly "Application"
|
||||
$result.Count | Should -BeGreaterThan 3
|
||||
}
|
||||
It "should return a list of eventlog objects when called with -List parameter" -Pending:($true) {
|
||||
{ $result=Get-EventLog -List -ErrorAction Stop } | Should -Not -Throw
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
,$result | Should -BeOfType "System.Array"
|
||||
,$result | Should -BeOfType System.Array
|
||||
{$logs=$result | Select-Object -ExpandProperty Log} | Should -Not -Throw
|
||||
$logs | Should -BeExactly "System"
|
||||
$logs.Count | Should -BeGreaterThan 3
|
||||
@@ -31,7 +31,7 @@ Describe "Get-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {
|
||||
{ $result=get-eventlog -LogName Application -Newest 100 -ErrorAction Stop } | Should -Not -Throw
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
$result.Length | Should -BeLessThan 100
|
||||
$result[0] | Should -BeOfType "EventLogEntry"
|
||||
$result[0] | Should -BeOfType EventLogEntry
|
||||
}
|
||||
It "should throw 'AmbiguousParameterSetException' when called with both -LogName and -List parameters" -Pending:($true) {
|
||||
{ Get-EventLog -LogName System -List -ErrorAction Stop } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetEventLogCommand"
|
||||
|
||||
@@ -11,20 +11,20 @@ Describe "Get-Item" -Tags "CI" {
|
||||
}
|
||||
It "Should list all the items in the current working directory when asterisk is used" {
|
||||
$items = Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")
|
||||
,$items | Should -BeOfType 'System.Object[]'
|
||||
,$items | Should -BeOfType System.Object[]
|
||||
}
|
||||
|
||||
It "Should return the name of the current working directory when a dot is used" {
|
||||
$item = Get-Item $PSScriptRoot
|
||||
$item | Should -BeOfType 'System.IO.DirectoryInfo'
|
||||
$item | Should -BeOfType System.IO.DirectoryInfo
|
||||
$item.Name | Should -BeExactly (Split-Path $PSScriptRoot -Leaf)
|
||||
}
|
||||
|
||||
It "Should return the proper Name and BaseType for directory objects vs file system objects" {
|
||||
$rootitem = Get-Item $PSScriptRoot
|
||||
$rootitem | Should -BeOfType 'System.IO.DirectoryInfo'
|
||||
$rootitem | Should -BeOfType System.IO.DirectoryInfo
|
||||
$childitem = (Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1))
|
||||
$childitem | Should -BeOfType 'System.IO.FileInfo'
|
||||
$childitem | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It "Using -literalpath should find no additional files" {
|
||||
@@ -127,7 +127,7 @@ Describe "Get-Item" -Tags "CI" {
|
||||
Context "Registry Provider" {
|
||||
It "Can retrieve an item from registry" -skip:$skipNotWindows {
|
||||
${result} = Get-Item HKLM:/Software
|
||||
${result} | Should -BeOfType "Microsoft.Win32.RegistryKey"
|
||||
${result} | Should -BeOfType Microsoft.Win32.RegistryKey
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ Describe "Get-Process" -Tags "CI" {
|
||||
$idleProcessPid = 0
|
||||
}
|
||||
It "Should return a type of Object[] for Get-Process cmdlet" -Pending:$IsMacOS {
|
||||
,$ps | Should -BeOfType "System.Object[]"
|
||||
,$ps | Should -BeOfType System.Object[]
|
||||
}
|
||||
|
||||
It "Should have not empty Name flags set for Get-Process object" -Pending:$IsMacOS {
|
||||
|
||||
@@ -49,7 +49,7 @@ Describe "Test-Push-Location" -Tags "CI" {
|
||||
}
|
||||
|
||||
It "Should produce a pathinfo object when the passthru parameter is used" {
|
||||
Push-Location .. -PassThru | ForEach-Object { $_ | Should -BeOfType "System.Management.Automation.PathInfo" }
|
||||
Push-Location .. -PassThru | ForEach-Object { $_ | Should -BeOfType System.Management.Automation.PathInfo }
|
||||
}
|
||||
|
||||
# final cleanup
|
||||
|
||||
@@ -61,7 +61,7 @@ Describe "Split-Path" -Tags "CI" {
|
||||
$actual.Count | Should -Be 2
|
||||
$actual[0] | Should -BeExactly $testFile1
|
||||
$actual[1] | Should -BeExactly $testFile2
|
||||
,$actual | Should -BeOfType "System.Array"
|
||||
,$actual | Should -BeOfType System.Array
|
||||
}
|
||||
|
||||
It "Should be able to tell if a given path is an absolute path" {
|
||||
|
||||
@@ -30,14 +30,14 @@ Describe "Test-Connection" -tags "CI" {
|
||||
Where-Object Status -eq 'Success' |
|
||||
Select-Object -First 1
|
||||
|
||||
$result | Should -BeOfType "Microsoft.PowerShell.Commands.TestConnectionCommand+PingStatus"
|
||||
$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingStatus
|
||||
$result.Ping | Should -Be 1
|
||||
$result.Source | Should -BeExactly $hostName
|
||||
$result.Destination | Should -BeExactly $targetName
|
||||
$result.Address | Should -BeIn @($targetAddress, $targetAddressIPv6)
|
||||
$result.Status | Should -BeExactly "Success"
|
||||
$result.Latency | Should -BeOfType "long"
|
||||
$result.Reply | Should -BeOfType "System.Net.NetworkInformation.PingReply"
|
||||
$result.Latency | Should -BeOfType long
|
||||
$result.Reply | Should -BeOfType System.Net.NetworkInformation.PingReply
|
||||
$result.BufferSize | Should -Be 32
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ Describe "Test-Connection" -tags "CI" {
|
||||
It "MTUSizeDetect works" -Pending:($env:__INCONTAINER -eq 1) {
|
||||
$result = Test-Connection $hostName -MtuSize
|
||||
|
||||
$result | Should -BeOfType "Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus"
|
||||
$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus
|
||||
$result.Destination | Should -BeExactly $hostName
|
||||
$result.Status | Should -BeExactly "Success"
|
||||
$result.MtuSize | Should -BeGreaterThan 0
|
||||
@@ -237,7 +237,7 @@ Describe "Test-Connection" -tags "CI" {
|
||||
It "Quiet works" -Pending:($env:__INCONTAINER -eq 1) {
|
||||
$result = Test-Connection $hostName -MtuSize -Quiet
|
||||
|
||||
$result | Should -BeOfType "Int32"
|
||||
$result | Should -BeOfType Int32
|
||||
$result | Should -BeGreaterThan 0
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ Describe "Test-Connection" -tags "CI" {
|
||||
# real address is an ipv4 address, so force IPv4
|
||||
$result = Test-Connection $hostName -TraceRoute -IPv4
|
||||
|
||||
$result[0] | Should -BeOfType "Microsoft.PowerShell.Commands.TestConnectionCommand+TraceStatus"
|
||||
$result[0] | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+TraceStatus
|
||||
$result[0].Source | Should -BeExactly $hostName
|
||||
$result[0].TargetAddress | Should -BeExactly $realAddress
|
||||
$result[0].Target | Should -BeExactly $hostName
|
||||
|
||||
@@ -53,8 +53,8 @@ Describe "Get-Timezone test cases" -Tags "CI" {
|
||||
$list = Get-TimeZone -ListAvailable
|
||||
$list.Count | Should -BeGreaterThan 0
|
||||
|
||||
,$list | Should -BeOfType "Object[]"
|
||||
$list[0] | Should -BeOfType "TimeZoneInfo"
|
||||
,$list | Should -BeOfType Object[]
|
||||
$list[0] | Should -BeOfType TimeZoneInfo
|
||||
}
|
||||
|
||||
## The local time zone could be set to UTC or GMT*. In this case, the .NET API returns the region ID
|
||||
|
||||
Reference in New Issue
Block a user