Skip to content

Commit 28eee62

Browse files
committed
Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
1 parent 3d2d710 commit 28eee62

35 files changed

Lines changed: 159 additions & 193 deletions

test/powershell/Host/ConsoleHost.Tests.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ Describe 'minishell for native executables' -Tag 'CI' {
1616

1717
It 'gets a hashtable object from minishell' {
1818
$output = & $powershell -noprofile { @{'a' = 'b'} }
19-
($output | measure).Count | Should Be 1
20-
($output.GetType().Name) | Should Be 'Hashtable'
19+
($output | Measure-Object).Count | Should Be 1
20+
$output | Should BeOfType 'Hashtable'
2121
$output['a'] | Should Be 'b'
2222
}
2323

2424
It 'gets the error stream from minishell' {
2525
$output = & $powershell -noprofile { Write-Error 'foo' } 2>&1
26-
($output | measure).Count | Should Be 1
27-
($output.GetType().Name) | Should Be 'ErrorRecord'
26+
($output | Measure-Object).Count | Should Be 1
27+
$output | Should BeOfType 'System.Management.Automation.ErrorRecord'
2828
$output.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException'
2929
}
3030

3131
It 'gets the information stream from minishell' {
3232
$output = & $powershell -noprofile { Write-Information 'foo' } 6>&1
33-
($output.GetType().Name) | Should Be 'InformationRecord'
33+
($output | Measure-Object).Count | Should Be 1
34+
$output | Should BeOfType 'System.Management.Automation.InformationRecord'
3435
$output | Should Be 'foo'
3536
}
3637
}
@@ -150,7 +151,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
150151
}
151152
foreach ($x in "--help", "-help", "-h", "-?", "--he", "-hel", "--HELP", "-hEl") {
152153
It "Accepts '$x' as a parameter for help" {
153-
& $powershell -noprofile $x | ?{ $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
154+
& $powershell -noprofile $x | Where-Object { $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
154155
}
155156
}
156157

test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Describe 'Classes inheritance syntax' -Tags "CI" {
7474
[A]::b = "bla"
7575
throw "No Exception!"
7676
} catch {
77-
$_.Exception | Should BeOfType SetValueInvocationException
77+
$_.Exception | Should BeOfType 'System.Management.Automation.SetValueInvocationException'
7878
}
7979
}
8080
}
@@ -419,7 +419,7 @@ Describe 'Classes inheritance ctors' -Tags "CI" {
419419
[B]::new(101)
420420
throw "No Exception!"
421421
} catch {
422-
$_.Exception | Should BeOfType MethodException
422+
$_.Exception | Should BeOfType "System.Management.Automation.MethodException"
423423
}
424424
}
425425

test/powershell/Language/Parser/Ast.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Describe "The SafeGetValue method on AST returns safe values" -Tags "CI" {
66
@{ one = 1 }
77
}.ast.Find({$args[0] -is $HashtableAstType}, $true)
88
$HtAst | Should Not BeNullOrEmpty
9-
$HtAst.SafeGetValue().GetType().Name | Should be Hashtable
9+
$HtAst.SafeGetValue() | Should BeOfType "Hashtable"
1010
}
1111
It "An Array is returned from a LiteralArrayAst" {
1212
$ArrayAstType = [ArrayLiteralAst]
1313
$ArrayAst = {
1414
@( 1,2,3,4)
1515
}.ast.Find({$args[0] -is $ArrayAstType}, $true)
1616
$ArrayAst | Should Not BeNullOrEmpty
17-
$ArrayAst.SafeGetValue().GetType().Name | Should be "Object[]"
17+
,$ArrayAst.SafeGetValue() | Should BeOfType "Object[]"
1818
}
1919
It "The proper error is returned when a variable is referenced" {
2020
$ast = { $a }.Ast.Find({$args[0] -is "VariableExpressionAst"},$true)

test/powershell/Language/Parser/BNotOperator.Tests.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ Describe "bnot on enums" -Tags "CI" {
3939
It "max - 1" {
4040
$res = -bnot $enumType::MaxMinus1
4141
$res | Should Be $enumType::MinPlus1
42-
$res.GetType() | Should Be $enumType
42+
$res | Should BeOfType $enumType
4343
}
4444

4545
It "min + 1" {
4646
$res = -bnot $enumType::MinPlus1
4747
$res | Should Be $enumType::MaxMinus1
48-
$res.GetType() | Should Be $enumType
48+
$res | Should BeOfType $enumType
4949
}
5050

5151
It "Max" {
5252
$res = -bnot $enumType::Max
5353
$res | Should Be $enumType::Min
54-
$res.GetType() | Should Be $enumType
54+
$res | Should BeOfType $enumType
5555
}
5656

5757
It "Min" {
5858
$res = -bnot $enumType::Min
5959
$res | Should Be $enumType::Max
60-
$res.GetType() | Should Be $enumType
60+
$res | Should BeOfType $enumType
6161
}
6262
}
6363
}
@@ -90,51 +90,51 @@ Describe "bnot on integral types" -Tags "CI" {
9090
It "max - 1" {
9191
$res = -bnot $maxMinus1
9292
$res | Should Be (-bnot [int]$maxMinus1)
93-
$res.GetType() | Should Be $expectedResultType
93+
$res | Should BeOfType $expectedResultType
9494
}
9595

9696
It "min + 1" {
9797
$res = -bnot $minPlus1
9898
$res | Should Be (-bnot [int]$minPlus1)
99-
$res.GetType() | Should Be $expectedResultType
99+
$res | Should BeOfType $expectedResultType
100100
}
101101

102102
It "max" {
103103
$res = -bnot $max
104104
$res | Should Be (-bnot [int]$max)
105-
$res.GetType() | Should Be $expectedResultType
105+
$res | Should BeOfType $expectedResultType
106106
}
107107

108108
It "min" {
109109
$res = -bnot $min
110110
$res | Should Be (-bnot [int]$min)
111-
$res.GetType() | Should Be $expectedResultType
111+
$res | Should BeOfType $expectedResultType
112112
}
113113
return
114114
}
115115

116116
It "max - 1" {
117117
$res = -bnot $maxMinus1
118118
$res | Should Be $minPlus1
119-
$res.GetType() | Should Be $expectedResultType
119+
$res | Should BeOfType $expectedResultType
120120
}
121121

122122
It "min + 1" {
123123
$res = -bnot $minPlus1
124124
$res | Should Be $maxMinus1
125-
$res.GetType() | Should Be $expectedResultType
125+
$res | Should BeOfType $expectedResultType
126126
}
127127

128128
It "max" {
129129
$res = -bnot $max
130130
$res | Should Be $min
131-
$res.GetType() | Should Be $expectedResultType
131+
$res | Should BeOfType $expectedResultType
132132
}
133133

134134
It "min" {
135135
$res = -bnot $min
136136
$res | Should Be $max
137-
$res.GetType() | Should Be $expectedResultType
137+
$res | Should BeOfType $expectedResultType
138138
}
139139
}
140140
}

test/powershell/Language/Scripting/ActionPreference.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
It '$err.Count' { $err.Count | Should Be 1 }
2121
It '$err[0] should not be $null' { $err[0] | Should Not Be $null }
22-
It '$err[0].GetType().Name' { $err[0].GetType().Name | Should Be ActionPreferenceStopException }
22+
It '$err[0].GetType().Name' { $err[0] | Should BeOfType "System.Management.Automation.ActionPreferenceStopException" }
2323
It '$err[0].ErrorRecord' { $err[0].ErrorRecord | Should not BeNullOrEmpty }
24-
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception.GetType().Name | Should Be ItemNotFoundException }
24+
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception | Should BeOfType "System.Management.Automation.ItemNotFoundException" }
2525
}
2626

2727
It 'ActionPreference Ignore Works' {

test/powershell/Language/Scripting/I18n.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Describe 'Testing of script internationalization' -Tags "CI" {
5353
import-localizedData mydata -uiculture nl-NL -ea SilentlyContinue -ev ev
5454

5555
$ev | Should Not BeNullOrEmpty
56-
$ev[0].Exception.GetType() | Should Be System.Management.Automation.PSInvalidOperationException
56+
$ev[0].Exception | Should BeOfType "System.Management.Automation.PSInvalidOperationException"
5757
}
5858

5959
It 'Import different file name is done correctly' {
@@ -112,7 +112,7 @@ Describe 'Testing of script internationalization' -Tags "CI" {
112112
}
113113

114114
$script:exception.exception | Should Not BeNullOrEmpty
115-
$script:exception.exception.gettype() | Should Be System.management.automation.psinvalidoperationexception
115+
$script:exception.exception | Should BeOfType System.management.automation.psinvalidoperationexception
116116
}
117117

118118
It 'Import if psd1 file is done correctly' {

test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" {
301301
It '$get_item_err.count and $get_item_err[0].exception' {
302302
$get_item_err.count | Should Be 1
303303
$get_item_err[0].exception | Should Not BeNullOrEmpty
304-
$get_item_err[0].exception.GetType() | Should Be 'System.Management.Automation.ItemNotFoundException'
304+
$get_item_err[0].exception | Should BeOftype 'System.Management.Automation.ItemNotFoundException'
305305
}
306306
}
307307

test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ try {
13331333

13341334
It "(special case) Test for property = OsLocalDateTime" -Pending:$true {
13351335
$computerInfo = Get-ComputerInfo
1336-
$computerInfo.GetType().Name | Should Be "ComputerInfo"
1336+
$computerInfo | Should BeOfType "ComputerInfo"
13371337
}
13381338

13391339
It "(special case) Test for property = OsMaxNumberOfProcesses" {

test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ Describe "Get-Content" -Tags "CI" {
3030
It "Should return an Object when listing only a single line and the correct information from a file" {
3131
$content = (Get-Content -Path $testPath)
3232
$content | Should Be $testString
33-
$content.GetType().BaseType.Name | Should Be "Object"
33+
$content.Count | Should Be 1
34+
$content | Should BeOfType "System.String"
3435
}
3536
It "Should deliver an array object when listing a file with multiple lines and the correct information from a file" {
3637
$content = (Get-Content -Path $testPath2)
3738
@(Compare-Object $content $testString2.Split($nl) -SyncWindow 0).Length | Should Be 0
38-
$content.GetType().BaseType.Name | Should Be "Array"
39+
,$content | Should BeOfType "System.Array"
3940
}
4041
It "Should be able to return a specific line from a file" {
4142
(Get-Content -Path $testPath2)[1] | Should be $secondline

test/powershell/Modules/Microsoft.PowerShell.Management/Get-EventLog.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
It "should return an array of eventlogs objects when called with -AsString parameter" -Pending:($True) {
1414
{$result=Get-EventLog -AsString -ea stop} | Should Not Throw
1515
$result | Should Not BeNullOrEmpty
16-
$result.GetType().BaseType.Name | Should Be "Array"
16+
,$result | Should BeOfType "System.Array"
1717
$result -eq "Application" | Should Be "Application"
1818
$result.Count -ge 3 | Should Be $true
1919
}
2020
It "should return a list of eventlog objects when called with -List parameter" -Pending:($True) {
2121
{$result=Get-EventLog -List -ea stop} | Should Not Throw
2222
$result | Should Not BeNullOrEmpty
23-
$result.GetType().BaseType.Name | Should Be "array"
24-
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
23+
,$result | Should BeOfType "System.Array"
24+
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
2525
$logs -eq "System" | Should Be "System"
2626
$logs.Count -ge 3 | Should Be $true
2727
}
2828
It "should be able to Get-EventLog -LogName Application -Newest 100" -Pending:($True) {
2929
{$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw
3030
$result | Should Not BeNullOrEmpty
3131
$result.Length -le 100 | Should Be $true
32-
$result[0].GetType().Name | Should Be "EventLogEntry"
32+
$result[0] | Should BeOfType "EventLogEntry"
3333
}
3434
It "should throw 'AmbiguousParameterSetException' when called with both -LogName and -List parameters" -Pending:($True) {
3535
try {Get-EventLog -LogName System -List -ea stop; Throw "Previous statement unexpectedly succeeded..."

0 commit comments

Comments
 (0)