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:
@@ -91,8 +91,8 @@ try {
|
||||
# in a runspace that has not been opened.
|
||||
$err = { $ps.AddScript('1+1').InvokeAsync() } | Should -Throw -ErrorId "InvalidRunspaceStateException" -PassThru
|
||||
|
||||
$err.Exception | Should -BeOfType "System.Management.Automation.MethodInvocationException"
|
||||
$err.Exception.InnerException | Should -BeOfType "System.Management.Automation.Runspaces.InvalidRunspaceStateException"
|
||||
$err.Exception | Should -BeOfType System.Management.Automation.MethodInvocationException
|
||||
$err.Exception.InnerException | Should -BeOfType System.Management.Automation.Runspaces.InvalidRunspaceStateException
|
||||
$err.Exception.InnerException.CurrentState | Should -Be 'BeforeOpen'
|
||||
$err.Exception.InnerException.ExpectedState | Should -Be 'Opened'
|
||||
} finally {
|
||||
|
||||
@@ -45,7 +45,7 @@ Describe "Command Discovery tests" -Tags "CI" {
|
||||
|
||||
$commands.Count | Should -Be 1
|
||||
$aliasResult = $commands -as [System.Management.Automation.AliasInfo]
|
||||
$aliasResult | Should -BeOfType [System.Management.Automation.AliasInfo]
|
||||
$aliasResult | Should -BeOfType System.Management.Automation.AliasInfo
|
||||
$aliasResult.Name | Should -Be 'AliasCommandDiscoveryTest'
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ Describe "Telemetry for shell startup" -Tag CI {
|
||||
$uuidPath | Should -Exist
|
||||
(Get-ChildItem -Path $uuidPath).Length | Should -Be 16
|
||||
[byte[]]$newBytes = Get-Content -AsByteStream -Path $uuidPath
|
||||
[System.Guid]::New($newBytes) | Should -BeOfType [System.Guid]
|
||||
[System.Guid]::New($newBytes) | Should -BeOfType System.Guid
|
||||
}
|
||||
|
||||
It "Should not create a telemetry file if one already exists and telemetry is opted in" {
|
||||
@@ -96,7 +96,7 @@ Describe "Telemetry for shell startup" -Tag CI {
|
||||
[System.IO.File]::WriteAllBytes($uuidPath, $badBytes)
|
||||
& $PWSH -NoProfile -Command "exit"
|
||||
[byte[]]$nb = Get-Content -AsByteStream -Path $uuidPath
|
||||
[System.Guid]::New($nb) | Should -BeOfType [System.Guid]
|
||||
[System.Guid]::New($nb) | Should -BeOfType System.Guid
|
||||
}
|
||||
|
||||
It "Should not create a new telemetry file if the current one has a valid guid and is larger than 16 bytes" {
|
||||
|
||||
@@ -162,7 +162,7 @@ Describe "Cdxml cmdlets are supported" -Tag CI,RequireAdminOnWindows {
|
||||
|
||||
It "Should be possible to invoke a method on an object returned by Get-CimTest" @ItSkipOrPending {
|
||||
$result = Get-CimTest | Select-Object -first 1
|
||||
$result.GetCimSessionInstanceId() | Should -BeOfType [guid]
|
||||
$result.GetCimSessionInstanceId() | Should -BeOfType guid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,37 +27,37 @@ Describe "Built-in type information tests" -Tag "CI" {
|
||||
$typeData | Should -Not -BeNullOrEmpty
|
||||
|
||||
$typeData.Members.Count | Should -BeExactly 6
|
||||
$typeData.Members['Size'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['Size'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['Size'].GetScriptBlock.ToString() | Should -BeExactly '$this.ModuleMemorySize / 1024'
|
||||
$typeData.Members['Size'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['Size'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['Size'].Name | Should -Be "Size"
|
||||
|
||||
$typeData.Members['Company'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['Company'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['Company'].GetScriptBlock.ToString() | Should -BeExactly '$this.FileVersionInfo.CompanyName'
|
||||
$typeData.Members['Company'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['Company'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['Company'].Name | Should -Be "Company"
|
||||
|
||||
$typeData.Members['FileVersion'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['FileVersion'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['FileVersion'].GetScriptBlock.ToString() | Should -BeExactly '$this.FileVersionInfo.FileVersion'
|
||||
$typeData.Members['FileVersion'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['FileVersion'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['FileVersion'].Name | Should -Be "FileVersion"
|
||||
|
||||
$typeData.Members['ProductVersion'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['ProductVersion'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['ProductVersion'].GetScriptBlock.ToString() | Should -BeExactly '$this.FileVersionInfo.ProductVersion'
|
||||
$typeData.Members['ProductVersion'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['ProductVersion'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['ProductVersion'].Name | Should -Be "ProductVersion"
|
||||
|
||||
$typeData.Members['Description'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['Description'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['Description'].GetScriptBlock.ToString() | Should -BeExactly '$this.FileVersionInfo.FileDescription'
|
||||
$typeData.Members['Description'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['Description'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['Description'].Name | Should -Be "Description"
|
||||
|
||||
$typeData.Members['Product'] | Should -BeOfType "System.Management.Automation.Runspaces.ScriptPropertyData"
|
||||
$typeData.Members['Product'] | Should -BeOfType System.Management.Automation.Runspaces.ScriptPropertyData
|
||||
$typeData.Members['Product'].GetScriptBlock.ToString() | Should -BeExactly '$this.FileVersionInfo.ProductName'
|
||||
$typeData.Members['Product'].SetScriptBlock | Should -BeNullOrEmpty
|
||||
$typeData.Members['Product'].IsHidden | Should -BeFalse
|
||||
@@ -83,7 +83,7 @@ Describe "Built-in type information tests" -Tag "CI" {
|
||||
$typeData | Should -Not -BeNullOrEmpty
|
||||
|
||||
$typeData.Members.Count | Should -BeExactly 1
|
||||
$typeData.Members['Flags'] | Should -BeOfType "System.Management.Automation.Runspaces.CodePropertyData"
|
||||
$typeData.Members['Flags'] | Should -BeOfType System.Management.Automation.Runspaces.CodePropertyData
|
||||
$typeData.Members['Flags'].IsHidden | Should -BeFalse
|
||||
$typeData.Members['Flags'].Name | Should -Be "Flags"
|
||||
|
||||
@@ -100,7 +100,7 @@ Describe "Built-in type information tests" -Tag "CI" {
|
||||
$typeData.DefaultKeyPropertySet | Should -BeNullOrEmpty
|
||||
|
||||
$typeData.SerializationMethod | Should -BeExactly "SpecificProperties"
|
||||
$typeData.PropertySerializationSet | Should -BeOfType "System.Management.Automation.Runspaces.PropertySetData"
|
||||
$typeData.PropertySerializationSet | Should -BeOfType System.Management.Automation.Runspaces.PropertySetData
|
||||
[string]::Join(",", $typeData.PropertySerializationSet.ReferencedProperties) | Should -BeExactly "Position,Flags,HelpMessage"
|
||||
}
|
||||
|
||||
|
||||
@@ -167,8 +167,8 @@ Describe "Experimental Feature Basic Tests - Feature-Disabled" -tags "CI" {
|
||||
## Common parameters + '-Name' and '-ConfigName' (dynamic parameters are triggered)
|
||||
$command.Parameters.Count | Should -Be ($CommonParameterCount + 2)
|
||||
$command.Parameters["ConfigName"].Attributes.Count | Should -Be 2
|
||||
$command.Parameters["ConfigName"].Attributes[0] | Should -BeOfType [parameter]
|
||||
$command.Parameters["ConfigName"].Attributes[1] | Should -BeOfType [ValidateNotNullOrEmpty]
|
||||
$command.Parameters["ConfigName"].Attributes[0] | Should -BeOfType parameter
|
||||
$command.Parameters["ConfigName"].Attributes[1] | Should -BeOfType ValidateNotNullOrEmpty
|
||||
|
||||
$command.Parameters.ContainsKey("ConfigFile") | Should -BeFalse
|
||||
}
|
||||
@@ -365,8 +365,8 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {
|
||||
## Common parameters + '-Name' and '-ConfigFile' (dynamic parameters are triggered)
|
||||
$command.Parameters.Count | Should -Be ($CommonParameterCount + 2)
|
||||
$command.Parameters["ConfigFile"].Attributes.Count | Should -Be 2
|
||||
$command.Parameters["ConfigFile"].Attributes[0] | Should -BeOfType [parameter]
|
||||
$command.Parameters["ConfigFile"].Attributes[1] | Should -BeOfType [ValidateNotNullOrEmpty]
|
||||
$command.Parameters["ConfigFile"].Attributes[0] | Should -BeOfType parameter
|
||||
$command.Parameters["ConfigFile"].Attributes[1] | Should -BeOfType ValidateNotNullOrEmpty
|
||||
|
||||
$command.Parameters.ContainsKey("ConfigName") | Should -BeFalse
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Describe 'Tests for $ErrorView' -Tag CI {
|
||||
|
||||
It '$ErrorView is an enum' {
|
||||
$ErrorView | Should -BeOfType [System.Management.Automation.ErrorView]
|
||||
$ErrorView | Should -BeOfType System.Management.Automation.ErrorView
|
||||
}
|
||||
|
||||
It '$ErrorView should have correct default value' {
|
||||
|
||||
@@ -28,7 +28,7 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") {
|
||||
$credential = [PSCredential]::new('username', $password)
|
||||
|
||||
$err = ({New-PSSession -ComputerName 'localhost' -Credential $credential -Authentication Basic} | Should -Throw -PassThru -ErrorId 'System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand')
|
||||
$err.Exception | Should -BeOfType [System.Management.Automation.Remoting.PSRemotingTransportException]
|
||||
$err.Exception | Should -BeOfType System.Management.Automation.Remoting.PSRemotingTransportException
|
||||
# Should be PSRemotingErrorId.ConnectFailed
|
||||
# Ensures we are looking at the expected instance
|
||||
$err.Exception.ErrorCode | Should -Be 801
|
||||
@@ -48,7 +48,7 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") {
|
||||
# NOTE: The connection is expected to fail but not with a ConnectFailed exception
|
||||
$uri = "https://localhost"
|
||||
New-PSSession -Uri $uri -Credential $credential -Authentication Basic -ErrorVariable err
|
||||
$err.Exception | Should -BeOfType [System.Management.Automation.Remoting.PSRemotingTransportException]
|
||||
$err.Exception | Should -BeOfType System.Management.Automation.Remoting.PSRemotingTransportException
|
||||
$err.FullyQualifiedErrorId | Should -Be '1,PSSessionOpenFailed'
|
||||
$err.Exception.HResult | Should -Be 0x80131501
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {
|
||||
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
|
||||
|
||||
$e = { $rs.Open() } | Should -Throw -PassThru
|
||||
$e.Exception.InnerException.InnerException | Should -BeOfType "System.IO.FileNotFoundException"
|
||||
$e.Exception.InnerException.InnerException | Should -BeOfType System.IO.FileNotFoundException
|
||||
}
|
||||
|
||||
It "SSHConnectionInfo should throw argument exception for invalid port (non 16bit uint)" {
|
||||
|
||||
@@ -10,7 +10,7 @@ try {
|
||||
}
|
||||
It "The SessionOption type can be created" {
|
||||
$result = [Microsoft.WSMan.Management.SessionOption]::new()
|
||||
$result | Should -BeOfType "Microsoft.WSMan.Management.SessionOption"
|
||||
$result | Should -BeOfType Microsoft.WSMan.Management.SessionOption
|
||||
}
|
||||
It "The SessionOption type has the proper properties when created with the default constructor" {
|
||||
$result = [Microsoft.WSMan.Management.SessionOption]::new()
|
||||
|
||||
Reference in New Issue
Block a user