From 1e5b36eaf4a68086af9396a11ecc63cff8ef48e6 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 08:45:06 -0700 Subject: [PATCH 01/21] Introduce new pester syntax: -Parameter in test module Microsoft.PowrShell.Utility. --- .../Add-Member.Tests.ps1 | 88 ++-- .../Add-Type.Tests.ps1 | 16 +- .../Clear-Variable.Tests.ps1 | 140 +++--- .../Compare-Object.Tests.ps1 | 184 ++++---- .../ConvertFrom-Csv.Tests.ps1 | 34 +- .../ConvertFrom-Json.Tests.ps1 | 12 +- .../ConvertFrom-StringData.Tests.ps1 | 30 +- .../ConvertTo-Csv.Tests.ps1 | 54 +-- .../ConvertTo-Html.Tests.ps1 | 22 +- .../ConvertTo-Json.Tests.ps1 | 6 +- .../ConvertTo-SecureString.Tests.ps1 | 2 +- .../ConvertTo-Xml.Tests.ps1 | 60 +-- .../Debug-Runspace.Tests.ps1 | 8 +- .../EnableDisablePSBreakpoint.Tests.ps1 | 8 +- .../Environment-Variables.Tests.ps1 | 18 +- .../Eventing.Tests.ps1 | 14 +- .../Export-Alias.Tests.ps1 | 50 +- .../Export-Csv.Tests.ps1 | 40 +- .../Export-FormatData.Tests.ps1 | 10 +- .../Format-Custom.Tests.ps1 | 22 +- .../Format-List.Tests.ps1 | 86 ++-- .../Format-Table.Tests.ps1 | 72 +-- .../Format-Wide.Tests.ps1 | 46 +- .../FormatHex.Tests.ps1 | 62 +-- .../Get-Alias.Tests.ps1 | 188 ++++---- .../Get-Culture.Tests.ps1 | 8 +- .../Get-Date.Tests.ps1 | 74 +-- .../Get-Event.Tests.ps1 | 8 +- .../Get-EventSubscriber.Tests.ps1 | 6 +- .../Get-FileHash.Tests.ps1 | 18 +- .../Get-FormatData.Tests.ps1 | 2 +- .../Get-Host.Tests.ps1 | 4 +- .../Get-Member.Tests.ps1 | 52 +-- .../Get-PSBreakpoint.Tests.ps1 | 8 +- .../Get-PSCallStack.Tests.ps1 | 44 +- .../Get-Random.Tests.ps1 | 66 +-- .../Get-RunspaceDebug.Tests.ps1 | 4 +- .../Get-TraceSource.Tests.ps1 | 2 +- .../Get-UICulture.Tests.ps1 | 4 +- .../Get-Unique.Tests.ps1 | 34 +- .../Get-Uptime.Tests.ps1 | 6 +- .../Get-Variable.Tests.ps1 | 82 ++-- .../Get-Verb.Tests.ps1 | 24 +- .../Group-Object.Tests.ps1 | 60 +-- .../Implicit.Remoting.Tests.ps1 | 428 +++++++++--------- .../Import-Alias.Tests.ps1 | 22 +- .../Import-Csv.Tests.ps1 | 42 +- .../Import-LocalizedData.Tests.ps1 | 10 +- .../ImportExportCSV.Delimiter.Tests.ps1 | 18 +- .../Invoke-Expression.Tests.ps1 | 6 +- .../Invoke-Item.Tests.ps1 | 24 +- .../JsonObject.Tests.ps1 | 20 +- .../Measure-Command.Tests.ps1 | 6 +- .../Measure-Object.Tests.ps1 | 90 ++-- .../MiscCmdletUpdates.Tests.ps1 | 10 +- .../New-Alias.Tests.ps1 | 36 +- .../New-Event.Tests.ps1 | 6 +- .../New-Object.Tests.ps1 | 80 ++-- .../New-TimeSpan.Tests.ps1 | 24 +- .../New-Variable.Tests.ps1 | 100 ++-- .../NewGuid.Tests.ps1 | 6 +- .../NewTemporaryFile.Tests.ps1 | 10 +- .../Out-File.Tests.ps1 | 104 ++--- .../Out-String.Tests.ps1 | 24 +- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 172 +++---- .../PowerShellData.tests.ps1 | 10 +- .../Read-Host.Tests.ps1 | 10 +- .../Register-EngineEvent.Tests.ps1 | 2 +- .../Register-ObjectEvent.Tests.ps1 | 6 +- .../Remove-Alias.Tests.ps1 | 2 +- .../Remove-Event.Tests.ps1 | 8 +- .../Remove-PSBreakpoint.Tests.ps1 | 12 +- .../Remove-TypeData.Tests.ps1 | 16 +- .../Remove-Variable.Tests.ps1 | 124 ++--- .../RunspaceCmdlets.Tests.ps1 | 12 +- .../Select-Object.Tests.ps1 | 164 +++---- .../Select-String.Tests.ps1 | 68 +-- .../Select-XML.Tests.ps1 | 6 +- .../Send-MailMessage.Tests.ps1 | 14 +- .../Set-Alias.Tests.ps1 | 76 ++-- .../Set-Date.Tests.ps1 | 4 +- .../Set-PSBreakpoint.Tests.ps1 | 62 +-- .../Set-Variable.Tests.ps1 | 158 +++---- .../Sort-Object.Tests.ps1 | 124 ++--- .../Start-Sleep.Tests.ps1 | 14 +- .../Tee-Object.Tests.ps1 | 24 +- .../Trace-Command.Tests.ps1 | 22 +- .../Unblock-File.Tests.ps1 | 8 +- .../Unimplemented-Cmdlet.Tests.ps1 | 2 +- .../Update-FormatData.Tests.ps1 | 16 +- .../Update-TypeData.Tests.ps1 | 124 ++--- .../Wait-Event.Tests.ps1 | 4 +- .../WebCmdlets.Tests.ps1 | 2 +- .../Write-Debug.Tests.ps1 | 2 +- .../Write-Error.Tests.ps1 | 94 ++-- .../Write-Host.Tests.ps1 | 14 +- .../Write-Output.Tests.ps1 | 36 +- .../Write-Progress.Tests.ps1 | 10 +- .../Write-Stream.Tests.ps1 | 34 +- .../Write-Verbose.Tests.ps1 | 16 +- .../XMLCommand.Tests.ps1 | 50 +- .../alias.tests.ps1 | 18 +- .../clixml.tests.ps1 | 40 +- .../command.tests.ps1 | 14 +- .../formatdata.tests.ps1 | 10 +- .../object.tests.ps1 | 20 +- .../string.tests.ps1 | 22 +- .../typedata.tests.ps1 | 44 +- .../xml.tests.ps1 | 20 +- 109 files changed, 2277 insertions(+), 2277 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 index 18e075415ea..dd4be831478 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 @@ -11,7 +11,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" } # when Name is empty @@ -22,7 +22,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" } # when MemberType is null @@ -33,7 +33,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" } # when MemberType is empty @@ -44,7 +44,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" } # when InputObject is null @@ -55,7 +55,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -70,7 +70,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch{ - $_.FullyQualifiedErrorId | Should Be "Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand" } } } @@ -86,7 +86,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "CannotAddMemberType,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "CannotAddMemberType,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -98,7 +98,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -114,7 +114,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "Value1AndValue2AreNotBothNull,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "Value1AndValue2AreNotBothNull,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -128,20 +128,20 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "InvalidCastFromStringToType,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "InvalidCastFromStringToType,Microsoft.PowerShell.Commands.AddMemberCommand" } } It "Successful alias, no type" { $results = Add-Member -InputObject a -MemberType AliasProperty -Name Cnt -Value Length -passthru - $results.Cnt | Should BeOfType Int32 - $results.Cnt | Should Be 1 + $results.Cnt | Should -BeOfType Int32 + $results.Cnt | Should -Be 1 } It "Successful alias, with type" { $results = add-member -InputObject a -MemberType AliasProperty -Name Cnt -Value Length -SecondValue String -passthru - $results.Cnt | Should BeOfType String - $results.Cnt | Should Be '1' + $results.Cnt | Should -BeOfType String + $results.Cnt | Should -Be '1' } It "CodeProperty Reference Wrong Type" { @@ -152,14 +152,14 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } } It "Empty Member Set Null Value1" { $results = add-member -InputObject a -MemberType MemberSet -Name Name -Value $null -passthru - $results.Length | Should Be 1 - $results.Name.a | Should BeNullOrEmpty + $results.Length | Should -Be 1 + $results.Name.a | Should -BeNullOrEmpty } It "Member Set With 1 Member" { @@ -167,7 +167,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $n=new-object Management.Automation.PSNoteProperty a,1 $members.Add($n) $r=add-member -InputObject a -MemberType MemberSet -Name Name -Value $members -passthru - $r.Name.a | Should Be '1' + $r.Name.a | Should -Be '1' } It "MemberSet With Wrong Type For Value1" { @@ -178,7 +178,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -190,14 +190,14 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } } It "Add ScriptMethod Success" { $results = add-member -InputObject 'abc' -MemberType ScriptMethod -Name Name -Value {$this.length} -passthru - $results | Should Be abc - $results.Name() | Should Be 3 + $results | Should -Be abc + $results.Name() | Should -Be 3 } It "ScriptProperty Reference Wrong Type" { @@ -208,7 +208,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" + $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -217,41 +217,41 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $al=(get-alias ScriptPropertyTestAlias) $al.Description="MyDescription" $al | add-member -MemberType ScriptProperty -Name NewDescription -Value {$this.Description} -SecondValue {$this.Description=$args[0]} - $al.NewDescription | Should Be 'MyDescription' + $al.NewDescription | Should -Be 'MyDescription' $al.NewDescription = "some description" - $al.NewDescription | Should Be 'some description' + $al.NewDescription | Should -Be 'some description' } It "Add TypeName MemberSet Success" { $a = 'string' | add-member -MemberType NoteProperty -Name TestNote -Value Any -TypeName MyType -passthru - $a.PSTypeNames[0] | Should Be MyType + $a.PSTypeNames[0] | Should -Be MyType } It "Add TypeName Existing Name Success" { $a = 'string' | add-member -TypeName System.Object -passthru - $a.PSTypeNames[0] | Should Be System.Object + $a.PSTypeNames[0] | Should -Be System.Object } It "Add Single Note To Array" { $a=1,2,3 $a = Add-Member -InputObject $a -MemberType NoteProperty -Name Name -Value Value -PassThru - $a.Name | Should Be Value + $a.Name | Should -Be Value } It "Add Multiple Note Members" { $obj=new-object psobject $hash=@{Name='Name';TestInt=1;TestNull=$null} add-member -InputObject $obj $hash - $obj.Name | Should Be 'Name' - $obj.TestInt | Should Be 1 - $obj.TestNull | Should BeNullOrEmpty + $obj.Name | Should -Be 'Name' + $obj.TestInt | Should -Be 1 + $obj.TestNull | Should -BeNullOrEmpty } It "Add Multiple Note With TypeName" { $obj=new-object psobject $hash=@{Name='Name';TestInt=1;TestNull=$null} $obj = add-member -InputObject $obj $hash -TypeName MyType -Passthru - $obj.PSTypeNames[0] | Should Be MyType + $obj.PSTypeNames[0] | Should -Be MyType } It "Add Multiple Members With Force" { @@ -259,32 +259,32 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $hash=@{TestNote='hello'} $obj | Add-Member -MemberType NoteProperty -Name TestNote -Value 1 $obj | add-member $hash -force - $obj.TestNote | Should Be 'hello' + $obj.TestNote | Should -Be 'hello' } It "Simplified Add-Member should support using 'Property' as the NoteProperty member name" { $results = add-member -InputObject a property Any -passthru - $results.property | Should Be 'Any' + $results.property | Should -Be 'Any' $results = add-member -InputObject a Method Any -passthru - $results.Method | Should Be 'Any' + $results.Method | Should -Be 'Any' $results = add-member -InputObject a 23 Any -passthru - $results.23 | Should Be 'Any' + $results.23 | Should -Be 'Any' $results = add-member -InputObject a 8 np Any -passthru - $results.np | Should Be 'Any' + $results.np | Should -Be 'Any' $results = add-member -InputObject a 16 sp {1+1} -passthru - $results.sp | Should Be 2 + $results.sp | Should -Be 2 } It "Verify Add-Member error message is not empty" { $object = @(1,2) Add-Member -InputObject $object "ABC" "Value1" Add-Member -InputObject $object "ABC" "Value2" -ErrorVariable errorVar -ErrorAction SilentlyContinue - $errorVar.Exception | Should BeOfType "System.InvalidOperationException" - $errorVar.Exception.Message | Should Not BeNullOrEmpty + $errorVar.Exception | Should -BeOfType "System.InvalidOperationException" + $errorVar.Exception.Message | Should -Not -BeNullOrEmpty } } @@ -294,8 +294,8 @@ Describe "Add-Member" -Tags "CI" { $o = New-Object psobject Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal" - $o.proppy | Should Not BeNullOrEmpty - $o.proppy | Should Be "superVal" + $o.proppy | Should -Not -BeNullOrEmpty + $o.proppy | Should -Be "superVal" } It "Should be able to add a member to an object that already has a member in it" { @@ -303,7 +303,7 @@ Describe "Add-Member" -Tags "CI" { Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal" Add-Member -InputObject $o -MemberType NoteProperty -Name AnotherMember -Value "AnotherValue" - $o.AnotherMember | Should Not BeNullOrEmpty - $o.AnotherMember | Should Be "AnotherValue" + $o.AnotherMember | Should -Not -BeNullOrEmpty + $o.AnotherMember | Should -Be "AnotherValue" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 index 5d9aac7222e..6b85cc0a0ea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 @@ -36,11 +36,11 @@ Describe "Add-Type" -Tags "CI" { } It "Public 'Language' enumeration contains all members" { - [Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should Be "CSharp,VisualBasic" + [Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should -Be "CSharp,VisualBasic" } It "Should not throw given a simple class definition" { - { Add-Type -TypeDefinition "public static class foo { }" } | Should Not Throw + { Add-Type -TypeDefinition "public static class foo { }" } | Should -Not -Throw } It "Can use System.Management.Automation.CmdletAttribute" { @@ -48,21 +48,21 @@ Describe "Add-Type" -Tags "CI" { [System.Management.Automation.Cmdlet("Get", "Thing", ConfirmImpact = System.Management.Automation.ConfirmImpact.High, SupportsPaging = true)] public class AttributeTest$guid {} "@ - Add-Type -TypeDefinition $code -PassThru | Should Not Be $null + Add-Type -TypeDefinition $code -PassThru | Should -Not -Be $null } It "Can load TPA assembly System.Runtime.Serialization.Primitives.dll" { - Add-Type -AssemblyName 'System.Runtime.Serialization.Primitives' -PassThru | Should Not Be $null + Add-Type -AssemblyName 'System.Runtime.Serialization.Primitives' -PassThru | Should -Not -Be $null } It "Can compile C# files" { - { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should Throw - { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should Throw + { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Throw + { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should -Throw Add-Type -Path $codeFile1,$codeFile2 - { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should Not Throw - { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should Not Throw + { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Not -Throw + { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index 5eae4c376ee..b14ee03133d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -5,10 +5,10 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Set-Variable foo bar Clear-Variable -Name foo $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be $null - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be $null + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "Clear-Variable ReadOnly variable Name should throw exception and force Clear-Variable should works"{ @@ -19,37 +19,37 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.CategoryInfo| Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should Be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" } Clear-Variable -Name foo -Force $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be $null - $var1.Options|Should Be "ReadOnly" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be $null + $var1.Options|Should -Be "ReadOnly" + $var1.Description|Should -Be "" } It "Clear-Variable normal variable Name with local scope should works"{ Set-Variable foo bar &{ Set-Variable foo baz - $foo | should be baz + $foo | should -be baz Clear-Variable -Name foo -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be $null - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be $null + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "Clear-Variable Private variable Name should works and Get-Variable with local scope should throw exception"{ @@ -60,16 +60,16 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.CategoryInfo| Should Match "ItemNotFoundException" - $_.FullyQualifiedErrorId | Should Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.CategoryInfo| Should -Match "ItemNotFoundException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "Private" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "Private" + $var1.Description|Should -Be "" } It "Clear-Variable normal variable Name with local scope should works in different scope"{ @@ -79,23 +79,23 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be $null - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be $null + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } } @@ -106,14 +106,14 @@ Describe "Clear-Variable" -Tags "CI" { It "Should be able to clear a variable using the Name switch" { Clear-Variable -Name var1 - $var1 | Should BeNullOrEmpty - { Get-Variable var1 } | Should Not Throw + $var1 | Should -BeNullOrEmpty + { Get-Variable var1 } | Should -Not -Throw } It "Should be able to clear a variable without using the Name switch" { Clear-Variable var1 - $var1 | Should BeNullOrEmpty - { Get-Variable var1 } | Should Not Throw + $var1 | Should -BeNullOrEmpty + { Get-Variable var1 } | Should -Not -Throw } It "Should be able to include a set of variables to clear" { @@ -127,14 +127,14 @@ Describe "Clear-Variable" -Tags "CI" { Clear-Variable -Name w, vari* -Include w, vari* - $variable1 | Should BeNullOrEmpty - $variable2 | Should BeNullOrEmpty - $variable3 | Should BeNullOrEmpty - $w | Should BeNullOrEmpty + $variable1 | Should -BeNullOrEmpty + $variable2 | Should -BeNullOrEmpty + $variable3 | Should -BeNullOrEmpty + $w | Should -BeNullOrEmpty - $var1 | Should Not BeNullOrEmpty - $var2 | Should Not BeNullOrEmpty - $var3 | Should Not BeNullOrEmpty + $var1 | Should -Not -BeNullOrEmpty + $var2 | Should -Not -BeNullOrEmpty + $var3 | Should -Not -BeNullOrEmpty } @@ -149,24 +149,24 @@ Describe "Clear-Variable" -Tags "CI" { Clear-Variable -Name w, vari* -Exclude var* - $variable1 | Should Not BeNullOrEmpty - $variable2 | Should Not BeNullOrEmpty - $variable3 | Should Not BeNullOrEmpty - $var1 | Should Not BeNullOrEmpty - $var2 | Should Not BeNullOrEmpty - $var3 | Should Not BeNullOrEmpty + $variable1 | Should -Not -BeNullOrEmpty + $variable2 | Should -Not -BeNullOrEmpty + $variable3 | Should -Not -BeNullOrEmpty + $var1 | Should -Not -BeNullOrEmpty + $var2 | Should -Not -BeNullOrEmpty + $var3 | Should -Not -BeNullOrEmpty - $w | Should BeNullOrEmpty + $w | Should -BeNullOrEmpty } It "Should be able to pass the cleared object through the pipeline using the passthru switch" { - { Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should Not Throw + { Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should -Not -Throw } It "Should not clear environment variables" { $env:TEMPVARIABLE = "test data" - {Clear-Variable -Name env:TEMPVARIABLE -ErrorAction Stop} | Should Throw + {Clear-Variable -Name env:TEMPVARIABLE -ErrorAction Stop} | Should -Throw } It "Should clear variable even if it is read-only using the Force parameter" { @@ -177,8 +177,8 @@ Describe "Clear-Variable" -Tags "CI" { Clear-Variable -Name var1 Clear-Variable -Name var2 -Force - $var1 | Should BeNullOrEmpty - $var2 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty + $var2 | Should -BeNullOrEmpty } finally { @@ -193,9 +193,9 @@ Describe "Clear-Variable" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $_.FullyQualifiedErrorId | should -be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" } - $var2 | Should Not BeNullOrEmpty + $var2 | Should -Not -BeNullOrEmpty Remove-Variable -Name var2 -Force } @@ -208,19 +208,19 @@ Describe "Clear-Variable" -Tags "CI" { Clear-Variable -Name globalVar -Scope global - $globalVar | Should BeNullOrEmpty + $globalVar | Should -BeNullOrEmpty } It "Should not be able to clear a global scope variable using the local switch" { New-Variable globalVar -Value 1 -Scope global -Force - {Clear-Variable -Name globalVar -Scope local -ErrorAction Stop} | Should Throw + {Clear-Variable -Name globalVar -Scope local -ErrorAction Stop} | Should -Throw } It "Should not be able to clear a global variable using the script scope switch" { New-Variable globalVar -Value 1 -Scope global -Force - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should Throw + {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw } It "Should be able to clear an item locally using the local switch" { @@ -228,21 +228,21 @@ Describe "Clear-Variable" -Tags "CI" { Clear-Variable -Name localVar -Scope local - $localVar | Should BeNullOrEmpty + $localVar | Should -BeNullOrEmpty - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should Throw + {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw } It "Should not be able to clear an item locally using the global switch" { New-Variable localVar -Value 2 -Scope local -Force - {Clear-Variable -Name localVar -Scope global -ErrorAction Stop} | Should Throw + {Clear-Variable -Name localVar -Scope global -ErrorAction Stop} | Should -Throw } It "Should not be able to clear a local variable using the script scope switch" { New-Variable localVar -Value 2 -Scope local -Force - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should Throw + {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw } It "Should be able to clear a script variable created using the script switch" { @@ -250,7 +250,7 @@ Describe "Clear-Variable" -Tags "CI" { New-Variable -Name derp2 -Value 3 -Scope script -Force Clear-Variable -Name derp2 -Scope script - }| Should Not Throw + }| Should -Not -Throw } It "Should be able to clear a global script variable that was created using the script scope switch" { @@ -258,7 +258,7 @@ Describe "Clear-Variable" -Tags "CI" { New-Variable -Name derpx -Value 4 -Scope script -Force Clear-Variable -Name derpx -Scope script - } | Should Not Throw + } | Should -Not -Throw } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index 27836bb2e5c..77ea4b12396 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -21,87 +21,87 @@ Describe "Compare-Object" -Tags "CI" { } It "Should be able to compare the same object using the referenceObject and differenceObject switches" { - { Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw + { Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should -Not -Throw } It "Should not throw when referenceobject switch is not used" { - { Compare-Object $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw + { Compare-Object $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should -Not -Throw } It "Should not throw when differenceobject switch is not used" { - { Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw + { Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should -Not -Throw } It "Should indicate data that exists only in the reference dataset" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) - $actualOutput[1].SideIndicator | Should Be "<=" + $actualOutput[1].SideIndicator | Should -Be "<=" } It "Should indicate data that exists only in the difference dataset" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) - $actualOutput[1].SideIndicator | Should Be "<=" + $actualOutput[1].SideIndicator | Should -Be "<=" } It "Should indicate data that exists in both datasets when the includeEqual switch is used" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual - $actualOutput.Length | Should Be 4 - $actualOutput[0].SideIndicator | Should Be "==" - $actualOutput[1].SideIndicator | Should Be "==" + $actualOutput.Length | Should -Be 4 + $actualOutput[0].SideIndicator | Should -Be "==" + $actualOutput[1].SideIndicator | Should -Be "==" } It "Should be able to use the casesensitive switch" { - { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive } | Should Not Throw + { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive } | Should -Not -Throw } It "Should correctly indicate that different cases are different when the casesensitive switch is used" { $caOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive $ncaOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) - $caOutput.Length | Should Be 4 + $caOutput.Length | Should -Be 4 - $ncaOutput[1].SideIndicator | Should Not Be $caOutput[1].SideIndicator - $ncaOutput[2].SideIndicator | Should Not Be $caOutput[2].SideIndicator - $ncaOutput[3].SideIndicator | Should Not Be $caOutput[3].SideIndicator + $ncaOutput[1].SideIndicator | Should -Not -Be $caOutput[1].SideIndicator + $ncaOutput[2].SideIndicator | Should -Not -Be $caOutput[2].SideIndicator + $ncaOutput[3].SideIndicator | Should -Not -Be $caOutput[3].SideIndicator } It "Should throw when reference set is null" { - { Compare-Object -ReferenceObject $anonexistentvariable -DifferenceObject $(Get-Content $file4) } | Should Throw + { Compare-Object -ReferenceObject $anonexistentvariable -DifferenceObject $(Get-Content $file4) } | Should -Throw } It "Should throw when difference set is null" { - { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should Throw + { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should -Throw } It "Should give a 0 array when using excludedifferent switch without also using the includeequal switch" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent - $actualOutput.Length | Should Be 0 + $actualOutput.Length | Should -Be 0 } It "Should only display equal lines when excludeDifferent switch is used alongside the includeequal switch" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual -ExcludeDifferent - $actualOutput.Length | Should Be 2 + $actualOutput.Length | Should -Be 2 } It "Should be able to pass objects to pipeline using the passthru switch" { - { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should Not Throw + { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should -Not -Throw } It "Should be able to specify the property of two objects to compare" { $actualOutput = Compare-Object -ReferenceObject $file3 -DifferenceObject $TestDrive -Property Length - $actualOutput[0].Length | Should BeNullOrEmpty - $actualOutput[1].Length | Should BeGreaterThan 0 - $actualOutput[0].Length | Should Not Be $actualOutput[1].Length + $actualOutput[0].Length | Should -BeNullOrEmpty + $actualOutput[1].Length | Should -BeGreaterThan 0 + $actualOutput[0].Length | Should -Not -Be $actualOutput[1].Length } It "Should be able to specify the syncwindow without error" { - { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 5 } | Should Not Throw - { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 8 } | Should Not Throw + { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 5 } | Should -Not -Throw + { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 8 } | Should -Not -Throw } It "Should have the expected output when changing the syncwindow" { @@ -110,15 +110,15 @@ Describe "Compare-Object" -Tags "CI" { $actualOutput = Compare-Object -ReferenceObject $var1 -DifferenceObject $var2 -syncWindow 6 - $actualOutput[0].InputObject | Should Be 15 - $actualOutput[1].InputObject | Should Be 1 - $actualOutput[2].InputObject | Should Be 1 - $actualOutput[3].InputObject | Should Be 15 + $actualOutput[0].InputObject | Should -Be 15 + $actualOutput[1].InputObject | Should -Be 1 + $actualOutput[2].InputObject | Should -Be 1 + $actualOutput[3].InputObject | Should -Be 15 - $actualOutput[0].SideIndicator | Should be "=>" - $actualOutput[1].SideIndicator | Should be "<=" - $actualOutput[2].SideIndicator | Should be "=>" - $actualOutput[3].SideIndicator | Should be "<=" + $actualOutput[0].SideIndicator | Should -be "=>" + $actualOutput[1].SideIndicator | Should -be "<=" + $actualOutput[2].SideIndicator | Should -be "=>" + $actualOutput[3].SideIndicator | Should -be "<=" } } @@ -230,23 +230,23 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { if(!$excludeDifferent) { - $result.Count | Should Be 2 + $result.Count | Should -Be 2 if($passthru) { - $result[0] | Should Be $empsDifference - $result[1] | Should Be $empsReference + $result[0] | Should -Be $empsDifference + $result[1] | Should -Be $empsReference } else { - $result[0].InputObject | Should Be $empsDifference - $result[1].InputObject | Should Be $empsReference - $result[0].SideIndicator | Should Be "=>" - $result[1].SideIndicator | Should Be "<=" + $result[0].InputObject | Should -Be $empsDifference + $result[1].InputObject | Should -Be $empsReference + $result[0].SideIndicator | Should -Be "=>" + $result[1].SideIndicator | Should -Be "<=" } } else { - $result.Count | Should Be 0 + $result.Count | Should -Be 0 } } } @@ -268,30 +268,30 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { if(!$excludeDifferent) { - $result.Count | Should Be 2 + $result.Count | Should -Be 2 if($passthru) { - $result[0] | Should Be $empsReference[0] - $result[1] | Should Be $empsReference[1] + $result[0] | Should -Be $empsReference[0] + $result[1] | Should -Be $empsReference[1] } else { - $result[0].InputObject | Should Be $empsReference[0] - $result[1].InputObject | Should Be $empsReference[1] - $result[0].SideIndicator | Should Be "==" - $result[1].SideIndicator | Should Be "<=" + $result[0].InputObject | Should -Be $empsReference[0] + $result[1].InputObject | Should -Be $empsReference[1] + $result[0].SideIndicator | Should -Be "==" + $result[1].SideIndicator | Should -Be "<=" } } else { if($passthru) { - $result | Should Be $empsReference[0] + $result | Should -Be $empsReference[0] } else { - $result.InputObject | Should Be $empsReference[0] - $result.SideIndicator | Should Be "==" + $result.InputObject | Should -Be $empsReference[0] + $result.SideIndicator | Should -Be "==" } } } @@ -301,17 +301,17 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { if($passthru) { - $result | Should Be $empsReference[1] + $result | Should -Be $empsReference[1] } else { - $result.InputObject | Should Be $empsReference[1] - $result.SideIndicator | Should Be "<=" + $result.InputObject | Should -Be $empsReference[1] + $result.SideIndicator | Should -Be "<=" } } else { - $result.Count | Should Be 0 + $result.Count | Should -Be 0 } } } @@ -334,30 +334,30 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { if(!$excludeDifferent) { - $result.Count | Should Be 2 + $result.Count | Should -Be 2 if($passthru) { - $result[0] | Should Be $empsReference - $result[1] | Should Be $empsDifference[1] + $result[0] | Should -Be $empsReference + $result[1] | Should -Be $empsDifference[1] } else { - $result[0].InputObject | Should Be $empsReference - $result[1].InputObject | Should Be $empsDifference[1] - $result[0].SideIndicator | Should Be "==" - $result[1].SideIndicator | Should Be "=>" + $result[0].InputObject | Should -Be $empsReference + $result[1].InputObject | Should -Be $empsDifference[1] + $result[0].SideIndicator | Should -Be "==" + $result[1].SideIndicator | Should -Be "=>" } } else { if($passthru) { - $result | Should Be $empsReference + $result | Should -Be $empsReference } else { - $result.InputObject | Should Be $empsReference - $result.SideIndicator | Should Be "==" + $result.InputObject | Should -Be $empsReference + $result.SideIndicator | Should -Be "==" } } } @@ -367,17 +367,17 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { if($passthru) { - $result | Should Be $empsDifference[1] + $result | Should -Be $empsDifference[1] } else { - $result.InputObject | Should Be $empsDifference[1] - $result.SideIndicator | Should Be "=>" + $result.InputObject | Should -Be $empsDifference[1] + $result.SideIndicator | Should -Be "=>" } } else { - $result.Count | Should Be 0 + $result.Count | Should -Be 0 } } } @@ -399,29 +399,29 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { if($recordEqual) { - $result.Count | Should Be 4 + $result.Count | Should -Be 4 if($passthru) { - $result[0] | Should Be $empsReference[0] - $result[1] | Should Be $empsReference[2] - $result[2] | Should Be $empsReference[1] - $result[3] | Should Be $empsReference[3] + $result[0] | Should -Be $empsReference[0] + $result[1] | Should -Be $empsReference[2] + $result[2] | Should -Be $empsReference[1] + $result[3] | Should -Be $empsReference[3] } else { - $result[0].InputObject | Should Be $empsReference[0] - $result[0].SideIndicator | Should Be "==" - $result[1].InputObject | Should Be $empsReference[2] - $result[1].SideIndicator | Should Be "==" - $result[2].InputObject | Should Be $empsReference[1] - $result[2].SideIndicator | Should Be "==" - $result[3].InputObject | Should Be $empsReference[3] - $result[3].SideIndicator | Should Be "==" + $result[0].InputObject | Should -Be $empsReference[0] + $result[0].SideIndicator | Should -Be "==" + $result[1].InputObject | Should -Be $empsReference[2] + $result[1].SideIndicator | Should -Be "==" + $result[2].InputObject | Should -Be $empsReference[1] + $result[2].SideIndicator | Should -Be "==" + $result[3].InputObject | Should -Be $empsReference[3] + $result[3].SideIndicator | Should -Be "==" } } else { - $result.Count | Should Be 0 + $result.Count | Should -Be 0 } } } @@ -432,28 +432,28 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { $a = [version]"1.2.3.4" $b = [version]"5.6.7.8" $result = Compare-Object $a $b -IncludeEqual -Property {$_.Major},{$_.Minor} - $result[0] | Select-Object -ExpandProperty "*Major" | Should Be 5 - $result[0] | Select-Object -ExpandProperty "*Minor" | Should Be 6 - $result[0].SideIndicator | Should Be "=>" - $result[1] | Select-Object -ExpandProperty "*Major" | Should Be 1 - $result[1] | Select-Object -ExpandProperty "*Minor" | Should Be 2 - $result[1].SideIndicator | Should Be "<=" + $result[0] | Select-Object -ExpandProperty "*Major" | Should -Be 5 + $result[0] | Select-Object -ExpandProperty "*Minor" | Should -Be 6 + $result[0].SideIndicator | Should -Be "=>" + $result[1] | Select-Object -ExpandProperty "*Major" | Should -Be 1 + $result[1] | Select-Object -ExpandProperty "*Minor" | Should -Be 2 + $result[1].SideIndicator | Should -Be "<=" } It "Compare-Object with no ReferenceObject nor DifferenceObject: output nothing, no error and should work"{ $result = Compare-Object @() @() - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Compare-Object with no DifferenceObject should work"{ $result = Compare-Object @() @("diffObject") - $result.InputObject | Should Be "diffObject" - $result.SideIndicator | Should Be "=>" + $result.InputObject | Should -Be "diffObject" + $result.SideIndicator | Should -Be "=>" } It "Compare-Object with no ReferenceObject should work"{ $result = Compare-Object @("refObject") @() - $result.InputObject | Should Be "refObject" - $result.SideIndicator | Should Be "<=" + $result.InputObject | Should -Be "refObject" + $result.SideIndicator | Should -Be "<=" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 index fbe8be135e5..1f4cc660b9a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 @@ -20,37 +20,37 @@ a,b,c } It "Should be able to be called" { - { ConvertFrom-Csv -InputObject $testObject } | Should Not Throw + { ConvertFrom-Csv -InputObject $testObject } | Should -Not -Throw } It "Should be able to pipe" { - { $testObject | ConvertFrom-Csv } | Should Not Throw + { $testObject | ConvertFrom-Csv } | Should -Not -Throw } It "Should have expected results when using piped inputs" { $csvContent = Get-Content $testcsv $actualresult = $csvContent | ConvertFrom-Csv - ,$actualresult | Should BeOfType "System.Array" - $actualresult[0] | Should BeOfType "PSCustomObject" + ,$actualresult | Should -BeOfType "System.Array" + $actualresult[0] | Should -BeOfType "PSCustomObject" #Should have a name property in the result - $actualresult[0].Name | Should Be $testName + $actualresult[0].Name | Should -Be $testName } It "Should be able to set a delimiter" { - { $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw + { $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should -Not -Throw } It "Should actually delimit the output" { $csvContent = Get-Content $testcsv $actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";" - ,$actualresult | Should BeOfType "System.Array" - $actualresult[0] | Should BeOfType "PSCustomObject" + ,$actualresult | Should -BeOfType "System.Array" + $actualresult[0] | Should -BeOfType "PSCustomObject" # ConvertFrom-Csv takes the first line of the input as a header by default - $actualresult.Length | Should Be $($csvContent.Length - 1) + $actualresult.Length | Should -Be $($csvContent.Length - 1) } It "Should be able to have multiple columns" { @@ -58,14 +58,14 @@ a,b,c $actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length - $actualLength | Should Be 3 + $actualLength | Should -Be 3 } It "Should Contain the Imported Type data" { $actualData = $testTypeData | ConvertFrom-Csv - $actualData.PSObject.TypeNames.Count | Should Be 2 - $actualData.PSObject.TypeNames[0] | Should Be "My.Custom.Object" - $actualData.PSObject.TypeNames[1] | Should Be "CSV:My.Custom.Object" + $actualData.PSObject.TypeNames.Count | Should -Be 2 + $actualData.PSObject.TypeNames[0] | Should -Be "My.Custom.Object" + $actualData.PSObject.TypeNames[1] | Should -Be "CSV:My.Custom.Object" } } @@ -75,9 +75,9 @@ Describe "ConvertFrom-Csv DRT Unit Tests" -Tags "CI" { $res = $inputObject | ConvertTo-Csv $result = $res | ConvertFrom-Csv -Header "Header1","Header2" - $result[0].Header1 | Should Be "First" - $result[0].Header2 | Should Be "Second" - $result[1].Header1 | Should Be "1" - $result[1].Header2 | Should Be "2" + $result[0].Header1 | Should -Be "First" + $result[0].Header2 | Should -Be "Second" + $result[1].Header1 | Should -Be "1" + $result[1].Header2 | Should -Be "2" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 index 403e8bb55f9..97ae068d6b7 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 @@ -11,27 +11,27 @@ Describe 'ConvertFrom-Json' -tags "CI" { It 'Can convert a single-line object with AsHashtable switch set to ' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { Param($AsHashtable) - ('{"a" : "1"}' | ConvertFrom-Json -AsHashtable:$AsHashtable).a | Should Be 1 + ('{"a" : "1"}' | ConvertFrom-Json -AsHashtable:$AsHashtable).a | Should -Be 1 } It 'Can convert one string-per-object with AsHashtable switch set to ' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { Param($AsHashtable) $json = @('{"a" : "1"}', '{"a" : "x"}') | ConvertFrom-Json -AsHashtable:$AsHashtable - $json.Count | Should Be 2 - $json[1].a | Should Be 'x' + $json.Count | Should -Be 2 + $json[1].a | Should -Be 'x' if ($AsHashtable) { - $json | Should BeOfType Hashtable + $json | Should -BeOfType Hashtable } } It 'Can convert multi-line object with AsHashtable switch set to ' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { Param($AsHashtable) $json = @('{"a" :', '"x"}') | ConvertFrom-Json -AsHashtable:$AsHashtable - $json.a | Should Be 'x' + $json.a | Should -Be 'x' if ($AsHashtable) { - $json | Should BeOfType Hashtable + $json | Should -BeOfType Hashtable } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index 456e189eea8..c3bc8ff1b35 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -15,7 +15,7 @@ def=content of def } catch { - $_.FullyQualifiedErrorId | Should be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + $_.FullyQualifiedErrorId | Should -be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" } } } @@ -28,48 +28,48 @@ bazz = 2 '@ It "Should not throw when called with just the stringdata switch" { - { ConvertFrom-StringData -StringData 'a=b' } | Should Not Throw + { ConvertFrom-StringData -StringData 'a=b' } | Should -Not -Throw } It "Should return a hashtable" { $result = ConvertFrom-StringData -StringData 'a=b' - $result | Should BeOfType Hashtable + $result | Should -BeOfType Hashtable } It "Should throw if not in x=y format" { - { ConvertFrom-StringData -StringData 'ab' } | Should Throw - { ConvertFrom-StringData -StringData 'a,b' } | Should Throw - { ConvertFrom-StringData -StringData 'a b' } | Should Throw - { ConvertFrom-StringData -StringData 'a\tb' } | Should Throw - { ConvertFrom-StringData -StringData 'a:b' } | Should Throw + { ConvertFrom-StringData -StringData 'ab' } | Should -Throw + { ConvertFrom-StringData -StringData 'a,b' } | Should -Throw + { ConvertFrom-StringData -StringData 'a b' } | Should -Throw + { ConvertFrom-StringData -StringData 'a\tb' } | Should -Throw + { ConvertFrom-StringData -StringData 'a:b' } | Should -Throw } It "Should return the data on the left side in the key" { $actualValue = ConvertFrom-StringData -StringData 'a=b' - $actualValue.Keys | Should Be "a" + $actualValue.Keys | Should -Be "a" } It "Should return the data on the right side in the value" { $actualValue = ConvertFrom-StringData -StringData 'a=b' - $actualValue.Values | Should Be "b" + $actualValue.Values | Should -Be "b" } It "Should return a keycollection for the keys" { - $(ConvertFrom-StringData -StringData 'a=b').Keys.PSObject.TypeNames[0] | Should Be "System.Collections.Hashtable+KeyCollection" + $(ConvertFrom-StringData -StringData 'a=b').Keys.PSObject.TypeNames[0] | Should -Be "System.Collections.Hashtable+KeyCollection" } It "Should return a valuecollection for the values" { - $(ConvertFrom-StringData -StringData 'a=b').Values.PSObject.TypeNames[0] | Should Be "System.Collections.Hashtable+ValueCollection" + $(ConvertFrom-StringData -StringData 'a=b').Values.PSObject.TypeNames[0] | Should -Be "System.Collections.Hashtable+ValueCollection" } It "Should work for multiple lines" { - { ConvertFrom-StringData -StringData $sampleData } | Should Not Throw + { ConvertFrom-StringData -StringData $sampleData } | Should -Not -Throw # keys are not order guaranteed - $(ConvertFrom-StringData -StringData $sampleData).Keys | Should BeIn @("foo", "bar", "bazz") + $(ConvertFrom-StringData -StringData $sampleData).Keys | Should -BeIn @("foo", "bar", "bazz") - $(ConvertFrom-StringData -StringData $sampleData).Values | Should BeIn @("0","1","2") + $(ConvertFrom-StringData -StringData $sampleData).Values | Should -BeIn @("0","1","2") } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 index 234108aa926..e76c3a12c25 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 @@ -5,35 +5,35 @@ Describe "ConvertTo-Csv DRT Unit Tests" -Tags "CI" { It "Test convertto-csv with psobject pipelined" { $returnObject = $inputObject | ConvertTo-Csv -IncludeTypeInformation - $returnObject.Count | Should Be 3 - $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should Be "`"First`",`"Second`"" - $returnObject[2] | Should Be "`"1`",`"2`"" + $returnObject.Count | Should -Be 3 + $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -Be "`"First`",`"Second`"" + $returnObject[2] | Should -Be "`"1`",`"2`"" } It "Test convertto-csv with NoTypeInformation and psobject pipelined" { $returnObject = $inputObject | ConvertTo-Csv -NoTypeInformation - $returnObject.Count | Should Be 2 - $returnObject[0] | Should Be "`"First`",`"Second`"" - $returnObject[1] | Should Be "`"1`",`"2`"" + $returnObject.Count | Should -Be 2 + $returnObject[0] | Should -Be "`"First`",`"Second`"" + $returnObject[1] | Should -Be "`"1`",`"2`"" } It "Test convertto-csv with a useculture flag" { #The default value is ',' $returnObject = $inputObject | ConvertTo-Csv -UseCulture -IncludeTypeInformation - $returnObject.Count | Should Be 3 - $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should Be "`"First`",`"Second`"" - $returnObject[2] | Should Be "`"1`",`"2`"" + $returnObject.Count | Should -Be 3 + $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -Be "`"First`",`"Second`"" + $returnObject[2] | Should -Be "`"1`",`"2`"" } It "Test convertto-csv with Delimiter" { #The default value is ',' $returnObject = $inputObject | ConvertTo-Csv -Delimiter ";" -IncludeTypeInformation - $returnObject.Count | Should Be 3 - $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should Be "`"First`";`"Second`"" - $returnObject[2] | Should Be "`"1`";`"2`"" + $returnObject.Count | Should -Be 3 + $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -Be "`"First`";`"Second`"" + $returnObject[2] | Should -Be "`"1`";`"2`"" } } @@ -42,51 +42,51 @@ Describe "ConvertTo-Csv" -Tags "CI" { $testObject = New-Object psobject -Property @{ FirstColumn = $Name; SecondColumn = $Data } It "Should Be able to be called without error" { - { $testObject | ConvertTo-Csv } | Should Not Throw + { $testObject | ConvertTo-Csv } | Should -Not -Throw } It "Should output an array of objects" { $result = $testObject | ConvertTo-Csv - ,$result | Should BeOfType "System.Array" + ,$result | Should -BeOfType "System.Array" } It "Should return the type of data in the first element of the output array" { $result = $testObject | ConvertTo-Csv -IncludeTypeInformation - $result[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" + $result[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" } It "Should return the column info in the second element of the output array" { $result = $testObject | ConvertTo-Csv -IncludeTypeInformation - $result[1] | Should Match "`"FirstColumn`"" - $result[1] | Should Match "`"SecondColumn`"" + $result[1] | Should -Match "`"FirstColumn`"" + $result[1] | Should -Match "`"SecondColumn`"" } It "Should return the data as a comma-separated list in the third element of the output array" { $result = $testObject | ConvertTo-Csv -IncludeTypeInformation - $result[2] | Should Match "`"Hello`"" - $result[2] | Should Match "`"World`"" + $result[2] | Should -Match "`"Hello`"" + $result[2] | Should -Match "`"World`"" } It "Includes type information when -IncludeTypeInformation is supplied" { $result = $testObject | ConvertTo-Csv -IncludeTypeInformation - ($result -split ([Environment]::NewLine))[0] | Should BeExactly "#TYPE System.Management.Automation.PSCustomObject" + ($result -split ([Environment]::NewLine))[0] | Should -BeExactly "#TYPE System.Management.Automation.PSCustomObject" } It "Does not include type information by default" { $result = $testObject | ConvertTo-Csv - $result | Should Not Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) - $result | Should Not Match ([regex]::Escape('#TYPE')) + $result | Should -Not -Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) + $result | Should -Not -Match ([regex]::Escape('#TYPE')) } It "Does not include type information with -NoTypeInformation" { $result = $testObject | ConvertTo-Csv -NoTypeInformation - $result | Should Not Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) - $result | Should Not Match ([regex]::Escape('#TYPE')) + $result | Should -Not -Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) + $result | Should -Not -Match ([regex]::Escape('#TYPE')) } It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index dd1aaa77aa4..98d566ffbd0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -14,7 +14,7 @@ Describe "ConvertTo-Html Tests" -Tags "CI" { It "Test ConvertTo-Html with no parameters" { $returnObject = $customObject | ConvertTo-Html - ,$returnObject | Should BeOfType System.Object[] + ,$returnObject | Should -BeOfType System.Object[] $returnString = $returnObject -join $newLine $expectedValue = normalizeLineEnds @" @@ -29,7 +29,7 @@ Describe "ConvertTo-Html Tests" -Tags "CI" { "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-Html Fragment parameter" { @@ -41,7 +41,7 @@ Describe "ConvertTo-Html Tests" -Tags "CI" { John Doe42System.Object[] "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-Html as List" { @@ -59,7 +59,7 @@ Describe "ConvertTo-Html Tests" -Tags "CI" { "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-Html specified properties" { @@ -76,7 +76,7 @@ Describe "ConvertTo-Html Tests" -Tags "CI" { "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-Html using page parameters" { @@ -96,7 +96,7 @@ Body Text "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-Html pre and post" { @@ -116,7 +116,7 @@ Before the object After the object "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-HTML meta"{ @@ -135,14 +135,14 @@ After the object "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-HTML meta with invalid properties should throw warning" { $parms = @{"authors"="John Doe";"keywords"="PowerShell,PSv6"} # make this a string, rather than an array of string so match will behave [string]$observedProperties = $customObject | ConvertTo-HTML -Meta $parms 3>&1 - $observedProperties | Should Match $parms["authors"] + $observedProperties | Should -Match $parms["authors"] } It "Test ConvertTo-HTML charset"{ @@ -161,12 +161,12 @@ After the object "@ - $returnString | Should Be $expectedValue + $returnString | Should -Be $expectedValue } It "Test ConvertTo-HTML transitional"{ $returnString = $customObject | ConvertTo-HTML -Transitional | Select-Object -First 1 - $returnString | Should Be '' + $returnString | Should -Be '' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 index 092a40baa22..02b56489f02 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 @@ -12,8 +12,8 @@ Describe 'ConvertTo-Json' -tags "CI" { $properties = @{'DictObject' = $dict; 'RandomString' = 'A quick brown fox jumped over the lazy dog'} $object = New-Object -TypeName psobject -Property $properties $jsonFormat = ConvertTo-Json -InputObject $object - $jsonFormat | Should Match '"TestValue1": 123456' - $jsonFormat | Should Match '"TestValue2": 78910' - $jsonFormat | Should Match '"TestValue3": 99999' + $jsonFormat | Should -Match '"TestValue1": 123456' + $jsonFormat | Should -Match '"TestValue2": 78910' + $jsonFormat | Should -Match '"TestValue3": 99999' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1 index 7cec247c7e6..ba3689ee759 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1 @@ -7,7 +7,7 @@ It "Should return System.Security.SecureString after converting plaintext variable"{ #[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")] $PesterTestConvert = (ConvertTo-SecureString "plaintextpester" -AsPlainText -force) - $PesterTestConvert | Should BeOfType securestring + $PesterTestConvert | Should -BeOfType securestring } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 index 4f069c22056..c2f21af6d81 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -11,17 +11,17 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $newLine = [System.Environment]::NewLine It "Test convertto-xml with a depth parameter" { $returnObject = $customPSObject | ConvertTo-Xml -Depth 1 - $returnObject -is [System.Xml.XmlDocument] | Should Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -Be $true #$xml = [System.Xml.XmlDocument]$returnObject $expectedValue = '' + 'val1val2' - $returnObject.OuterXml | Should Be $expectedValue + $returnObject.OuterXml | Should -Be $expectedValue } It "Test convertto-xml with notypeinfo parameter" { $returnObject = $customPSObject | ConvertTo-Xml -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -Be $true $expectedValue = '' + 'val1val2' - $returnObject.OuterXml | Should Be $expectedValue + $returnObject.OuterXml | Should -Be $expectedValue } It "Test convertto-xml as String" { @@ -29,14 +29,14 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $expectedValue = @" $newLine$newLine $newLine val1$newLine val2$newLine $newLine "@ - $returnObject -is [System.String] | Should Be $true - $returnObject | Should Be $expectedValue + $returnObject -is [System.String] | Should -Be $true + $returnObject | Should -Be $expectedValue #$returnObject.Trim($newLine) | Should Be $expectedValue.Trim($newLine) } It "Test convertto-xml as Stream" { $returnObject = $customPSObject | ConvertTo-Xml -As Stream - $returnObject -is [System.Array] | Should Be $true + $returnObject -is [System.Array] | Should -Be $true $stream1 = '' $stream2 = '' $stream3 = @" @@ -44,18 +44,18 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { "@ $stream4 = '' - $returnObject.Count | Should Be 4 - $returnObject[0] | Should Be $stream1 - $returnObject[1] | Should Be $stream2 - $returnObject[2] | Should Be $stream3 - $returnObject[3] | Should Be $stream4 + $returnObject.Count | Should -Be 4 + $returnObject[0] | Should -Be $stream1 + $returnObject[1] | Should -Be $stream2 + $returnObject[2] | Should -Be $stream3 + $returnObject[3] | Should -Be $stream4 } It "Test convertto-xml as Document" { $returnObject = $customPSObject | ConvertTo-Xml -As Document -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -Be $true $expectedValue = 'val1val2' - $returnObject.OuterXml | Should Be $expectedValue + $returnObject.OuterXml | Should -Be $expectedValue } It "StopProcessing should work" { @@ -65,7 +65,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $ps.AddParameter("Depth", 2) $ps.BeginInvoke() $ps.Stop() - $ps.InvocationStateInfo.State | Should Be "Stopped" + $ps.InvocationStateInfo.State | Should -Be "Stopped" } # these tests just cover aspects that aren't normally exercised being used as a cmdlet @@ -74,24 +74,24 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $cmd = [Microsoft.PowerShell.Commands.ConvertToXmlCommand]::new() $cmd.NoTypeInformation = $true - $cmd.NoTypeInformation | Should Be $true + $cmd.NoTypeInformation | Should -Be $true } It "Serialize primitive type" { [int] $i = 1 $x = $i | ConvertTo-Xml - $x.Objects.Object.Type | Should BeExactly $i.GetType().ToString() - $x.Objects.Object."#text" | Should BeExactly $i + $x.Objects.Object.Type | Should -BeExactly $i.GetType().ToString() + $x.Objects.Object."#text" | Should -BeExactly $i } It "Serialize ContainerType.Dictionary type" { $a = @{foo="bar"} $x = $a | ConvertTo-Xml - $x.Objects.Object.Type | Should BeExactly $a.GetType().ToString() - $x.Objects.Object.Property[0].Name | Should BeExactly "Key" - $x.Objects.Object.Property[0]."#text" | Should BeExactly "foo" - $x.Objects.Object.Property[1].Name | Should BeExactly "Value" - $x.Objects.Object.Property[1]."#text" | Should BeExactly "bar" + $x.Objects.Object.Type | Should -BeExactly $a.GetType().ToString() + $x.Objects.Object.Property[0].Name | Should -BeExactly "Key" + $x.Objects.Object.Property[0]."#text" | Should -BeExactly "foo" + $x.Objects.Object.Property[1].Name | Should -BeExactly "Value" + $x.Objects.Object.Property[1]."#text" | Should -BeExactly "bar" } It "Serialize ContainerType.Enumerable type" { @@ -100,13 +100,13 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $fruit2 = [fruit]::new() $fruit2.name = "banana" $x = $fruit1,$fruit2 | ConvertTo-Xml - $x.Objects.Object.Count | Should BeExactly 2 - $x.Objects.Object[0].Type | Should BeExactly $fruit1.GetType().FullName - $x.Objects.Object[0].Property.Name | Should BeExactly "name" - $x.Objects.Object[0].Property."#text" | Should BeExactly "apple" - $x.Objects.Object[1].Type | Should BeExactly $fruit2.GetType().FullName - $x.Objects.Object[1].Property.Name | Should BeExactly "name" - $x.Objects.Object[1].Property."#text" | Should BeExactly "banana" + $x.Objects.Object.Count | Should -BeExactly 2 + $x.Objects.Object[0].Type | Should -BeExactly $fruit1.GetType().FullName + $x.Objects.Object[0].Property.Name | Should -BeExactly "name" + $x.Objects.Object[0].Property."#text" | Should -BeExactly "apple" + $x.Objects.Object[1].Type | Should -BeExactly $fruit2.GetType().FullName + $x.Objects.Object[1].Property.Name | Should -BeExactly "name" + $x.Objects.Object[1].Property."#text" | Should -BeExactly "banana" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 index df5cb2c1422..710a9b660b0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | should -be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -30,7 +30,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | should -be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -41,7 +41,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | should -be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -52,7 +52,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | should -be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 index 0294366cd69..838f33a4842 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 @@ -10,14 +10,14 @@ Describe "Enable and Disable PSBreakpoints" -Tag "CI" { $bp | remove-psbreakpoint } It "Enable-PSBreakpoint should enable the breakpoint" { - $bp.Enabled | should be $false + $bp.Enabled | should -be $false Enable-PSBreakpoint $bp - $bp.Enabled | Should be $true + $bp.Enabled | Should -be $true } It "Disable-PSBreakpoint should disable the breakpoint" { Enable-PSBreakpoint $bp - $bp.Enabled | Should be $true + $bp.Enabled | Should -be $true Disable-PSBreakpoint $bp - $bp.Enabled | Should be $false + $bp.Enabled | Should -be $false } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Environment-Variables.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Environment-Variables.Tests.ps1 index 8ea69c78143..ffde57b88a2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Environment-Variables.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Environment-Variables.Tests.ps1 @@ -3,21 +3,21 @@ Describe "Environment-Variables" -Tags "CI" { It "Should have environment variables" { - Get-Item ENV: | Should Not BeNullOrEmpty + Get-Item ENV: | Should -Not -BeNullOrEmpty } It "Should have a nonempty PATH" { - $ENV:PATH | Should Not BeNullOrEmpty + $ENV:PATH | Should -Not -BeNullOrEmpty } It "Should contain /bin in the PATH" { if ($IsWindows) { - $ENV:PATH | Should Match "C:" + $ENV:PATH | Should -Match "C:" } else { - $ENV:PATH | Should Match "/bin" + $ENV:PATH | Should -Match "/bin" } } @@ -25,21 +25,21 @@ Describe "Environment-Variables" -Tags "CI" { if ($IsWindows) { $expected = "\Users" - Split-Path $ENV:HOMEPATH -Parent | Should Be $expected + Split-Path $ENV:HOMEPATH -Parent | Should -Be $expected } else { $expected = /bin/bash -c "cd ~ && pwd" - $ENV:HOME | Should Be $expected + $ENV:HOME | Should -Be $expected } } It "Should be able to set the environment variables" { $expected = "this is a test environment variable" - { $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should Not Throw + { $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should -Not -Throw - $ENV:TESTENVIRONMENTVARIABLE | Should Not BeNullOrEmpty - $ENV:TESTENVIRONMENTVARIABLE | Should Be $expected + $ENV:TESTENVIRONMENTVARIABLE | Should -Not -BeNullOrEmpty + $ENV:TESTENVIRONMENTVARIABLE | Should -Be $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 index e0c4d8383d5..f8a6b0f0947 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 @@ -10,7 +10,7 @@ Describe "Event Subscriber Tests" -tags "CI" { # can't let this case to work It "Register an event with no action, trigger it and wait for it to be raised." -Pending:$true{ - Get-EventSubscriber | should BeNullOrEmpty + Get-EventSubscriber | should -BeNullOrEmpty $messageData = new-object psobject $job = Start-Job { Start-Sleep -Seconds 5; 1..5 } $eventtest = Register-ObjectEvent $job -EventName StateChanged -SourceIdentifier EventSIDTest -Action {} -MessageData $messageData @@ -18,21 +18,21 @@ Describe "Event Subscriber Tests" -tags "CI" { wait-event EventSIDTest $eventdata = get-event EventSIDTest - $eventdata.MessageData | should Be $messageData + $eventdata.MessageData | should -Be $messageData remove-event EventSIDTest Unregister-Event EventSIDTest - Get-EventSubscriber | should BeNullOrEmpty + Get-EventSubscriber | should -BeNullOrEmpty } It "Access a global variable from an event action." { - Get-EventSubscriber | should BeNullOrEmpty + Get-EventSubscriber | should -BeNullOrEmpty set-variable incomingGlobal -scope global -value globVarValue $eventtest = register-engineevent -SourceIdentifier foo -Action {set-variable -scope global -name aglobalvariable -value $incomingGlobal} new-event foo $getvar = get-variable aglobalvariable -scope global - $getvar.Name | should Be aglobalvariable - $getvar.Value | should Be globVarValue + $getvar.Name | should -Be aglobalvariable + $getvar.Value | should -Be globVarValue Unregister-Event foo - Get-EventSubscriber | should BeNullOrEmpty + Get-EventSubscriber | should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index 4cd16da9f3c..149ffe90f4f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { It "Export-Alias for exist file should work"{ New-Item -Path $fulltestpath -ItemType File -Force - {Export-Alias $fulltestpath}| Should Not Throw + {Export-Alias $fulltestpath}| Should -Not -Throw } It "Export-Alias resolving to multiple files will throw ReadWriteMultipleFilesNotSupported" { @@ -45,7 +45,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" } finally{ Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue @@ -59,52 +59,52 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" } } It "Export-Alias for Default"{ Export-Alias $fulltestpath abcd01 -passthru - $fulltestpath| Should FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -FileContentMatchExactly '"abcd01","efgh01","","None"' } It "Export-Alias As CSV"{ Export-Alias $fulltestpath abcd01 -As CSV -passthru - $fulltestpath| Should FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -FileContentMatchExactly '"abcd01","efgh01","","None"' } It "Export-Alias As CSV With Description"{ Export-Alias $fulltestpath abcd01 -As CSV -description "My Aliases" -passthru - $fulltestpath| Should FileContentMatchExactly '"abcd01","efgh01","","None"' - $fulltestpath| Should FileContentMatchExactly "My Aliases" + $fulltestpath| Should -FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -FileContentMatchExactly "My Aliases" } It "Export-Alias As CSV With Multiline Description"{ Export-Alias $fulltestpath abcd01 -As CSV -description "My Aliases\nYour Aliases\nEveryones Aliases" -passthru - $fulltestpath| Should FileContentMatchExactly '"abcd01","efgh01","","None"' - $fulltestpath| Should FileContentMatchExactly "My Aliases" - $fulltestpath| Should FileContentMatchExactly "Your Aliases" - $fulltestpath| Should FileContentMatchExactly "Everyones Aliases" + $fulltestpath| Should -FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -FileContentMatchExactly "My Aliases" + $fulltestpath| Should -FileContentMatchExactly "Your Aliases" + $fulltestpath| Should -FileContentMatchExactly "Everyones Aliases" } It "Export-Alias As Script"{ Export-Alias $fulltestpath abcd01 -As Script -passthru - $fulltestpath| Should FileContentMatchExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"' + $fulltestpath| Should -FileContentMatchExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"' } It "Export-Alias As Script With Multiline Description"{ Export-Alias $fulltestpath abcd01 -As Script -description "My Aliases\nYour Aliases\nEveryones Aliases" -passthru - $fulltestpath| Should FileContentMatchExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"' - $fulltestpath| Should FileContentMatchExactly "My Aliases" - $fulltestpath| Should FileContentMatchExactly "Your Aliases" - $fulltestpath| Should FileContentMatchExactly "Everyones Aliases" + $fulltestpath| Should -FileContentMatchExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"' + $fulltestpath| Should -FileContentMatchExactly "My Aliases" + $fulltestpath| Should -FileContentMatchExactly "Your Aliases" + $fulltestpath| Should -FileContentMatchExactly "Everyones Aliases" } It "Export-Alias for Force Test"{ Export-Alias $fulltestpath abcd01 Export-Alias $fulltestpath abcd02 -force - $fulltestpath| Should Not FileContentMatchExactly '"abcd01","efgh01","","None"' - $fulltestpath| Should FileContentMatchExactly '"abcd02","efgh02","","None"' + $fulltestpath| Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -FileContentMatchExactly '"abcd02","efgh02","","None"' } It "Export-Alias for Force ReadOnly Test" { @@ -123,12 +123,12 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { throw "No Exception!" } catch{ - $_.FullyQualifiedErrorId | Should be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" } Export-Alias $fulltestpath abcd03 -force - $fulltestpath| Should Not FileContentMatchExactly '"abcd01","efgh01","","None"' - $fulltestpath| Should Not FileContentMatchExactly '"abcd02","efgh02","","None"' - $fulltestpath| Should FileContentMatchExactly '"abcd03","efgh03","","None"' + $fulltestpath| Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath| Should -Not -FileContentMatchExactly '"abcd02","efgh02","","None"' + $fulltestpath| Should -FileContentMatchExactly '"abcd03","efgh03","","None"' if ( $IsWindows ) { @@ -160,12 +160,12 @@ Describe "Export-Alias" -Tags "CI" { It "Should be able to create a file in the specified location"{ Export-Alias $fulltestpath - Test-Path $fulltestpath | Should be $true + Test-Path $fulltestpath | Should -be $true } It "Should create a file with the list of aliases that match the expected list" { Export-Alias $fulltestpath - Test-Path $fulltestpath | Should Be $true + Test-Path $fulltestpath | Should -Be $true $actual = Get-Content $fulltestpath | Sort-Object $expected = Get-Command -CommandType Alias @@ -173,7 +173,7 @@ Describe "Export-Alias" -Tags "CI" { for ( $i=0; $i -lt $expected.Length; $i++) { # We loop through the expected list and not the other because the output writes some comments to the file. - $expected[$i] | Should Match $actual[$i].Name + $expected[$i] | Should -Match $actual[$i].Name } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 index 11ad3091c43..2cc97edf64b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 @@ -11,7 +11,7 @@ Describe "Export-Csv" -Tags "CI" { } It "Should be able to be called without error" { - { $testObject | Export-Csv $testCsv -ErrorAction Stop } | Should Not Throw + { $testObject | Export-Csv $testCsv -ErrorAction Stop } | Should -Not -Throw } It "Should throw if an output file isn't specified" { @@ -23,7 +23,7 @@ Describe "Export-Csv" -Tags "CI" { $piped = Get-Content $testCsv - $piped[0] | Should BeExactly "#TYPE System.String" + $piped[0] | Should -BeExactly "#TYPE System.String" } It "Should be an object when exporting via the inputObject switch" { @@ -31,7 +31,7 @@ Describe "Export-Csv" -Tags "CI" { $switch = Get-Content $testCsv - $switch[0] | Should BeExactly "#TYPE System.Object[]" + $switch[0] | Should -BeExactly "#TYPE System.Object[]" } It "Should output a csv file containing a string of all the lengths of each element when piped input is used" { @@ -43,28 +43,28 @@ Describe "Export-Csv" -Tags "CI" { $expected = @("#TYPE System.String", "`"Length`"", $first , $second, $third) for ($i = 0; $i -lt $expected.Count; $i++) { - $(Get-Content $testCsv)[$i] | Should Be $expected[$i] + $(Get-Content $testCsv)[$i] | Should -Be $expected[$i] } } It "Does not include type information by default" { $testObject | Export-Csv -Path $testCsv - $(Get-Content $testCsv)[0] | Should Not Match ([regex]::Escape("System.String")) - $(Get-Content $testCsv)[0] | Should Not Match ([regex]::Escape("#TYPE")) + $(Get-Content $testCsv)[0] | Should -Not -Match ([regex]::Escape("System.String")) + $(Get-Content $testCsv)[0] | Should -Not -Match ([regex]::Escape("#TYPE")) } It "Does not include type information with -NoTypeInformation" { $testObject | Export-Csv -Path $testCsv -NoTypeInformation - $(Get-Content $testCsv)[0] | Should Not Match ([regex]::Escape("System.String")) - $(Get-Content $testCsv)[0] | Should Not Match ([regex]::Escape("#TYPE")) + $(Get-Content $testCsv)[0] | Should -Not -Match ([regex]::Escape("System.String")) + $(Get-Content $testCsv)[0] | Should -Not -Match ([regex]::Escape("#TYPE")) } It "Includes type information when -IncludeTypeInformation is supplied" { $testObject | Export-Csv -Path $testCsv -IncludeTypeInformation - $(Get-Content $testCsv)[0] | Should BeExactly "#TYPE System.String" + $(Get-Content $testCsv)[0] | Should -BeExactly "#TYPE System.String" } It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" { @@ -83,9 +83,9 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input = [pscustomobject]@{ "P1" = "V11"; "P2" = "V12"; "P3" = "V13" } $input | Export-Csv -Path $filePath -NoTypeInformation $results = Import-Csv $filePath - $results.P1 | Should Be "V11" - $results.P2 | Should Be "V12" - $results.P3 | Should Be "V13" + $results.P1 | Should -Be "V11" + $results.P2 | Should -Be "V12" + $results.P3 | Should -Be "V13" } It "Test if it works with special character" { @@ -93,9 +93,9 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input = [pscustomobject]@{ "P1" = " "; "P2" = "abc,foo"; "P3" = $v3} $input | Export-Csv -Path $filePath -NoTypeInformation $results = Import-Csv $filePath - $results.P1 | Should Be " " - $results.P2 | Should Be "abc,foo" - $results.P3 | Should Be $v3 + $results.P1 | Should -Be " " + $results.P2 | Should -Be "abc,foo" + $results.P3 | Should -Be $v3 } It "Test force switch works well" { @@ -106,9 +106,9 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input | Export-Csv -Path $filePath -Force $results = Import-Csv $filePath - $results.P2 | Should be "second" + $results.P2 | Should -be "second" $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } - $property | should not be P1 + $property | should -not -be P1 } It "Test export-csv with a useculture flag" { @@ -118,8 +118,8 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { New-Item -Path $outputFilesDir -ItemType Directory -Force Get-Item -Path $outputFilesDir| Export-Csv -Path $fileToGenerate -UseCulture -NoTypeInformation $contents = Get-Content -Path $fileToGenerate - $contents.Count | Should Be 2 - $contents[0].Contains($delimiter) | Should Be $true - $contents[1].Contains($delimiter) | Should Be $true + $contents.Count | Should -Be 2 + $contents[0].Contains($delimiter) | Should -Be $true + $contents[1].Contains($delimiter) | Should -Be $true } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index 457074cde68..cc2d6067e88 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -8,10 +8,10 @@ Describe "Export-FormatData DRT Unit Tests" -Tags "CI" { $content = Get-Content $tempFile $formatViewDefinition = $fd[0].FormatViewDefinition $typeName = $fd[0].TypeName - $content.Contains($typeName) | Should Be $true + $content.Contains($typeName) | Should -Be $true for ($i = 0; $i -lt $formatViewDefinition.Count;$i++) { - $content.Contains($formatViewDefinition[$i].Name) | Should Be $true + $content.Contains($formatViewDefinition[$i].Name) | Should -Be $true } } } @@ -26,7 +26,7 @@ Describe "Export-FormatData" -Tags "CI" { Context "Check Export-FormatData can be called validly." { It "Should be able to be called without error" { - { Get-FormatData | Export-FormatData -Path $testOutput } | Should Not Throw + { Get-FormatData | Export-FormatData -Path $testOutput } | Should -Not -Throw } } @@ -34,13 +34,13 @@ Describe "Export-FormatData" -Tags "CI" { It "Should not return an empty xml file" { Get-FormatData | Export-FormatData -Path $testOutput $piped = Get-Content $testOutput - $piped | Should Not Be "" + $piped | Should -Not -Be "" } It "Should have a valid xml tag at the start of the file" { Get-FormatData | Export-FormatData -Path $testOutput $piped = Get-Content $testOutput - $piped[0] | Should Be "<" + $piped[0] | Should -Be "<" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 index 0e7380cb697..f22ac7294b7 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 @@ -7,7 +7,7 @@ Describe "Format-Custom" -Tags "CI" { It "Should have the same output between the alias and the unaliased function" { $nonaliased = Get-FormatData | Format-Custom $aliased = Get-FormatData | fc - $($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0 + $($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should -Be 0 } } @@ -15,12 +15,12 @@ Describe "Format-Custom" -Tags "CI" { It "Should be able to specify the depth in output" { $getprocesspester = Get-FormatData | Format-Custom -depth 1 - ($getprocesspester).Count | Should BeGreaterThan 0 + ($getprocesspester).Count | Should -BeGreaterThan 0 } It "Should be able to use the Property flag to select properties" { $CommandName = Get-Command | Format-Custom -Property "Name" - $CommandName | Should Not Match "Source" + $CommandName | Should -Not -Match "Source" } } @@ -69,10 +69,10 @@ Describe "Format-Custom DRT basic functionality" -Tags "CI" { $testObject.subObjectValue.array = (0..63) $testObject.subObjectValue.stringarray = @("one","two") $result = $testObject | Format-Custom | Out-String - $result | Should Match $expectResult1 - $result | Should Match $expectResult2 - $result | Should Match "one" - $result | Should Match "two" + $result | Should -Match $expectResult1 + $result | Should -Match $expectResult2 + $result | Should -Match "one" + $result | Should -Match "two" } It "Format-Custom with Tree Object should work" { @@ -201,7 +201,7 @@ class MyContainer1 $result = $objectList | Format-Custom | Out-String $result = $result -replace "[{} `n\r]","" $expectedResult = $expectedResult -replace "[{} `n\r]","" - $result | Should Be $expectedResult + $result | Should -Be $expectedResult } It "Format-Custom with Empty Data Tree Object should work" { @@ -223,7 +223,7 @@ class MyContainer1 $result = $objectList | Format-Custom | Out-String $result = $result -replace "[{} `n\r]","" $expectedResult = $expectedResult -replace "[{} `n\r]","" - $result | Should Be $expectedResult + $result | Should -Be $expectedResult } It "Format-Custom with Back Pointers Tree Object should work" { @@ -266,7 +266,7 @@ class MyContainer1 $result = $objectList | Format-Custom | Out-String $result = $result -replace "[{} `n\r]","" $expectedResult = $expectedResult -replace "[{} `n\r]","" - $result | Should Be $expectedResult + $result | Should -Be $expectedResult } It "Format-Custom with Leaf Only Data should work" { @@ -296,6 +296,6 @@ class MyLeaf2 $result = $objectList | Format-Custom | Out-String $result = $result -replace "[{} `n\r]","" $expectedResult = $expectedResult -replace "[{} `n\r]","" - $result | Should Be $expectedResult + $result | Should -Be $expectedResult } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 index 33695000260..03ff9cdba8d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 @@ -8,18 +8,18 @@ Describe "Format-List" -Tags "CI" { } It "Should call format list without error" { - { $in | Format-List } | Should Not BeNullOrEmpty + { $in | Format-List } | Should -Not -BeNullOrEmpty } It "Should be able to call the alias" { - { $in | fl } | Should Not BeNullOrEmpty + { $in | fl } | Should -Not -BeNullOrEmpty } It "Should have the same output whether choosing alias or not" { $expected = $in | Format-List | Out-String $actual = $in | fl | Out-String - $actual | Should Be $expected + $actual | Should -Be $expected } It "Should produce the expected output" { @@ -27,44 +27,44 @@ Describe "Format-List" -Tags "CI" { $in = New-Object PSObject Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue - $in | Format-List | Should Not BeNullOrEmpty - $in | Format-List | Out-String | Should Not BeNullOrEmpty - $in | Format-List | Out-String | Should Be $expected + $in | Format-List | Should -Not -BeNullOrEmpty + $in | Format-List | Out-String | Should -Not -BeNullOrEmpty + $in | Format-List | Out-String | Should -Be $expected } It "Should be able to call a property of the piped input" { # Tested on two input commands to verify functionality. - { Get-Command | Select-Object -First 5 | Format-List -Property Name } | Should Not BeNullOrEmpty + { Get-Command | Select-Object -First 5 | Format-List -Property Name } | Should -Not -BeNullOrEmpty - { Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty + { Get-Date | Format-List -Property DisplayName } | Should -Not -BeNullOrEmpty } It "Should be able to display a list of props when separated by a comma" { (Get-Command | Select-Object -First 5 | Format-List -Property Name,Source | Out-String) -Split "${nl}" | Where-Object { $_.trim() -ne "" } | - ForEach-Object { $_ | Should Match "(Name)|(Source)" } + ForEach-Object { $_ | Should -Match "(Name)|(Source)" } } It "Should show the requested prop in every element" { # Testing each element of format-list, using a for-each loop since the Format-List is so opaque (Get-Command | Select-Object -First 5 | Format-List -Property Source | Out-String) -Split "${nl}" | Where-Object { $_.trim() -ne "" } | - ForEach-Object { $_ | Should Match "Source :" } + ForEach-Object { $_ | Should -Match "Source :" } } It "Should not show anything other than the requested props" { $output = Get-Command | Select-Object -First 5 | Format-List -Property Name | Out-String - $output | Should Not Match "CommandType :" - $output | Should Not Match "Source :" - $output | Should Not Match "Module :" + $output | Should -Not -Match "CommandType :" + $output | Should -Not -Match "Source :" + $output | Should -Not -Match "Module :" } It "Should be able to take input without piping objects to it" { $output = { Format-List -InputObject $in } - $output | Should Not BeNullOrEmpty + $output | Should -Not -BeNullOrEmpty } } @@ -75,37 +75,37 @@ Describe "Format-List DRT basic functionality" -Tags "CI" { $info = @{} $info.array = $al $result = $info | Format-List | Out-String - $result | Should Match "Name : array\s+Value : {0, 1, 2, 3...}" + $result | Should -Match "Name : array\s+Value : {0, 1, 2, 3...}" } It "Format-List with No Objects for End-To-End should work"{ $p = @{} $result = $p | Format-List -Force -Property "foo","bar" | Out-String - $result.Trim() | Should BeNullOrEmpty + $result.Trim() | Should -BeNullOrEmpty } It "Format-List with Null Objects for End-To-End should work"{ $p = $null $result = $p | Format-List -Force -Property "foo","bar" | Out-String - $result.Trim() | Should BeNullOrEmpty + $result.Trim() | Should -BeNullOrEmpty } It "Format-List with single line string for End-To-End should work"{ $p = "single line string" $result = $p | Format-List -Force -Property "foo","bar" | Out-String - $result.Trim() | Should BeNullOrEmpty + $result.Trim() | Should -BeNullOrEmpty } It "Format-List with multiple line string for End-To-End should work"{ $p = "Line1\nLine2" $result = $p | Format-List -Force -Property "foo","bar" | Out-String - $result.Trim() | Should BeNullOrEmpty + $result.Trim() | Should -BeNullOrEmpty } It "Format-List with string sequence for End-To-End should work"{ $p = "Line1","Line2" $result = $p | Format-List -Force -Property "foo","bar" | Out-String - $result.Trim() | Should BeNullOrEmpty + $result.Trim() | Should -BeNullOrEmpty } It "Format-List with complex object for End-To-End should work" { @@ -117,26 +117,26 @@ Describe "Format-List DRT basic functionality" -Tags "CI" { $info.enumerable = [MyDayOfWeek]$eto $info.enumerableTestObject = $eto $result = $info|Format-List|Out-String - $result | Should Match "Name : enumerableTestObject" - $result | Should Match "Value : Sun" - $result | Should Match "Name : arrayList" - $result | Should Match "Value : {string1, string2}" - $result | Should Match "Name : enumerable" - $result | Should Match "Value : Sun" - $result | Should Match "Name : intArray" - $result | Should Match "Value : {1, 2, 3, 4}" + $result | Should -Match "Name : enumerableTestObject" + $result | Should -Match "Value : Sun" + $result | Should -Match "Name : arrayList" + $result | Should -Match "Value : {string1, string2}" + $result | Should -Match "Name : enumerable" + $result | Should -Match "Value : Sun" + $result | Should -Match "Name : intArray" + $result | Should -Match "Value : {1, 2, 3, 4}" } It "Format-List with multiple same class object should work"{ Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}" $testobjects = [TestClass]::New('name1',1),[TestClass]::New('name2',2),[TestClass]::New('name3',3) $result = $testobjects|Format-List|Out-String - $result | Should Match "Name : name1" - $result | Should Match "Length : 1" - $result | Should Match "Name : name2" - $result | Should Match "Length : 2" - $result | Should Match "Name : name3" - $result | Should Match "Length : 3" + $result | Should -Match "Name : name1" + $result | Should -Match "Length : 1" + $result | Should -Match "Name : name2" + $result | Should -Match "Length : 2" + $result | Should -Match "Name : name3" + $result | Should -Match "Length : 3" } It "Format-List with multiple different class object should work"{ @@ -144,19 +144,19 @@ Describe "Format-List DRT basic functionality" -Tags "CI" { Add-Type -TypeDefinition "public class TestClass2{public TestClass2(string name,string value,int length){Name = name;Value = value; Length = length;}public string Name;public string Value;public int Length;}" $testobjects = [TestClass]::New('name1',1),[TestClass2]::New('name2',"value2",2),[TestClass]::New('name3',3) $result = $testobjects|Format-List|Out-String - $result | Should Match "Name : name1" - $result | Should Match "Length : 1" - $result | Should Match "Name : name2" - $result | Should Match "Value : value2" - $result | Should Match "Length : 2" - $result | Should Match "Name : name3" - $result | Should Match "Length : 3" + $result | Should -Match "Name : name1" + $result | Should -Match "Length : 1" + $result | Should -Match "Name : name2" + $result | Should -Match "Value : value2" + $result | Should -Match "Length : 2" + $result | Should -Match "Name : name3" + $result | Should -Match "Length : 3" } It "Format-List with FileInfo should work" { $null = New-Item $testdrive\test.txt -ItemType File -Value "hello" -Force $result = Get-ChildItem -File $testdrive\test.txt | Format-List | Out-String - $result | Should Match "Name\s*:\s*test.txt" - $result | Should Match "Length\s*:\s*5" + $result | Should -Match "Name\s*:\s*test.txt" + $result | Should -Match "Length\s*:\s*5" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 62bbd83c83a..e2d2e5fef6b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -2,9 +2,9 @@ # Licensed under the MIT License. Describe "Format-Table" -Tags "CI" { It "Should call format table on piped input without error" { - { Get-Date | Format-Table } | Should Not Throw + { Get-Date | Format-Table } | Should -Not -Throw - { Get-Date | ft } | Should Not Throw + { Get-Date | ft } | Should -Not -Throw } It "Should return a format object data type" { @@ -12,9 +12,9 @@ Describe "Format-Table" -Tags "CI" { $val2 = (Get-Date | Format-Table | gm ) - $val.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format" + $val.TypeName | Should -Match "Microsoft.Powershell.Commands.Internal.Format" - $val2.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format" + $val2.TypeName | Should -Match "Microsoft.Powershell.Commands.Internal.Format" } It "Should be able to be called with optional parameters" { @@ -39,8 +39,8 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "PipelineStoppedException" - $_.FullyQualifiedErrorId | Should be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $_.CategoryInfo | Should -Match "PipelineStoppedException" + $_.FullyQualifiedErrorId | Should -be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" } } @@ -49,14 +49,14 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $info = @{} $info.array = $al $result = $info|Format-Table|Out-String - $result | Should Match "array\s+{0, 1, 2, 3...}" + $result | Should -Match "array\s+{0, 1, 2, 3...}" } It "Format-Table with Negative Count should work" { $FormatEnumerationLimit = -1 $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1, 2}" + $resultStr | Should -Match "test\s+{1, 2}" } # Pending on issue#888 @@ -64,28 +64,28 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $FormatEnumerationLimit = 0 $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{...}" + $resultStr | Should -Match "test\s+{...}" } It "Format-Table with Less Count should work" { $FormatEnumerationLimit = 1 $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1...}" + $resultStr | Should -Match "test\s+{1...}" } It "Format-Table with More Count should work" { $FormatEnumerationLimit = 10 $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1, 2}" + $resultStr | Should -Match "test\s+{1, 2}" } It "Format-Table with Equal Count should work" { $FormatEnumerationLimit = 2 $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1, 2}" + $resultStr | Should -Match "test\s+{1, 2}" } # Pending on issue#888 @@ -93,7 +93,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $FormatEnumerationLimit = "abc" $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1, 2}" + $resultStr | Should -Match "test\s+{1, 2}" } # Pending on issue#888 @@ -102,14 +102,14 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { Remove-Variable FormatEnumerationLimit $result = Format-Table -inputobject @{'test'= 1, 2} $resultStr = $result|Out-String - $resultStr | Should Match "test\s+{1, 2}" + $resultStr | Should -Match "test\s+{1, 2}" } It "Format-Table with new line should work" { $info = @{} $info.name = "1\n2" $result = $info|Format-Table|Out-String - $result | Should Match "name\s+1.+2" + $result | Should -Match "name\s+1.+2" } It "Format-Table with ExposeBug920454 should work" { @@ -121,7 +121,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $info = @{} $info.test = $IPs $result = $info|Format-Table|Out-String - $result | Should Match "test\s+{1.1.1.1, 4fde::2:22:f376:ff3b:ab3f}" + $result | Should -Match "test\s+{1.1.1.1, 4fde::2:22:f376:ff3b:ab3f}" } It "Format-Table with Autosize should work" { @@ -131,10 +131,10 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $IPs.Add($IP1) $IPs.Add($IP2) $result = $IPs|Format-Table -Autosize|Out-String - $result | Should Match "name size booleanValue" - $result | Should Match "---- ---- ------------" - $result | Should Match "Bob\s+1234\s+True" - $result | Should Match "Jim\s+5678\s+False" + $result | Should -Match "name size booleanValue" + $result | Should -Match "---- ---- ------------" + $result | Should -Match "Bob\s+1234\s+True" + $result | Should -Match "Jim\s+5678\s+False" } It "Format-Table with '' should return `$null" -TestCases @( @@ -143,7 +143,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { ) { param ($testObject) $result = $testObject | Format-Table -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Format-Table with '' string and -Force should output table with requested properties" -TestCases @( @@ -153,7 +153,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { ) { param ($testString) $result = $testString | Format-Table -Property "foo","bar" -Force | Out-String - $result.Replace(" ","").Replace([Environment]::NewLine,"") | Should BeExactly "foobar------" + $result.Replace(" ","").Replace([Environment]::NewLine,"") | Should -BeExactly "foobar------" } It "Format-Table with complex object for End-To-End should work" { @@ -165,10 +165,10 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $info.enumerable = [MyDayOfWeek]$eto $info.enumerableTestObject = $eto $result = $info|Format-Table|Out-String - $result | Should Match "intArray\s+{1, 2, 3, 4}" - $result | Should Match "arrayList\s+{string1, string2}" - $result | Should Match "enumerable\s+Sun" - $result | Should Match "enumerableTestObject\s+Sun" + $result | Should -Match "intArray\s+{1, 2, 3, 4}" + $result | Should -Match "arrayList\s+{string1, string2}" + $result | Should -Match "enumerable\s+Sun" + $result | Should -Match "enumerableTestObject\s+Sun" } It "Format-Table with Expand Enumerable should work" { @@ -179,26 +179,26 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { $objs.Add($obj2) $mo = [PSCustomObject]@{name = "this is name";sub = $objs} $result1 = $mo|Format-Table -Expand CoreOnly|Out-String - $result1 | Should Match "name\s+sub" - $result1 | Should Match "this is name" + $result1 | Should -Match "name\s+sub" + $result1 | Should -Match "this is name" $result2 = $mo|Format-Table -Expand EnumOnly|Out-String - $result2 | Should Match "name\s+sub" - $result2 | Should Match "this is name\s+{x 0 y 0, x 1 y 1}" + $result2 | Should -Match "name\s+sub" + $result2 | Should -Match "this is name\s+{x 0 y 0, x 1 y 1}" $result3 = $mo|Format-Table -Expand Both|Out-String - $result3 | Should Match "name\s+sub" - $result3 | Should Match "this is name\s+{x 0 y 0, x 1 y 1}" + $result3 | Should -Match "name\s+sub" + $result3 | Should -Match "this is name\s+{x 0 y 0, x 1 y 1}" } It "Format-Table should not add trailing whitespace to the header" { $out = "hello" | Format-Table -Property foo -Force | Out-String - $out.Replace([System.Environment]::NewLine, "") | Should BeExactly "foo---" + $out.Replace([System.Environment]::NewLine, "") | Should -BeExactly "foo---" } It "Format-Table should not add trailing whitespace to rows" { $out = [pscustomobject]@{a=1;b=2} | Format-Table -HideTableHeaders | Out-String - $out.Replace([System.Environment]::NewLine, "") | Should BeExactly "1 2" + $out.Replace([System.Environment]::NewLine, "") | Should -BeExactly "1 2" } It "Format-Table should have correct alignment" { @@ -268,7 +268,7 @@ Left Center Right "@ - $output.Replace("`n","").Replace("`r","") | Should BeExactly $expectedTable.Replace("`n","").Replace("`r","") + $output.Replace("`n","").Replace("`r","") | Should -BeExactly $expectedTable.Replace("`n","").Replace("`r","") } It "Format-Table should not have trailing whitespace if there is truncation: " -TestCases @( @@ -344,6 +344,6 @@ Left Center Right $object | Format-Table -View $view | Out-String } ).AddArgument($ps1xmlPath).AddArgument($view).AddArgument($object) | Out-Null $output = $ps.Invoke() - $output.Replace("`n","").Replace("`r","") | Should BeExactly $expected + $output.Replace("`n","").Replace("`r","") | Should -BeExactly $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 index fe7b1dca727..1011125acf6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 @@ -6,23 +6,23 @@ Describe "Format-Wide" -Tags "CI" { $nonaliased = Get-ChildItem | Format-Wide $aliased = Get-ChildItem | fw - $($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0 + $($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should -Be 0 } It "Should be able to specify the columns in output using the column switch" { - { Get-ChildItem | Format-Wide -Column 3 } | Should Not Throw + { Get-ChildItem | Format-Wide -Column 3 } | Should -Not -Throw } It "Should be able to use the autosize switch" { - { Get-ChildItem | Format-Wide -Autosize } | Should Not Throw + { Get-ChildItem | Format-Wide -Autosize } | Should -Not -Throw } It "Should be able to take inputobject instead of pipe" { - { Format-Wide -InputObject $(Get-ChildItem) } | Should Not Throw + { Format-Wide -InputObject $(Get-ChildItem) } | Should -Not -Throw } It "Should be able to use the property switch" { - { Format-Wide -InputObject $(Get-ChildItem) -Property Mode } | Should Not Throw + { Format-Wide -InputObject $(Get-ChildItem) -Property Mode } | Should -Not -Throw } It "Should throw an error when property switch and view switch are used together" { @@ -33,12 +33,12 @@ Describe "Format-Wide" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" + $_.FullyQualifiedErrorId | Should -be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" } } It "Should throw and suggest proper input when view is used with invalid input without the property switch" { - { Format-Wide -InputObject $(Get-Process) -View aoeu } | Should Throw + { Format-Wide -InputObject $(Get-Process) -View aoeu } | Should -Throw } } @@ -48,39 +48,39 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" { $info = @{} $info.array = $al $result = $info | Format-Wide | Out-String - $result | Should Match "array" + $result | Should -Match "array" } It "Format-Wide with No Objects for End-To-End should work"{ $p = @{} $result = $p | Format-Wide | Out-String - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Format-Wide with Null Objects for End-To-End should work"{ $p = $null $result = $p | Format-Wide | Out-String - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Format-Wide with single line string for End-To-End should work"{ $p = "single line string" $result = $p | Format-Wide | Out-String - $result | Should Match $p + $result | Should -Match $p } It "Format-Wide with multiple line string for End-To-End should work"{ $p = "Line1\nLine2" $result = $p | Format-Wide | Out-String - $result | Should Match "Line1" - $result | Should Match "Line2" + $result | Should -Match "Line1" + $result | Should -Match "Line2" } It "Format-Wide with string sequence for End-To-End should work"{ $p = "Line1","Line2" $result = $p |Format-Wide | Out-String - $result | Should Match "Line1" - $result | Should Match "Line2" + $result | Should -Match "Line1" + $result | Should -Match "Line2" } It "Format-Wide with complex object for End-To-End should work" { @@ -92,10 +92,10 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" { $info.enumerable = [MyDayOfWeek]$eto $info.enumerableTestObject = $eto $result = $info|Format-Wide|Out-String - $result | Should Match "intArray" - $result | Should Match "arrayList" - $result | Should Match "enumerable" - $result | Should Match "enumerableTestObject" + $result | Should -Match "intArray" + $result | Should -Match "arrayList" + $result | Should -Match "enumerable" + $result | Should -Match "enumerableTestObject" } It "Format-Wide with multiple same class object with grouping should work"{ @@ -108,9 +108,9 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" { $testobject1.GroupingKey = "bar" $testobjects = @($testobject1,$testobject2,$testobject3) $result = $testobjects|Format-Wide -GroupBy GroupingKey|Out-String - $result | Should Match "GroupingKey: bar" - $result | Should Match "name1" - $result | Should Match " GroupingKey:" - $result | Should Match "name2\s+name3" + $result | Should -Match "GroupingKey: bar" + $result | Should -Match "name1" + $result | Should -Match " GroupingKey:" + $result | Should -Match "name2\s+name3" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 index eeb26f0f88a..cdf9f7d3154 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 @@ -105,9 +105,9 @@ Describe "FormatHex" -tags "CI" { $result = Format-Hex -InputObject $InputObject - $result.count | Should Be $Count - $result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' - $result.ToString() | Should MatchExactly $ExpectedResult + $result.count | Should -Be $Count + $result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result.ToString() | Should -MatchExactly $ExpectedResult } } @@ -179,13 +179,13 @@ Describe "FormatHex" -tags "CI" { $result = $InputObject | Format-Hex - $result.count | Should Be $Count - $result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' - $result[0].ToString() | Should MatchExactly $ExpectedResult + $result.count | Should -Be $Count + $result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result[0].ToString() | Should -MatchExactly $ExpectedResult if ($result.count -gt 1) { - $result[1].ToString() | Should MatchExactly $ExpectedSecondResult + $result[1].ToString() | Should -MatchExactly $ExpectedSecondResult } } } @@ -246,12 +246,12 @@ Describe "FormatHex" -tags "CI" { $result = Format-Hex -LiteralPath $Path } - $result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' - $result[0].ToString() | Should MatchExactly $ExpectedResult + $result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result[0].ToString() | Should -MatchExactly $ExpectedResult if ($result.count -gt 1) { - $result[1].ToString() | Should MatchExactly $ExpectedSecondResult + $result[1].ToString() | Should -MatchExactly $ExpectedSecondResult } } } @@ -302,9 +302,9 @@ Describe "FormatHex" -tags "CI" { $result = Format-Hex -InputObject 'hello' -Encoding $Encoding - $result.count | Should Be $Count - $result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' - $result[0].ToString() | Should MatchExactly $ExpectedResult + $result.count | Should -Be $Count + $result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result[0].ToString() | Should -MatchExactly $ExpectedResult } } @@ -348,7 +348,7 @@ Describe "FormatHex" -tags "CI" { $thrownError = $_ } - $thrownError.FullyQualifiedErrorId | Should MatchExactly $ExpectedFullyQualifiedErrorId + $thrownError.FullyQualifiedErrorId | Should -MatchExactly $ExpectedFullyQualifiedErrorId } } @@ -390,10 +390,10 @@ Describe "FormatHex" -tags "CI" { $output = Format-Hex -LiteralPath $InvalidPath, $inputFile1 -ErrorVariable errorThrown -ErrorAction SilentlyContinue } - $errorThrown.FullyQualifiedErrorId | Should MatchExactly $ExpectedFullyQualifiedErrorId + $errorThrown.FullyQualifiedErrorId | Should -MatchExactly $ExpectedFullyQualifiedErrorId - $output.Length | Should Be 1 - $output[0].ToString() | Should MatchExactly $inputText1 + $output.Length | Should -Be 1 + $output[0].ToString() | Should -MatchExactly $inputText1 } } @@ -403,40 +403,40 @@ Describe "FormatHex" -tags "CI" { $result = Format-Hex $inputFile1 - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' $actualResult = $result.ToString() - $actualResult | Should MatchExactly $inputText1 + $actualResult | Should -MatchExactly $inputText1 } It "Validate file input from Pipeline 'Get-ChildItem `$inputFile1 | Format-Hex'" { $result = Get-ChildItem $inputFile1 | Format-Hex - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' $actualResult = $result.ToString() - $actualResult | Should MatchExactly $inputText1 + $actualResult | Should -MatchExactly $inputText1 } It "Validate that streamed text does not have buffer underrun problems ''a' * 30 | Format-Hex'" { $result = "a" * 30 | Format-Hex - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' - $result.ToString() | Should MatchExactly "00000000 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa`r`n00000010 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaa " + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType 'Microsoft.PowerShell.Commands.ByteCollection' + $result.ToString() | Should -MatchExactly "00000000 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa`r`n00000010 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaa " } It "Validate that files do not have buffer underrun problems 'Format-Hex -path `$InputFile4'" { $result = Format-Hex -path $InputFile4 - $result | Should Not BeNullOrEmpty - $result.Count | Should Be 3 - $result[0].ToString() | Should MatchExactly "00000000 4E 6F 77 20 69 73 20 74 68 65 20 77 69 6E 74 65 Now is the winte" - $result[1].ToString() | Should MatchExactly "00000010 72 20 6F 66 20 6F 75 72 20 64 69 73 63 6F 6E 74 r of our discont" - $result[2].ToString() | Should MatchExactly "00000020 65 6E 74 ent " + $result | Should -Not -BeNullOrEmpty + $result.Count | Should -Be 3 + $result[0].ToString() | Should -MatchExactly "00000000 4E 6F 77 20 69 73 20 74 68 65 20 77 69 6E 74 65 Now is the winte" + $result[1].ToString() | Should -MatchExactly "00000010 72 20 6F 66 20 6F 75 72 20 64 69 73 63 6F 6E 74 r of our discont" + $result[2].ToString() | Should -MatchExactly "00000020 65 6E 74 ent " } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 118326da91f..2fc6ad93a6e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias OutOfRange Scope"{ @@ -17,87 +17,87 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Named Single Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Get-Alias Positional Single Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Get-Alias Named Multiple Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name AEFG -Value "bar" $result=Get-Alias -Name ABCD,AEFG - $result[0].Name| Should Be "ABCD" - $result[0].Definition| Should Be "foo" - $result[0].Description| Should Be "" - $result[0].Options| Should Be "None" - $result[1].Name| Should Be "AEFG" - $result[1].Definition| Should Be "bar" - $result[1].Description| Should Be "" - $result[1].Options| Should Be "None" + $result[0].Name| Should -Be "ABCD" + $result[0].Definition| Should -Be "foo" + $result[0].Description| Should -Be "" + $result[0].Options| Should -Be "None" + $result[1].Name| Should -Be "AEFG" + $result[1].Definition| Should -Be "bar" + $result[1].Description| Should -Be "" + $result[1].Options| Should -Be "None" } It "Get-Alias Named Wildcard Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias -Name ABC* - $result[0].Name| Should Be "ABCD" - $result[0].Definition| Should Be "foo" - $result[0].Description| Should Be "" - $result[0].Options| Should Be "None" - $result[1].Name| Should Be "ABCG" - $result[1].Definition| Should Be "bar" - $result[1].Description| Should Be "" - $result[1].Options| Should Be "None" + $result[0].Name| Should -Be "ABCD" + $result[0].Definition| Should -Be "foo" + $result[0].Description| Should -Be "" + $result[0].Options| Should -Be "None" + $result[1].Name| Should -Be "ABCG" + $result[1].Definition| Should -Be "bar" + $result[1].Description| Should -Be "" + $result[1].Options| Should -Be "None" } It "Get-Alias Positional Wildcard Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias ABC* - $result[0].Name| Should Be "ABCD" - $result[0].Definition| Should Be "foo" - $result[0].Description| Should Be "" - $result[0].Options| Should Be "None" - $result[1].Name| Should Be "ABCG" - $result[1].Definition| Should Be "bar" - $result[1].Description| Should Be "" - $result[1].Options| Should Be "None" + $result[0].Name| Should -Be "ABCD" + $result[0].Definition| Should -Be "foo" + $result[0].Description| Should -Be "" + $result[0].Options| Should -Be "None" + $result[1].Name| Should -Be "ABCG" + $result[1].Definition| Should -Be "bar" + $result[1].Description| Should -Be "" + $result[1].Options| Should -Be "None" } It "Get-Alias Named Wildcard And Exclude Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias -Name ABC* -Exclude "*BCG" - $result[0].Name| Should Be "ABCD" - $result[0].Definition| Should Be "foo" - $result[0].Description| Should Be "" - $result[0].Options| Should Be "None" + $result[0].Name| Should -Be "ABCD" + $result[0].Definition| Should -Be "foo" + $result[0].Description| Should -Be "" + $result[0].Options| Should -Be "None" } It "Get-Alias Scope Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" Set-Alias -Name ABCD -Value "localfoo" -scope local $result=Get-Alias -Name ABCD -scope local - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "localfoo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "localfoo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" Set-Alias -Name ABCD -Value "globalfoo" -scope global Set-Alias -Name ABCD -Value "scriptfoo" -scope "script" @@ -105,40 +105,40 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Set-Alias -Name ABCD -Value "foo1" -scope "1" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo0" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo0" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope local - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo0" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo0" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope global - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "globalfoo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "globalfoo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "script" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "scriptfoo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "scriptfoo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "0" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo0" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo0" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "1" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo1" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo1" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Get-Alias Expose Bug 1065828, BugId:905235"{ try { @@ -146,31 +146,31 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Zero Scope Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "0" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Test get-alias with Definition parameter" { $returnObject = Get-Alias -Definition Get-Command For($i = 0; $i -lt $returnObject.Length;$i++) { - $returnObject[$i] | Should Not BeNullOrEmpty - $returnObject[$i].CommandType | Should Be 'Alias' - $returnObject[$i].Definition | Should Be 'Get-Command' + $returnObject[$i] | Should -Not -BeNullOrEmpty + $returnObject[$i].CommandType | Should -Be 'Alias' + $returnObject[$i].Definition | Should -Be 'Get-Command' } } } @@ -181,25 +181,25 @@ Describe "Get-Alias" -Tags "CI" { $val2=(Get-Alias c*) $i=0 - $val1 | Should Not BeNullOrEmpty - $val2 | Should Not BeNullOrEmpty + $val1 | Should -Not -BeNullOrEmpty + $val2 | Should -Not -BeNullOrEmpty $val1 | ForEach-Object{ $i++}; if($i -lt 2) { - $val1 | Should BeOfType "System.Management.Automation.CommandInfo" + $val1 | Should -BeOfType "System.Management.Automation.CommandInfo" } else { - ,$val1 | Should BeOfType "System.Array" + ,$val1 | Should -BeOfType "System.Array" } $val2 | ForEach-Object{ $i++}; if($i -lt 2) { - $val2 | Should BeOfType "System.Management.Automation.CommandInfo" + $val2 | Should -BeOfType "System.Management.Automation.CommandInfo" } else { - ,$val2 | Should BeOfType "System.Array" + ,$val2 | Should -BeOfType "System.Array" } } @@ -207,12 +207,12 @@ Describe "Get-Alias" -Tags "CI" { $val = Get-Alias a* $alias = gal a* - $val.Count | Should Be $alias.Count + $val.Count | Should -Be $alias.Count for ($i=0; $i -lt $val.Count;$i++) { - $val[$i].CommandType | Should Be $alias[$i].CommandType - $val[$i].Name | Should Be $alias[$i].Name - $val[$i].ModuleName | Should Be $alias[$i].ModuleName + $val[$i].CommandType | Should -Be $alias[$i].CommandType + $val[$i].Name | Should -Be $alias[$i].Name + $val[$i].ModuleName | Should -Be $alias[$i].ModuleName } } } @@ -231,7 +231,7 @@ Describe "Get-Alias null tests" -Tags "CI" { Get-Alias -Name $data throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + catch { $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } } Context 'Check null or empty value to the -Name parameter via pipeline' { @@ -242,7 +242,7 @@ Describe "Get-Alias null tests" -Tags "CI" { $data | Get-Alias -ErrorAction Stop throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + catch { $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 index 6c87a75cc4f..ecc1d2b2aaf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 @@ -3,8 +3,8 @@ Describe "Get-Culture DRT Unit Tests" -Tags "CI" { It "Should works proper with get-culture" { $results = get-Culture - $results -is "System.Globalization.CultureInfo" | Should be $true - $results[0].Name | Should Be $PSCulture + $results -is "System.Globalization.CultureInfo" | Should -be $true + $results[0].Name | Should -Be $PSCulture } } @@ -12,13 +12,13 @@ Describe "Get-Culture" -Tags "CI" { It "Should return a type of CultureInfo for Get-Culture cmdlet" { - Get-Culture | Should BeOfType CultureInfo + Get-Culture | Should -BeOfType CultureInfo } It "Should have $ culture variable be equivalent to (Get-Culture).Name" { - (Get-Culture).Name | Should Be $PsCulture + (Get-Culture).Name | Should -Be $PsCulture } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index c111d721bf2..8a2c4ce8220 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -4,39 +4,39 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { It "Get-Date with all parameters returns proper results" { $date = [datetime]::Now + ([timespan]::new(0,0,30)) $result = Get-Date -Date $date -Year 1973 -Month 2 -Day 22 -Hour 15 -Minute 40 -Second 10 -Millisecond 200 - $result | Should BeOfType Datetime - $result.Year | Should be 1973 - $result.Month| Should be 2 - $result.Day | Should be 22 - $result.Hour | Should be 15 - $result.Minute | Should be 40 - $result.Second | Should be 10 - $result.Millisecond | Should be 200 + $result | Should -BeOfType Datetime + $result.Year | Should -be 1973 + $result.Month| Should -be 2 + $result.Day | Should -be 22 + $result.Hour | Should -be 15 + $result.Minute | Should -be 40 + $result.Second | Should -be 10 + $result.Millisecond | Should -be 200 } It "using -displayhint produces the correct output" { $d = Get-date -Date:"Jan 1, 2020" -DisplayHint Date | Out-String - $d.Trim() | Should be "Wednesday, January 1, 2020" + $d.Trim() | Should -be "Wednesday, January 1, 2020" } It "using -format produces the correct output" { - Get-date -Date:"Jan 1, 2020" -Format:"MMM-dd-yy" | Should be "Jan-01-20" + Get-date -Date:"Jan 1, 2020" -Format:"MMM-dd-yy" | Should -be "Jan-01-20" } It "using -uformat produces the correct output" { - Get-date -Date:"Jan 1, 2020" -UFormat:"%s" | Should be "1577836800" + Get-date -Date:"Jan 1, 2020" -UFormat:"%s" | Should -be "1577836800" } It "using -uformat 'ymdH' produces the correct output" { - Get-date -Date 0030-01-01T00:00:00 -uformat %y/%m/%d-%H | Should be "30/01/01-00" + Get-date -Date 0030-01-01T00:00:00 -uformat %y/%m/%d-%H | Should -be "30/01/01-00" } It "using -uformat 'aAbBcCdDehHIjmMpr' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" + Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should -be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should -be "0000:00:002012001/01/3000:00:00300030%" } It "Passing '' to -uformat produces a descriptive error" -TestCases @( @@ -51,7 +51,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $x = new-object System.Management.Automation.PSObject $x | add-member NoteProperty Date ([DateTime]::Now) $y = @($x,$x) - ($y | Get-date).Length | Should be 2 + ($y | Get-date).Length | Should -be 2 } It "the LastWriteTime alias works with pipeline input" { @@ -74,12 +74,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $result1 = get-childitem -path $pathString | get-date $result2 = get-childitem -path $pathString | get-date - $result1.Length | Should be 10 - $result1.Length -eq $result2.Length | Should be $true + $result1.Length | Should -be 10 + $result1.Length -eq $result2.Length | Should -be $true for($i = 0; $i -lt $result1.Length; $i++) { - $result1[$i] -eq $result2[$i] | Should be $true + $result1[$i] -eq $result2[$i] | Should -be $true } Get-ChildItem -Path $pathString | Remove-Item @@ -90,48 +90,48 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { Describe "Get-Date" -Tags "CI" { It "-Format FileDate works" { - Get-date -Date 0030-01-01T01:02:03.0004 -Format FileDate | Should Be "00300101" + Get-date -Date 0030-01-01T01:02:03.0004 -Format FileDate | Should -Be "00300101" } It "-Format FileDateTime works" { - Get-date -Date 0030-01-01T01:02:03.0004 -Format FileDateTime | Should Be "00300101T0102030004" + Get-date -Date 0030-01-01T01:02:03.0004 -Format FileDateTime | Should -Be "00300101T0102030004" } It "-Format FileDateTimeUniversal works" { - Get-date -Date 0030-01-01T01:02:03.0004z -Format FileDateTimeUniversal | Should Be "00300101T0102030004Z" + Get-date -Date 0030-01-01T01:02:03.0004z -Format FileDateTimeUniversal | Should -Be "00300101T0102030004Z" } It "-Format FileDateTimeUniversal works" { - Get-date -Date 0030-01-01T01:02:03.0004z -Format FileDateUniversal | Should Be "00300101Z" + Get-date -Date 0030-01-01T01:02:03.0004z -Format FileDateUniversal | Should -Be "00300101Z" } It "Should have colons when ToString method is used" { - (Get-Date).ToString().Contains(":") | Should be $true - (Get-Date -DisplayHint Time).ToString().Contains(":") | Should be $true - (Get-Date -DisplayHint Date).ToString().Contains(":") | Should be $true + (Get-Date).ToString().Contains(":") | Should -be $true + (Get-Date -DisplayHint Time).ToString().Contains(":") | Should -be $true + (Get-Date -DisplayHint Date).ToString().Contains(":") | Should -be $true } It "Should be able to use the format flag" { # You would think that one could use simple loops here, but apparently powershell in Windows returns different values in loops - (Get-Date -Format d).Contains("/") | Should be $true - (Get-Date -Format D).Contains(",") | Should be $true - (Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should be $true - (Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should be $true - (Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should be $true - (Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should be $true + (Get-Date -Format d).Contains("/") | Should -be $true + (Get-Date -Format D).Contains(",") | Should -be $true + (Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should -be $true + (Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should -be $true + (Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should -be $true + (Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should -be $true (Get-Date -Format m).Contains(",") -or ` (Get-Date -Format m).Contains(":") -or ` - (Get-Date -Format m).Contains("/") | Should be $false + (Get-Date -Format m).Contains("/") | Should -be $false } It "Should check that Get-Date can return the correct datetime from the system time" { $timeDifference = $(Get-Date).Subtract([System.DateTime]::Now) - $timeDifference.Days | Should Be 0 - $timeDifference.Hours | Should Be 0 - $timeDifference.Minutes | Should Be 0 - $timeDifference.Milliseconds | Should BeLessThan 1 - $timeDifference.Ticks | Should BeLessThan 10000 + $timeDifference.Days | Should -Be 0 + $timeDifference.Hours | Should -Be 0 + $timeDifference.Minutes | Should -Be 0 + $timeDifference.Milliseconds | Should -BeLessThan 1 + $timeDifference.Ticks | Should -BeLessThan 10000 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 index a5c0d82d106..b860edb6e44 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 @@ -13,22 +13,22 @@ Describe "Get-Event" -Tags "CI" { Context "Check return type of Get-Event" { It "Should return PSEventArgs as return type of Get-Event" { - Get-Event -SourceIdentifier PesterTestEvent | Should BeOfType System.Management.Automation.PSEventArgs + Get-Event -SourceIdentifier PesterTestEvent | Should -BeOfType System.Management.Automation.PSEventArgs } } Context "Validate Get-Event can retrieve event" { It "Should return at least 1 event" { - { (Get-Event).Count | Should BeGreaterThan 0 } + { (Get-Event).Count | Should -BeGreaterThan 0 } } It "Should return PesterTestMessage as the MessageData" { - { (Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage" } + { (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -Be "PesterTestMessage" } } It "Should return Sender as Windows.timer" { - { (Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer } + { (Get-Event -SourceIdentifier PesterTimer).Sender | Should -be Windows.timer } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 index 66176a476c3..7c37f9f05b8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 @@ -11,7 +11,7 @@ Describe "Get-EventSubscriber" -Tags "CI" { It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event" { $pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object]) Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - Get-EventSubscriber | Should BeOfType System.Management.Automation.PSEventSubscriber + Get-EventSubscriber | Should -BeOfType System.Management.Automation.PSEventSubscriber } } @@ -19,13 +19,13 @@ Describe "Get-EventSubscriber" -Tags "CI" { It "Should return source identifier of PesterTimer " { $pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object]) Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister" + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -Be "PesterTestRegister" } It "Should return an integer greater than 0 for the SubscriptionId" { $pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object]) Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0 + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should -BeGreaterThan 0 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 index b05d6ac3a2d..af02f685529 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 @@ -10,9 +10,9 @@ Describe "Get-FileHash" -Tags "CI" { Context "Default result tests" { It "Should default to correct algorithm, hash and path" { $result = Get-FileHash $testDocument - $result.Algorithm | Should Be "SHA256" - $result.Hash | Should Be "8129a08e5d748ffb9361375677785f96545a1a37619a27608efd76a870787a7a" - $result.Path | Should Be $testDocument + $result.Algorithm | Should -Be "SHA256" + $result.Hash | Should -Be "8129a08e5d748ffb9361375677785f96545a1a37619a27608efd76a870787a7a" + $result.Path | Should -Be $testDocument } } @@ -29,7 +29,7 @@ Describe "Get-FileHash" -Tags "CI" { It "Should be able to get the correct hash from algorithm" -TestCases $testCases { param($algorithm, $hash) $algorithmResult = Get-FileHash $testDocument -Algorithm $algorithm - $algorithmResult.Hash | Should Be $hash + $algorithmResult.Hash | Should -Be $hash } It "Should be throw for wrong algorithm name" { @@ -38,7 +38,7 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" } } } @@ -50,7 +50,7 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.FullyQualifiedErrorId | Should -Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } } @@ -60,18 +60,18 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.FullyQualifiedErrorId | Should -Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } } It "With '-Path': file exist" { $result = Get-FileHash -Path $testDocument - $result.Path | Should Be $testDocument + $result.Path | Should -Be $testDocument } It "With '-LiteralPath': file exist" { $result = Get-FileHash -LiteralPath $testDocument - $result.Path | Should Be $testDocument + $result.Path | Should -Be $testDocument } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 index c19b8976e88..9db38ee99e1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Get-FormatData" -Tags "CI" { It "Should return an object[] as the return type" { $result = Get-FormatData - ,$result | Should BeOfType "System.Object[]" + ,$result | Should -BeOfType "System.Object[]" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 index 214c57f390a..a54b2679f69 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 @@ -3,7 +3,7 @@ Describe "Get-Host DRT Unit Tests" -Tags "CI" { It "Should works proper with get-host" { $results = Get-Host - $results | Should Be $Host - $results.PSObject.TypeNames[0] | Should Be "System.Management.Automation.Internal.Host.InternalHost" + $results | Should -Be $Host + $results.PSObject.TypeNames[0] | Should -Be "System.Management.Automation.Internal.Host.InternalHost" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 index 5e08a78f169..086d156460c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 @@ -9,12 +9,12 @@ Describe "Get-Member" -Tags "CI" { $e = "anoeduntodeu" #test strings $f = 'asntoheusth' #test strings - Get-Member -InputObject $a | Should Not BeNullOrEmpty - Get-Member -InputObject $b | Should Not BeNullOrEmpty - Get-Member -InputObject $c | Should Not BeNullOrEmpty - Get-Member -InputObject $d | Should Not BeNullOrEmpty - Get-Member -InputObject $e | Should Not BeNullOrEmpty - Get-Member -InputObject $f | Should Not BeNullOrEmpty + Get-Member -InputObject $a | Should -Not -BeNullOrEmpty + Get-Member -InputObject $b | Should -Not -BeNullOrEmpty + Get-Member -InputObject $c | Should -Not -BeNullOrEmpty + Get-Member -InputObject $d | Should -Not -BeNullOrEmpty + Get-Member -InputObject $e | Should -Not -BeNullOrEmpty + Get-Member -InputObject $f | Should -Not -BeNullOrEmpty } It "Should be able to extract a field from string objects, ints, arrays, etc" { @@ -25,12 +25,12 @@ Describe "Get-Member" -Tags "CI" { $e = "anoeduntodeu" #test strings $f = 'asntoheusth' #test strings - $a | Should BeOfType 'Int32' - $b | Should BeOfType 'Double' - $c | Should BeOfType 'Boolean' - ,$d | Should BeOfType 'Object[]' - $e | Should BeOfType 'String' - $f | Should BeOfType 'String' + $a | Should -BeOfType 'Int32' + $b | Should -BeOfType 'Double' + $c | Should -BeOfType 'Boolean' + ,$d | Should -BeOfType 'Object[]' + $e | Should -BeOfType 'String' + $f | Should -BeOfType 'String' } It "Should be able to be called on a newly created PSObject" { @@ -38,7 +38,7 @@ Describe "Get-Member" -Tags "CI" { # this creates a dependency on the Add-Member cmdlet. Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal" - Get-Member -InputObject $o | Should Not BeNullOrEmpty + Get-Member -InputObject $o | Should -Not -BeNullOrEmpty } } @@ -156,24 +156,24 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' + $_.FullyQualifiedErrorId | Should -Be 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' } } It 'Get the expected Properties of "Employee" object' { $emps = [Employee]::New("john", "smith", 5), [Employee]::New("joesph", "smith", 15), [Employee]::New("john", "smyth", 2) $results = $emps | Get-Member -MemberType Property - $results.Length | Should Be 3 - $results[0].Name | Should Be "FirstName" - $results[1].Name | Should Be "LastName" - $results[2].Name | Should Be "YearsInMS" + $results.Length | Should -Be 3 + $results[0].Name | Should -Be "FirstName" + $results[1].Name | Should -Be "LastName" + $results[2].Name | Should -Be "YearsInMS" } It 'Get the Public Methods of "Employee" object' { $emps = [Employee]::New("john", "smith", 5), [Employee]::New("joesph", "smith", 15), [Employee]::New("john", "smyth", 2) $methodList = "GetHashCode", "Equals", "ToString", "GetType" $results = $emps | Get-Member -MemberType Method - $results.Length | Should Be $methodList.Length + $results.Length | Should -Be $methodList.Length $methodFound = @() for ($i = 0;$i -lt $methodList.Length;$i++) @@ -189,16 +189,16 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { for ($i = 0;$i -lt $methodList.Length;$i++) { - $methodFound[$i] | Should Be $true + $methodFound[$i] | Should -Be $true } } It 'Get property sets defined in private members' { $emps = [Employee]::New("john", "smith", 5), [Employee]::New("joesph", "smith", 15), [Employee]::New("john", "smyth", 2) $results = $emps | Get-Member -MemberType PropertySet - $results.Length | Should Be 2 - $results[0].Name | Should Be "FullSet" - $results[1].Name | Should Be "PropertySetName" + $results.Length | Should -Be 2 + $results[0].Name | Should -Be "FullSet" + $results[1].Name | Should -Be "PropertySetName" } } @@ -256,9 +256,9 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { Context "Verify Get-Member with other parameters" { It 'works with View Parameter' { $results = [xml]'some text' | Get-Member -view adapted - $results | Where-Object Name -eq a | Should Not BeNullOrEmpty - $results | Where-Object Name -eq CreateElement | Should Not BeNullOrEmpty - $results | Where-Object Name -eq CreateNode | Should Not BeNullOrEmpty + $results | Where-Object Name -eq a | Should -Not -BeNullOrEmpty + $results | Where-Object Name -eq CreateElement | Should -Not -BeNullOrEmpty + $results | Where-Object Name -eq CreateNode | Should -Not -BeNullOrEmpty } It 'Get hidden members'{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 index 5757e3baefe..90de2f4debc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 @@ -12,23 +12,23 @@ Describe "Get-PSBreakpoint" -Tags "CI" { It "should be able to get PSBreakpoint with using Id switch" { Set-PSBreakpoint -Script $fullScriptPath -Line 1 - { Get-PSBreakpoint -Script $fullScriptPath } | Should Not Throw + { Get-PSBreakpoint -Script $fullScriptPath } | Should -Not -Throw $Id = (Get-PSBreakpoint -Script $fullScriptPath).Id # if breakpoints have been set by other tests, the number may or may not be 0 # so we can't check against a specific number # however, we can be sure that we're getting an int and that the int is # greater or equal to 0 - ([int]$Id) -ge 0 | should be $true + ([int]$Id) -ge 0 | should -be $true } It "should be able to get PSBreakpoint with using Variable switch" { Set-PSBreakpoint -Script $fullScriptPath -Variable "$scriptName" - { Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath } | Should Not Throw + { Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath } | Should -Not -Throw $Id = (Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath).Variable - $Id | Should be $scriptName + $Id | Should -be $scriptName } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 index 00c43985aed..e956498669c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 @@ -44,22 +44,22 @@ Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" { $fileStream > $scriptFilePath $results = & "$scriptFilePath" - $results.Count | Should BeGreaterThan 3 - $results[0].Command | Should be "bar" - $results[0].ScriptName | Should be $scriptFilePath - $results[0].ScriptLineNumber | Should be 27 - $results[0].InvocationInfo.ScriptLineNumber | Should be 9 + $results.Count | Should -BeGreaterThan 3 + $results[0].Command | Should -be "bar" + $results[0].ScriptName | Should -be $scriptFilePath + $results[0].ScriptLineNumber | Should -be 27 + $results[0].InvocationInfo.ScriptLineNumber | Should -be 9 - $results[1].Command | Should be "foo" - $results[1].ScriptName | Should be $scriptFilePath - $results[1].ScriptLineNumber | Should be 9 - $results[1].InvocationInfo.ScriptLineNumber | Should be 32 + $results[1].Command | Should -be "foo" + $results[1].ScriptName | Should -be $scriptFilePath + $results[1].ScriptLineNumber | Should -be 9 + $results[1].InvocationInfo.ScriptLineNumber | Should -be 32 #InvocationInfo.ScriptLineNumber: Gets the line number of the script that contains the command - $results[2].Command | Should be $scriptFileName - $results[2].ScriptName | Should be $scriptFilePath - $results[2].ScriptLineNumber | Should be 32 - $results[2].InvocationInfo.ScriptLineNumber | Should be 46 + $results[2].Command | Should -be $scriptFileName + $results[2].ScriptName | Should -be $scriptFilePath + $results[2].ScriptLineNumber | Should -be 32 + $results[2].InvocationInfo.ScriptLineNumber | Should -be 46 } It "Verify that the script block of a trap statement shows up on the call stack" { @@ -75,15 +75,15 @@ Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" { $fileStream > $scriptFilePath $results = & "$scriptFilePath" - $results.Count | Should BeGreaterThan 2 - $results[0].Command | Should be $scriptFileName - $results[0].ScriptName | Should be $scriptFilePath - $results[0].ScriptLineNumber | Should be 3 - $results[0].InvocationInfo.ScriptLineNumber | Should be 77 + $results.Count | Should -BeGreaterThan 2 + $results[0].Command | Should -be $scriptFileName + $results[0].ScriptName | Should -be $scriptFilePath + $results[0].ScriptLineNumber | Should -be 3 + $results[0].InvocationInfo.ScriptLineNumber | Should -be 77 - $results[1].Command | Should be $scriptFileName - $results[1].ScriptName | Should be $scriptFilePath - $results[1].ScriptLineNumber | Should be 7 - $results[1].InvocationInfo.ScriptLineNumber | Should be 77 + $results[1].Command | Should -be $scriptFileName + $results[1].ScriptName | Should -be $scriptFilePath + $results[1].ScriptLineNumber | Should -be 7 + $results[1].InvocationInfo.ScriptLineNumber | Should -be 77 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 index 06628db01df..0ab9f1e0444 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 @@ -65,9 +65,9 @@ Describe "Get-Random DRT Unit Tests" -Tags "CI" { param($maximum, $minimum, $greaterThan, $lessThan, $type) $result = Get-Random -Maximum $maximum -Minimum $minimum - $result | Should BeGreaterThan $greaterThan - $result | Should BeLessThan $lessThan - $result | Should BeOfType $type + $result | Should -BeGreaterThan $greaterThan + $result | Should -BeLessThan $lessThan + $result | Should -BeOfType $type } @@ -80,97 +80,97 @@ Describe "Get-Random DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" + $_.FullyQualifiedErrorId | Should -Be "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" } } It "Tests for setting the seed" { $result1 = (get-random -SetSeed 123), (get-random) $result2 = (get-random -SetSeed 123), (get-random) - $result1 | Should Be $result2 + $result1 | Should -Be $result2 } } Describe "Get-Random" -Tags "CI" { It "Should return a random number greater than -1 " { - Get-Random | Should BeGreaterThan -1 + Get-Random | Should -BeGreaterThan -1 } It "Should return a random number less than 100 " { - Get-Random -Maximum 100 | Should BeLessThan 100 - Get-Random -Maximum 100 | Should BeGreaterThan -1 + Get-Random -Maximum 100 | Should -BeLessThan 100 + Get-Random -Maximum 100 | Should -BeGreaterThan -1 } It "Should return a random number less than 100 and greater than -100 " { $randomNumber = Get-Random -Minimum -100 -Maximum 100 - $randomNumber | Should BeLessThan 100 - $randomNumber | Should BeGreaterThan -101 + $randomNumber | Should -BeLessThan 100 + $randomNumber | Should -BeGreaterThan -101 } It "Should return a random number less than 20.93 and greater than 10.7 " { $randomNumber = Get-Random -Minimum 10.7 -Maximum 20.93 - $randomNumber | Should BeLessThan 20.93 - $randomNumber | Should BeGreaterThan 10.7 + $randomNumber | Should -BeLessThan 20.93 + $randomNumber | Should -BeGreaterThan 10.7 } It "Should return same number for both Get-Random when switch SetSeed is used " { $firstRandomNumber = Get-Random -Maximum 100 -SetSeed 23 $secondRandomNumber = Get-Random -Maximum 100 -SetSeed 23 - $firstRandomNumber | Should be $secondRandomNumber + $firstRandomNumber | Should -be $secondRandomNumber } It "Should return a number from 1,2,3,5,8,13 " { $randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 - $randomNumber | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) } It "Should return an array " { $randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3 - $randomNumber.Count | Should Be 3 - ,$randomNumber | Should BeOfType "System.Array" + $randomNumber.Count | Should -Be 3 + ,$randomNumber | Should -BeOfType "System.Array" } It "Should return three random numbers for array of 1,2,3,5,8,13 " { $randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3 - $randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[3] | Should BeNullOrEmpty + $randomNumber[0] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[1] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[2] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[3] | Should -BeNullOrEmpty } It "Should return all the numbers for array of 1,2,3,5,8,13 in no particular order" { $randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count ([int]::MaxValue) - $randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[3] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[4] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[5] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) - $randomNumber[6] | Should BeNullOrEmpty + $randomNumber[0] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[1] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[2] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[3] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[4] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[5] | Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13) + $randomNumber[6] | Should -BeNullOrEmpty } It "Should return for a string collection " { $randomNumber = Get-Random -InputObject "red", "yellow", "blue" - $randomNumber | Should Be ("red" -or "yellow" -or "blue") + $randomNumber | Should -Be ("red" -or "yellow" -or "blue") } It "Should return a number for hexadecimal " { $randomNumber = Get-Random 0x07FFFFFFFFF - $randomNumber | Should BeLessThan 549755813887 - $randomNumber | Should BeGreaterThan 0 + $randomNumber | Should -BeLessThan 549755813887 + $randomNumber | Should -BeGreaterThan 0 } It "Should return false, check two random numbers are not equal when not using the SetSeed switch " { $firstRandomNumber = Get-Random $secondRandomNumber = Get-Random - $firstRandomNumber | Should Not Be $secondRandomNumber + $firstRandomNumber | Should -Not -Be $secondRandomNumber } It "Should return the same number for hexadecimal number and regular number when the switch SetSeed it used " { $firstRandomNumber = Get-Random 0x07FFFFFFFF -SetSeed 20 $secondRandomNumber = Get-Random 34359738367 -SetSeed 20 - $firstRandomNumber | Should Be @secondRandomNumber + $firstRandomNumber | Should -Be @secondRandomNumber } It "Should throw an error because the hexadecimal number is to large " { - { Get-Random 0x07FFFFFFFFFFFFFFFF } | Should Throw "Value was either too large or too small for a UInt32" + { Get-Random 0x07FFFFFFFFFFFFFFFF } | Should -Throw "Value was either too large or too small for a UInt32" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 index 5dc58c47a75..02c6e1c26f3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 @@ -6,8 +6,8 @@ Describe "Get-RunspaceDebug" -Tags "CI" { It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" { $rs = Get-RunspaceDebug - $rs | Should Not BeNullOrEmpty - $rs[0] | Should BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" + $rs | Should -Not -BeNullOrEmpty + $rs[0] | Should -BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 index 550d8911af1..b282b9bc702 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 @@ -3,6 +3,6 @@ Describe "Get-TraceSource" -Tags "Feature" { It "Should output data sorted by name" { $expected = (Get-TraceSource | Sort-Object Name) - Get-TraceSource | Should be $expected + Get-TraceSource | Should -be $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-UICulture.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-UICulture.Tests.ps1 index 703d2b4a0e5..3845e2c9e49 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-UICulture.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-UICulture.Tests.ps1 @@ -3,7 +3,7 @@ Describe "Get-UICulture" -Tags "CI" { It "Should have $ PsUICulture variable be equivalent to Get-UICulture object" { $result = Get-UICulture - $result.Name | Should Be $PsUICulture - $result | Should BeOfType CultureInfo + $result.Name | Should -Be $PsUICulture + $result | Should -BeOfType CultureInfo } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 index 4f4f5a4957d..535ec1a22e1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 @@ -5,17 +5,17 @@ Describe "Get-Unique DRT Unit Tests" -Tags "CI" { $inputArray = "aa","aa","Aa","ba","BA","BA" $results = $inputArray | Get-Unique -AsString - $results.Length | Should Be 4 + $results.Length | Should -Be 4 - $results[0] | Should Be "aa" - $results[1] | Should Be "Aa" - $results[2] | Should Be "ba" - $results[3] | Should Be "BA" + $results[0] | Should -Be "aa" + $results[1] | Should -Be "Aa" + $results[2] | Should -Be "ba" + $results[3] | Should -Be "BA" - $results[0] | Should BeOfType "System.String" - $results[1] | Should BeOfType "System.String" - $results[2] | Should BeOfType "System.String" - $results[3] | Should BeOfType "System.String" + $results[0] | Should -BeOfType "System.String" + $results[1] | Should -BeOfType "System.String" + $results[2] | Should -BeOfType "System.String" + $results[3] | Should -BeOfType "System.String" } } @@ -29,36 +29,36 @@ Describe "Get-Unique" -Tags "CI" { } It "Should be able to use the Get-Unique cmdlet without error with inputObject switch" { - { Get-Unique -InputObject $sortedList1 } | Should Not Throw + { Get-Unique -InputObject $sortedList1 } | Should -Not -Throw } It "Should output an array" { $result = Get-Unique -InputObject $sortedList1 - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType "System.Array" + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType "System.Array" } It "Should output an array of unchanged items when the InputObject switch is used" { $actual = Get-Unique -InputObject $sortedList1 - $(Compare-Object $actual $sortedList1 -SyncWindow 0).Length | Should Be 0 + $(Compare-Object $actual $sortedList1 -SyncWindow 0).Length | Should -Be 0 } It "Should accept piped input" { - { $actualOutput = $sortedList1 | Get-Unique } | Should Not Throw + { $actualOutput = $sortedList1 | Get-Unique } | Should -Not -Throw } It "Should have the expected output when piped input is used" { $actualOutput = $sortedList1 | Get-Unique - $(Compare-Object $actualOutput $expectedOutput1 -SyncWindow 0).Length | Should Be 0 + $(Compare-Object $actualOutput $expectedOutput1 -SyncWindow 0).Length | Should -Be 0 } It "Should be able to input a collection in the inputObject switch" { $actual = Get-Unique -InputObject $collection - $(Compare-Object $actual $collection -SyncWindow 0).Length | Should Be 0 + $(Compare-Object $actual $collection -SyncWindow 0).Length | Should -Be 0 } It "Should get the unique items when piped collection input is used" { $actual = $collection | Get-Unique - $(Compare-Object $actual $expectedOutput2 -SyncWindow 0).Length | Should Be 0 + $(Compare-Object $actual $expectedOutput2 -SyncWindow 0).Length | Should -Be 0 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index 586a1dae9b5..77e9f8e58dd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -19,11 +19,11 @@ Describe "Get-Uptime" -Tags "CI" { } It "Get-Uptime return timespan (default -Timespan)" { $upt = Get-Uptime - $upt | Should BeOfType "Timespan" + $upt | Should -BeOfType "Timespan" } It "Get-Uptime -Since return DateTime" { $upt = Get-Uptime -Since - $upt | Should BeOfType "DateTime" + $upt | Should -BeOfType "DateTime" } It "Get-Uptime throw if IsHighResolution == false" { try @@ -36,7 +36,7 @@ Describe "Get-Uptime" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + $_.FullyQualifiedErrorId | Should -be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" } finally { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 index 064e71015c3..9bdfaf1761d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 @@ -8,24 +8,24 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } It "Get-Variable of existing variable Name with include and bogus exclude should work"{ Set-Variable newVar testing $var1=get-variable -Name newVar -Include newVar -Exclude bogus - $var1.Name|Should Be "newVar" - $var1.Value|Should Be "testing" + $var1.Name|Should -Be "newVar" + $var1.Value|Should -Be "testing" } It "Get-Variable of existing variable Name with Description and Option should work"{ Set-Variable newVar testing -Option ReadOnly -Description "testing description" $var1=get-variable -Name newVar - $var1.Name|Should Be "newVar" - $var1.Value|Should Be "testing" - $var1.Options|Should Be "ReadOnly" - $var1.Description|Should Be "testing description" + $var1.Name|Should -Be "newVar" + $var1.Value|Should -Be "testing" + $var1.Options|Should -Be "ReadOnly" + $var1.Description|Should -Be "testing description" } It "Get-Variable of existing variable Globbing Name should work"{ @@ -33,13 +33,13 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Set-Variable bcdaVar "another test" Set-Variable aVarfoo wow $var1=get-variable -Name *aVar* -Scope local - $var1.Count | Should be 3 - $var1[0].Name|Should Be "abcaVar" - $var1[0].Value|Should Be "testing" - $var1[1].Name|Should Be "aVarfoo" - $var1[1].Value|Should Be "wow" - $var1[2].Name|Should Be "bcdaVar" - $var1[2].Value|Should Be "another test" + $var1.Count | Should -be 3 + $var1[0].Name|Should -Be "abcaVar" + $var1[0].Value|Should -Be "testing" + $var1[1].Name|Should -Be "aVarfoo" + $var1[1].Value|Should -Be "wow" + $var1[2].Name|Should -Be "bcdaVar" + $var1[2].Value|Should -Be "another test" } It "Get-Variable of existing private variable Name should throw ItemNotFoundException"{ @@ -49,36 +49,36 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } } Describe "Get-Variable" -Tags "CI" { It "Should be able to call with no parameters without error" { - { Get-Variable } | Should Not Throw + { Get-Variable } | Should -Not -Throw } It "Should return environment variables when called with no parameters" { - (Get-Variable).Name -contains "$" | Should Be $true - (Get-Variable).Name -contains "?" | Should Be $true - (Get-Variable).Name -contains "HOST" | Should Be $true - (Get-Variable).Name -contains "PWD" | Should Be $true - (Get-Variable).Name -contains "PID" | Should Be $true - (Get-Variable).Name -contains "^" | Should Be $true + (Get-Variable).Name -contains "$" | Should -Be $true + (Get-Variable).Name -contains "?" | Should -Be $true + (Get-Variable).Name -contains "HOST" | Should -Be $true + (Get-Variable).Name -contains "PWD" | Should -Be $true + (Get-Variable).Name -contains "PID" | Should -Be $true + (Get-Variable).Name -contains "^" | Should -Be $true } It "Should return the value of an object" { New-Variable -Name tempVar -Value 1 - (Get-Variable tempVar).Value | Should Be (1) + (Get-Variable tempVar).Value | Should -Be (1) } It "Should be able to call using the Name switch" { New-Variable -Name var1 -Value 4 - { Get-Variable -Name var1 } | Should Not Throw + { Get-Variable -Name var1 } | Should -Not -Throw - (Get-Variable -Name var1).Value | Should Be 4 + (Get-Variable -Name var1).Value | Should -Be 4 Remove-Variable var1 } @@ -87,8 +87,8 @@ Describe "Get-Variable" -Tags "CI" { New-Variable -Name var1 -Value 4 New-Variable -Name var2 -Value "test" - (Get-Variable -Name var*).Value[0] | Should be 4 - (Get-Variable -Name var*).Value[1] | Should be "test" + (Get-Variable -Name var*).Value[0] | Should -be 4 + (Get-Variable -Name var*).Value[1] | Should -be "test" Remove-Variable var1 Remove-Variable var2 @@ -97,7 +97,7 @@ Describe "Get-Variable" -Tags "CI" { It "Should return only the value if the value switch is used" { New-Variable -Name var1 -Value 4 - Get-Variable -Name var1 -ValueOnly | Should be 4 + Get-Variable -Name var1 -ValueOnly | Should -be 4 Remove-Variable var1 } @@ -105,7 +105,7 @@ Describe "Get-Variable" -Tags "CI" { It "Should pipe string to the name field without the Name field being specified"{ New-Variable -Name var1 -Value 3 - ("var1" | Get-Variable ).Value | Should Be 3 + ("var1" | Get-Variable ).Value | Should -Be 3 Remove-Variable var1 } @@ -116,11 +116,11 @@ Describe "Get-Variable" -Tags "CI" { $actual = Get-Variable -Include var1, var2 - $actual[0].Name | Should Be var1 - $actual[1].Name | Should Be var2 + $actual[0].Name | Should -Be var1 + $actual[1].Name | Should -Be var2 - $actual[0].Value | Should Be 4 - $actual[1].Value | Should Be 2 + $actual[0].Value | Should -Be 4 + $actual[1].Value | Should -Be 2 Remove-Variable var1 Remove-Variable var2 @@ -133,7 +133,7 @@ Describe "Get-Variable" -Tags "CI" { $actual = Get-Variable -Exclude var1, var2 - $actual.Name -contains "var3" | Should Be $true + $actual.Name -contains "var3" | Should -Be $true } Context "Scope Tests" { @@ -141,21 +141,21 @@ Describe "Get-Variable" -Tags "CI" { It "Should be able to get a global scope variable using the global switch" { New-Variable globalVar -Value 1 -Scope global -Force - (Get-Variable -Name globalVar -Scope global).Value | Should Be 1 + (Get-Variable -Name globalVar -Scope global).Value | Should -Be 1 } It "Should not be able to clear a global scope variable using the local switch" { New-Variable globalVar -Value 1 -Scope global -Force Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue -ErrorVariable removeGlobalAsLocal - $removeGlobalAsLocal.FullyQualifiedErrorId | Should Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $removeGlobalAsLocal.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } It "Should be able to get a global variable when there's one in the script scope" { New-Variable globalVar -Value 1 -Scope global -Force { New-Variable globalVar -Value 2 -Scope script -Force} - (Get-Variable -Name globalVar).Value | Should Be 1 + (Get-Variable -Name globalVar).Value | Should -Be 1 } It "Should be able to get an item locally using the local switch" { @@ -163,7 +163,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable localVar -Value 1 -Scope local -Force Get-Variable -Name localVar -Scope local - } | Should Not Throw + } | Should -Not -Throw } It "Should be able to get a variable created in the global scope when there's one in local scope" { @@ -171,7 +171,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable localVar -Value 2 -Scope global -Force - (Get-Variable -Name localVar -Scope global).Value | Should Be 2 + (Get-Variable -Name localVar -Scope global).Value | Should -Be 2 } It "Should be able to get a script variable created using the script switch" { @@ -179,7 +179,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable scriptVar -Value 1 -Scope script -Force Get-Variable -Name scriptVar -Scope script - } | Should Not Throw + } | Should -Not -Throw } It "Should be able to clear a global script variable that was created using the script scope switch" { @@ -187,7 +187,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable scriptVar -Value 1 -Scope script -Force Get-Variable -Name scriptVar -Scope script - } | Should Not Throw + } | Should -Not -Throw } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 index f1443f34444..7c13a51859b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 @@ -3,34 +3,34 @@ Describe "Get-Verb" -Tags "CI" { It "Should get a list of Verbs" { - Get-Verb | Should not be $null + Get-Verb | Should -not -be $null } It "Should get a specific verb" { - @(Get-Verb -Verb Add).Count | Should be 1 - @(Get-Verb -Verb Add -Group Common).Count | Should be 1 + @(Get-Verb -Verb Add).Count | Should -be 1 + @(Get-Verb -Verb Add -Group Common).Count | Should -be 1 } It "Should get a specific group" { - (Get-Verb -Group Common).Group | Sort-Object -Unique | Should be Common + (Get-Verb -Group Common).Group | Sort-Object -Unique | Should -be Common } It "Should not return duplicate Verbs with Verb paramater" { $dups = Get-Verb -Verb Add,ad*,a* $unique = $dups | Select-Object -Property * -Unique - $dups.Count | Should be $unique.Count + $dups.Count | Should -be $unique.Count } It "Should not return duplicate Verbs with Group paramater" { $dupVerbs = Get-Verb -Group Data,Data $uniqueVerbs = $dupVerbs | Select-Object -Property * -Unique - $dupVerbs.Count | Should be $uniqueVerbs.Count + $dupVerbs.Count | Should -be $uniqueVerbs.Count } It "Should filter using the Verb parameter" { - Get-Verb -Verb fakeVerbNeverExists | Should BeNullOrEmpty + Get-Verb -Verb fakeVerbNeverExists | Should -BeNullOrEmpty } It "Should not accept Groups that are not in the validate set" { @@ -39,7 +39,7 @@ Describe "Get-Verb" -Tags "CI" { throw "Expected error did not occur" } Catch{ - $PSItem.FullyQualifiedErrorId | Should be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' + $PSItem.FullyQualifiedErrorId | Should -be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' } } @@ -49,22 +49,22 @@ Describe "Get-Verb" -Tags "CI" { Select-Object -Property @{Name='VerbGroup';Expression={$_.Name.Substring(5)}}).VerbGroup ForEach($group in $groups) { - {Get-Verb -Group $group} | Should Not Throw + {Get-Verb -Group $group} | Should -Not -Throw } } It "Should not have verbs without descriptions" { $noDescVerbs = (Get-Verb | Where-Object { [string]::IsNullOrEmpty($_.Description) }).Verb -join ", " - $noDescVerbs | Should BeNullOrEmpty + $noDescVerbs | Should -BeNullOrEmpty } It "Should not have verbs without alias prefixes" { $noPrefixVerbs = (Get-Verb | Where-Object { [string]::IsNullOrEmpty($_.AliasPrefix) }).Verb -join ", " - $noPrefixVerbs | Should BeNullOrEmpty + $noPrefixVerbs | Should -BeNullOrEmpty } It "Should not have duplicate alias prefixes" { $dupPrefixVerbs = ((Get-Verb | Group-Object -Property AliasPrefix | Where-Object Count -gt 1).Group).Verb -join ", " - $dupPrefixVerbs | Should BeNullOrEmpty + $dupPrefixVerbs | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Group-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Group-Object.Tests.ps1 index efc1f8d9ab8..a2f113fef31 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Group-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Group-Object.Tests.ps1 @@ -4,12 +4,12 @@ Describe "Group-Object DRT Unit Tests" -Tags "CI" { It "Test for CaseSensitive switch" { $testObject = 'aA', 'aA', 'AA', 'AA' $results = $testObject | Group-Object -CaseSensitive - $results.Count | Should Be 2 - $results.Name.Count | Should Be 2 - $results.Group.Count | Should Be 4 - $results.Name | Should Be aA,AA - $results.Group | Should Be aA,aA,AA,AA - ,$results | Should BeOfType "System.Array" + $results.Count | Should -Be 2 + $results.Name.Count | Should -Be 2 + $results.Group.Count | Should -Be 4 + $results.Name | Should -Be aA,AA + $results.Group | Should -Be aA,aA,AA,AA + ,$results | Should -BeOfType "System.Array" } } @@ -20,55 +20,55 @@ Describe "Group-Object" -Tags "CI" { } It "Should be called using an object as piped without error with no switches" { - {$testObject | Group-Object } | Should Not Throw + {$testObject | Group-Object } | Should -Not -Throw } It "Should be called using the InputObject without error with no other switches" { - { Group-Object -InputObject $testObject } | Should Not Throw + { Group-Object -InputObject $testObject } | Should -Not -Throw } It "Should return three columns- count, name, and group" { $actual = Group-Object -InputObject $testObject - $actual.Count | Should BeGreaterThan 0 - $actual.Name.Count | Should BeGreaterThan 0 - $actual.Group.Count | Should BeGreaterThan 0 + $actual.Count | Should -BeGreaterThan 0 + $actual.Name.Count | Should -BeGreaterThan 0 + $actual.Group.Count | Should -BeGreaterThan 0 } It "Should use the group alias" { - { Group-Object -InputObject $testObject } | Should Not Throw + { Group-Object -InputObject $testObject } | Should -Not -Throw } It "Should create a collection when the inputObject parameter is used" { $actualParam = Group-Object -InputObject $testObject - $actualParam.Group.Gettype().Name | Should Be 'Collection`1' + $actualParam.Group.Gettype().Name | Should -Be 'Collection`1' } It "Should return object of 'GroupInfo' type" { $actualParam = Group-Object -InputObject $testObject - $actualParam | Should BeOfType "Microsoft.PowerShell.Commands.GroupInfo" + $actualParam | Should -BeOfType "Microsoft.PowerShell.Commands.GroupInfo" } It "Should output an array when piped input is used" { $actual = $testObject | Group-Object - ,$actual | Should BeOfType "System.Array" + ,$actual | Should -BeOfType "System.Array" } It "Should have the same output between the group alias and the group-object cmdlet" { $actualAlias = Group-Object -InputObject $testObject $actualCmdlet = Group-Object -InputObject $testObject - $actualAlias.Name[0] | Should Be $actualCmdlet.Name[0] - $actualAlias.Group[0] | Should Be $actualCmdlet.Group[0] + $actualAlias.Name[0] | Should -Be $actualCmdlet.Name[0] + $actualAlias.Group[0] | Should -Be $actualCmdlet.Group[0] } It "Should be able to use the property switch without error" { - { $testObject | Group-Object -Property Attributes } | Should Not Throw + { $testObject | Group-Object -Property Attributes } | Should -Not -Throw $actual = $testObject | Group-Object -Property Attributes - $actual.Group.Count | Should BeGreaterThan 0 + $actual.Group.Count | Should -BeGreaterThan 0 } It "Should be able to use the property switch on multiple properties without error" { @@ -76,34 +76,34 @@ Describe "Group-Object" -Tags "CI" { $actual = $testObject | Group-Object -Property Attributes, Length - $actual.Group.Count | Should BeGreaterThan 0 + $actual.Group.Count | Should -BeGreaterThan 0 } It "Should be able to omit members of a group using the NoElement switch without error" { - { $testObject | Group-Object -NoElement } | Should Not Throw + { $testObject | Group-Object -NoElement } | Should -Not -Throw - ($testObject | Group-Object -NoElement).Group | Should BeNullOrEmpty + ($testObject | Group-Object -NoElement).Group | Should -BeNullOrEmpty } It "Should be able to output a hashtable datatype" { $actual = $testObject | Group-Object -AsHashTable - $actual | Should Not BeNullOrEmpty - $actual | Should BeOfType "System.Collections.Hashtable" + $actual | Should -Not -BeNullOrEmpty + $actual | Should -BeOfType "System.Collections.Hashtable" } It "Should be able to access when output as hash table" { $actual = $testObject | Group-Object -AsHashTable - $actual.Keys | Should Not BeNullOrEmpty + $actual.Keys | Should -Not -BeNullOrEmpty } It "Should throw when attempting to use AsString without AsHashTable" { - { $testObject | Group-Object -AsString } | Should Throw + { $testObject | Group-Object -AsString } | Should -Throw } It "Should not throw error when using AsString when the AsHashTable was added" { - { $testObject | Group-Object -AsHashTable -AsString } | Should Not Throw + { $testObject | Group-Object -AsHashTable -AsString } | Should -Not -Throw } } @@ -124,7 +124,7 @@ Describe "Check 'Culture' parameter in order object cmdlets (Group-Object, Sort- $testCulture = "ru-RU" } - {$testObject | Group-Object -Culture $testCulture } | Should Not Throw + {$testObject | Group-Object -Culture $testCulture } | Should -Not -Throw } It "Should accept a culture by hex string LCID" { @@ -136,7 +136,7 @@ Describe "Check 'Culture' parameter in order object cmdlets (Group-Object, Sort- $testCulture = "0x419" } - {$testObject | Group-Object -Culture $testCulture } | Should Not Throw + {$testObject | Group-Object -Culture $testCulture } | Should -Not -Throw } It "Should accept a culture by int string LCID" { @@ -148,6 +148,6 @@ Describe "Check 'Culture' parameter in order object cmdlets (Group-Object, Sort- $testCulture = "1049" } - {$testObject | Group-Object -Culture $testCulture } | Should Not Throw + {$testObject | Group-Object -Culture $testCulture } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index d19f8ccde85..66acd8b5592 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -100,7 +100,7 @@ try It "Verifies that Import-PSSession works in AllSigned if Certificate is used" -Skip:($skipTest -or $skipThisTest) { try { $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -Certificate $cert -AllowClobber - $importedModule | Should Not Be $null + $importedModule | Should -Not -Be $null } finally { $importedModule | Remove-Module -Force -ErrorAction SilentlyContinue } @@ -111,7 +111,7 @@ try $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -AllowClobber throw "expect Import-PSSession to throw" } catch { - $_.FullyQualifiedErrorId | Should Be "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" + $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" } } } @@ -152,9 +152,9 @@ try $module = Import-PSSession -Session $session -CommandName foo -AllowClobber # The enum is treated as an int - (foo -x "Value2") | Should Be 2 + (foo -x "Value2") | Should -Be 2 # The enum is to-string-ed appropriately - (foo -x "Value2").ToString() | Should Be "Value2" + (foo -x "Value2").ToString() | Should -Be "Value2" } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -180,7 +180,7 @@ try $gcmOutPut = (Get-Command Select-MyObject ).Name $getHelpOutPut = (Get-Help Select-MyObject).Name - $gcmOutPut | Should Be $getHelpOutPut + $gcmOutPut | Should -Be $getHelpOutPut } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -205,8 +205,8 @@ try Invoke-Command $session { Set-Alias BrokenAlias NonExistantCommand } $module = Import-PSSession $session -CommandName:BrokenAlias -CommandType:All -ErrorAction SilentlyContinue -ErrorVariable expectedError -AllowClobber - $expectedError | Should Not Be NullOrEmpty - $expectedError[0].ToString().Contains("BrokenAlias") | Should Be $true + $expectedError | Should -Not -Be NullOrEmpty + $expectedError[0].ToString().Contains("BrokenAlias") | Should -Be $true } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { Remove-Item alias:BrokenAlias } @@ -228,19 +228,19 @@ try It "Test non-terminating error" { $results = Get-MyVariable blah,pid 2>&1 - ($results[1]).Value | Should Not Be $PID # Verifies that returned PID is not for this session + ($results[1]).Value | Should -Not -Be $PID # Verifies that returned PID is not for this session $errorString = $results[0] | Out-String # Verifies error message for variable blah - ($errorString -like "*VariableNotFound*") | Should Be $true + ($errorString -like "*VariableNotFound*") | Should -Be $true } It "Test terminating error" { $results = Get-MyVariable pid -Scope blah 2>&1 - $results.Count | Should Be 1 # Verifies that remote session pid is not returned + $results.Count | Should -Be 1 # Verifies that remote session pid is not returned $errorString = $results[0] | Out-String # Verifes error message for incorrect Scope parameter argument - ($errorString -like "*Argument*") | Should Be $true + ($errorString -like "*Argument*") | Should -Be $true } } @@ -269,22 +269,22 @@ try } It "Verifies proxied output = proxied output 2" { - $proxiedOut2 | Should Be $proxiedOut + $proxiedOut2 | Should -Be $proxiedOut } It "Verifies proxied output = icm output (for mixed error and output results)" { - $icmOut | Should Be $proxiedOut + $icmOut | Should -Be $proxiedOut } It "Verifies proxied error = icm error (for mixed error and output results)" { - $icmErr | Should Be $proxiedErr + $icmErr | Should -Be $proxiedErr } It "Verifies proxied order = icm order (for mixed error and output results)" { $icmOrder = Invoke-Command $session { foo1 } 2>&1 | out-string $proxiedOrder = foo1 2>&1 | out-string - $icmOrder | Should Be $proxiedOrder + $icmOrder | Should -Be $proxiedOrder } } @@ -303,7 +303,7 @@ try It "Verifies WarningVariable" { $global:myWarningVariable = @() Write-RemoteWarning MyWarning -WarningVariable global:myWarningVariable - ([string]($myWarningVariable[0])) | Should Be 'MyWarning' + ([string]($myWarningVariable[0])) | Should -Be 'MyWarning' } } } @@ -329,19 +329,19 @@ try } It "Verifies Export-PSSession creates a file/directory" { - @(Get-Item $file).Count | Should Be 1 + @(Get-Item $file).Count | Should -Be 1 } It "Verifies Export-PSSession creates a psd1 file" { - ($results | Where-Object { $_.Name -like "*$(Split-Path -Leaf $file).psd1" }) | Should Be $true + ($results | Where-Object { $_.Name -like "*$(Split-Path -Leaf $file).psd1" }) | Should -Be $true } It "Verifies Export-PSSession creates a psm1 file" { - ($results | Where-Object { $_.Name -like "*.psm1" }) | Should Be $true + ($results | Where-Object { $_.Name -like "*.psm1" }) | Should -Be $true } It "Verifies Export-PSSession creates a ps1xml file" { - ($results | Where-Object { $_.Name -like "*.ps1xml" }) | Should Be $true + ($results | Where-Object { $_.Name -like "*.ps1xml" }) | Should -Be $true } It "Verifies that Export-PSSession fails when a module directory already exists" { @@ -349,19 +349,19 @@ try Export-PSSession -Session $session -CommandName Get-Variable -AllowClobber -ModuleName $file -EA SilentlyContinue -ErrorVariable expectedError } catch { } - $expectedError | Should Not Be NullOrEmpty + $expectedError | Should -Not -Be NullOrEmpty # Error contains reference to the directory that already exists - ([string]($expectedError[0]) -like "*$file*") | Should Be $true + ([string]($expectedError[0]) -like "*$file*") | Should -Be $true } It "Verifies that overwriting an existing directory succeeds with -Force" { $newResults = Export-PSSession -Session $session -CommandName Get-Variable -AllowClobber -ModuleName $file -Force # Verifies that Export-PSSession returns 4 files - @($newResults).Count | Should Be 4 + @($newResults).Count | Should -Be 4 # Verifies that Export-PSSession creates *new* files - $newResults | ForEach-Object { $_.LastWriteTime | Should BeGreaterThan $oldTimestamp } + $newResults | ForEach-Object { $_.LastWriteTime | Should -BeGreaterThan $oldTimestamp } } Context "The module is usable when the original runspace is still around" { @@ -377,12 +377,12 @@ try } It "Verifies that proxy returns remote pid" { - (Get-Variable -Name pid).Value | Should Not Be $pid + (Get-Variable -Name pid).Value | Should -Not -Be $pid } It "Verfies Remove-Module doesn't remove user's runspace" { Remove-Module $module -Force -ErrorAction SilentlyContinue - (Get-PSSession -InstanceId $session.InstanceId) | Should Not Be NullOrEmpty + (Get-PSSession -InstanceId $session.InstanceId) | Should -Not -Be NullOrEmpty } } } @@ -422,20 +422,20 @@ try } It "Verifies proxy should return remote pid" -Pending { - (Get-Variable -Name PID).Value | Should Not Be $PID + (Get-Variable -Name PID).Value | Should -Not -Be $PID } It "Verifies ApplicationArguments got preserved correctly" -Pending { - $(Invoke-Command $internalSession { $PSSenderInfo.ApplicationArguments.MyTest }) | Should Be "MyValue" + $(Invoke-Command $internalSession { $PSSenderInfo.ApplicationArguments.MyTest }) | Should -Be "MyValue" } It "Verifies Remove-Module removed the runspace that was automatically created" -Pending { Remove-Module $module -Force - (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should Be $null + (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -Be $null } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should Be "Closed" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Closed" } } @@ -452,24 +452,24 @@ try } It "Verifies proxy should return remote pid" -Pending { - (Get-Variable -Name PID).Value | Should Not Be $PID + (Get-Variable -Name PID).Value | Should -Not -Be $PID } # culture settings should be taken from the explicitly passed session options It "Verifies proxy returns modified culture" -Pending { - (Get-Variable -Name PSCulture).Value | Should Be "fr-FR" + (Get-Variable -Name PSCulture).Value | Should -Be "fr-FR" } It "Verifies proxy returns modified culture" -Pending { - (Get-Variable -Name PSUICulture).Value | Should Be "de-DE" + (Get-Variable -Name PSUICulture).Value | Should -Be "de-DE" } # removing the module should remove the implicitly/magically created runspace It "Verifies Remove-Module removes automatically created runspace" -Pending { Remove-Module $module -Force - (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should Be $null + (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -Be $null } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should Be "Closed" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Closed" } } @@ -488,20 +488,20 @@ try } It "Verifies proxy returns remote pid" { - (Get-Variable -Name PID).Value | Should Not Be $PID + (Get-Variable -Name PID).Value | Should -Not -Be $PID } It "Verifies switch parameters work" { - (Get-Variable -Name PID -ValueOnly) | Should Not Be $PID + (Get-Variable -Name PID -ValueOnly) | Should -Not -Be $PID } It "Verifies Adding a module affects runspace's state" { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should Be "Opened" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Opened" } It "Verifies Runspace stays opened after removing module from Export-PSSession that got initialized with an external runspace" { Remove-Module $module -Force - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should Be "Opened" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Opened" } } } @@ -641,13 +641,13 @@ try # Original local and remote formatting should be equal (sanity check) $originalRemoteFormatting = Invoke-Command $samesession $formattingScript - $originalLocalFormatting | Should Be $originalRemoteFormatting + $originalLocalFormatting | Should -Be $originalRemoteFormatting Invoke-Command $samesession { param($file) Update-FormatData $file } -ArgumentList $formatFile # Original remote and modified remote formatting should not be equal (sanity check) $modifiedRemoteFormatting = Invoke-Command $samesession $formattingScript - $originalRemoteFormatting | Should Not Be $modifiedRemoteFormatting + $originalRemoteFormatting | Should -Not -Be $modifiedRemoteFormatting $module = Import-PSSession -Session $samesession -CommandName @() -FormatTypeName * -AllowClobber } @@ -659,13 +659,13 @@ try It "modified remote and imported local should be equal" { $importedLocalFormatting = & $formattingScript - $modifiedRemoteFormatting | Should Be $importedLocalFormatting + $modifiedRemoteFormatting | Should -Be $importedLocalFormatting } It "original local and unimported local should be equal" { Remove-Module $module -Force $unimportedLocalFormatting = & $formattingScript - $originalLocalFormatting | Should Be $unimportedLocalFormatting + $originalLocalFormatting | Should -Be $unimportedLocalFormatting } } @@ -679,11 +679,11 @@ try } # Should get 2 deserialized S.M.A.H.Coordinates objects - $results.Count | Should Be 2 + $results.Count | Should -Be 2 # First object shouldn't have the additional ETS note property - $results[0].MyTestLabel | Should Be $null + $results[0].MyTestLabel | Should -Be $null # Second object should have the additional ETS note property - $results[1].MyTestLabel | Should Be 123 + $results[1].MyTestLabel | Should -Be 123 } Context "Implicit remoting works even when types.ps1xml is missing on the client" { @@ -725,17 +725,17 @@ try It "Serialization works for top-level properties" { $x = foo - $x.text | Should Be "root" + $x.text | Should -Be "root" } It "Serialization settings works for deep properties" { $x = foo - $x.Son.Grandson.text | Should Be "Grandson" + $x.Son.Grandson.text | Should -Be "Grandson" } It "Serialization settings are preserved even if types.ps1xml is missing on the client" { $y = foo | bar - $y | Should Be "Grandson" + $y | Should -Be "Grandson" } } } @@ -769,36 +769,36 @@ try } It "Import-PSSession should return a PSModuleInfo object" { - $module | Should Not Be NullOrEmpty + $module | Should -Not -Be NullOrEmpty } It "Import-PSSession should return a PSModuleInfo object" { - ($module -as [System.Management.Automation.PSModuleInfo]) | Should Not Be NullOrEmpty + ($module -as [System.Management.Automation.PSModuleInfo]) | Should -Not -Be NullOrEmpty } It "Helper functions should not be imported" { - (Get-Item function:*PSImplicitRemoting* -ErrorAction SilentlyContinue) | Should Be $null + (Get-Item function:*PSImplicitRemoting* -ErrorAction SilentlyContinue) | Should -Be $null } It "Calls implicit remoting proxies 'MyFunction'" { - (MyFunction 1 2 3) | Should Be "x = '1'; args = '2 3'" + (MyFunction 1 2 3) | Should -Be "x = '1'; args = '2 3'" } It "proxy should return remote pid" { - (Get-VariableProxy -Name:pid).Value | Should Not Be $pid + (Get-VariableProxy -Name:pid).Value | Should -Not -Be $pid } It "proxy should return remote pid" { - (Get-Variable -Name:pid).Value | Should Not Be $pid + (Get-Variable -Name:pid).Value | Should -Not -Be $pid } It "proxy should return remote pid" { - $(& (Get-Command gvalias -Type alias) -Name:pid).Value | Should Not Be $pid + $(& (Get-Command gvalias -Type alias) -Name:pid).Value | Should -Not -Be $pid } It "NoName-c8aeb5c8-2388-4d64-98c1-a9c6c218d404" { Invoke-Command -Session $session { $env:TestImplicitRemotingVariable = 123 } - (cmd.exe /c "echo TestImplicitRemotingVariable=%TestImplicitRemotingVariable%") | Should Be "TestImplicitRemotingVariable=123" + (cmd.exe /c "echo TestImplicitRemotingVariable=%TestImplicitRemotingVariable%") | Should -Be "TestImplicitRemotingVariable=123" } Context "Test what happens after the runspace is closed" { @@ -818,11 +818,11 @@ try } It "Temporary module should be automatically removed after runspace is closed" { - (Get-Module | Where-Object { $_.Path -eq $module.Path }) | Should Be $null + (Get-Module | Where-Object { $_.Path -eq $module.Path }) | Should -Be $null } It "Temporary psm1 file should be automatically removed after runspace is closed" { - (Get-Item $module.Path -ErrorAction SilentlyContinue) | Should Be $null + (Get-Item $module.Path -ErrorAction SilentlyContinue) | Should -Be $null } It "Event should be unregistered when the runspace is closed" { @@ -832,11 +832,11 @@ try { if ($item.SourceIdentifier -match "Implicit remoting event") { $implicitEventCount++ } } - $implicitEventCount | Should Be 0 + $implicitEventCount | Should -Be 0 } It "Private functions from the implicit remoting module shouldn't get imported into global scope" { - @(Get-ChildItem function:*Implicit* -ErrorAction SilentlyContinue).Count | Should Be 0 + @(Get-ChildItem function:*Implicit* -ErrorAction SilentlyContinue).Count | Should -Be 0 } } } @@ -857,7 +857,7 @@ try try { $module = Import-PSSession -Session $session -Name Get-Random -AllowClobber $x = 1..20 | Get-Random -Count 5 - $x.Count | Should Be 5 + $x.Count | Should -Be 5 } finally { Remove-Module $module -Force } @@ -885,8 +885,8 @@ try } # Sanity checks. - Invoke-Command $session {"s" | foo} | Should Be "Bound parameter: string" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should Be "Bound parameter: ipaddress" + Invoke-Command $session {"s" | foo} | Should -Be "Bound parameter: string" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -897,11 +897,11 @@ try } It "Pipeline binding works even if it relies on type constraints" { - ("s" | foo) | Should Be "Bound parameter: string" + ("s" | foo) | Should -Be "Bound parameter: string" } It "Pipeline binding works even if it relies on type constraints" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" } } @@ -926,8 +926,8 @@ try } # Sanity checks. - Invoke-Command $session {"s" | foo} | Should Be "Bound parameter: string" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should Be "Bound parameter: ipaddress" + Invoke-Command $session {"s" | foo} | Should -Be "Bound parameter: string" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -938,11 +938,11 @@ try } It "Pipeline binding works even if it relies on type constraints and parameter set is ambiguous" { - ("s" | foo) | Should Be "Bound parameter: string" + ("s" | foo) | Should -Be "Bound parameter: string" } It "Pipeline binding works even if it relies on type constraints and parameter set is ambiguous" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" } } @@ -967,10 +967,10 @@ try } # Sanity checks. - Invoke-Command $session {Get-Date | foo} | Should Be "Bound parameter: date" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should Be "Bound parameter: ipaddress" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo -date (get-date)} | Should Be "Bound parameter: date ipaddress" - Invoke-Command $session {Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))} | Should Be "Bound parameter: date ipaddress" + Invoke-Command $session {Get-Date | foo} | Should -Be "Bound parameter: date" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo -date (get-date)} | Should -Be "Bound parameter: date ipaddress" + Invoke-Command $session {Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))} | Should -Be "Bound parameter: date ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -981,19 +981,19 @@ try } It "Pipeline binding works even when also binding by name" { - (Get-Date | foo) | Should Be "Bound parameter: date" + (Get-Date | foo) | Should -Be "Bound parameter: date" } It "Pipeline binding works even when also binding by name" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" } It "Pipeline binding works even when also binding by name" { - ([ipaddress]::parse("127.0.0.1") | foo -date $(Get-Date)) | Should Be "Bound parameter: date ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo -date $(Get-Date)) | Should -Be "Bound parameter: date ipaddress" } It "Pipeline binding works even when also binding by name" { - (Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))) | Should Be "Bound parameter: date ipaddress" + (Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))) | Should -Be "Bound parameter: date ipaddress" } } @@ -1018,9 +1018,9 @@ try } # Sanity checks. - Invoke-Command $session {gps -pid $pid | foo} | Should Be "Bound parameter: PriorityClass TotalProcessorTime" - Invoke-Command $session {gps -pid $pid | foo -Total 5} | Should Be "Bound parameter: PriorityClass TotalProcessorTime" - Invoke-Command $session {gps -pid $pid | foo -Priority normal} | Should Be "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo -Total 5} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo -Priority normal} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" $module = Import-PSSession $session foo -AllowClobber } @@ -1031,15 +1031,15 @@ try } It "Pipeline binding works by property name" { - (gps -id $pid | foo) | Should Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" } It "Pipeline binding works by property name" { - (gps -id $pid | foo -Total 5) | Should Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo -Total 5) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" } It "Pipeline binding works by property name" { - (gps -id $pid | foo -Priority normal) | Should Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo -Priority normal) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" } } @@ -1064,8 +1064,8 @@ try } # Sanity checks. - Invoke-Command $session {foo ([ipaddress]::parse("127.0.0.1"))} | Should Be "Bound parameter: ipaddress" - Invoke-Command $session {foo "blah"} | Should Be "Bound parameter: string" + Invoke-Command $session {foo ([ipaddress]::parse("127.0.0.1"))} | Should -Be "Bound parameter: ipaddress" + Invoke-Command $session {foo "blah"} | Should -Be "Bound parameter: string" $module = Import-PSSession $session foo -AllowClobber } @@ -1076,11 +1076,11 @@ try } It "Positional binding works" { - foo "blah" | Should Be "Bound parameter: string" + foo "blah" | Should -Be "Bound parameter: string" } It "Positional binding works" { - foo ([ipaddress]::parse("127.0.0.1")) | Should Be "Bound parameter: ipaddress" + foo ([ipaddress]::parse("127.0.0.1")) | Should -Be "Bound parameter: ipaddress" } } @@ -1105,11 +1105,11 @@ try } # Sanity checks. - Invoke-Command $session {foo 1,2,3} | Should Be "1 2 3 : " - Invoke-Command $session {foo 1,2,3 4} | Should Be "1 2 3 : 4" - Invoke-Command $session {foo -p2 4 1,2,3} | Should Be "1 2 3 : 4" - Invoke-Command $session {foo 1 4} | Should Be "1 : 4" - Invoke-Command $session {foo -p2 4 1} | Should Be "1 : 4" + Invoke-Command $session {foo 1,2,3} | Should -Be "1 2 3 : " + Invoke-Command $session {foo 1,2,3 4} | Should -Be "1 2 3 : 4" + Invoke-Command $session {foo -p2 4 1,2,3} | Should -Be "1 2 3 : 4" + Invoke-Command $session {foo 1 4} | Should -Be "1 : 4" + Invoke-Command $session {foo -p2 4 1} | Should -Be "1 : 4" $module = Import-PSSession $session foo -AllowClobber } @@ -1120,23 +1120,23 @@ try } It "Positional binding works when binding an array value" { - foo 1,2,3 | Should Be "1 2 3 : " + foo 1,2,3 | Should -Be "1 2 3 : " } It "Positional binding works when binding an array value" { - foo 1,2,3 4 | Should Be "1 2 3 : 4" + foo 1,2,3 4 | Should -Be "1 2 3 : 4" } It "Positional binding works when binding an array value" { - foo -p2 4 1,2,3 | Should Be "1 2 3 : 4" + foo -p2 4 1,2,3 | Should -Be "1 2 3 : 4" } It "Positional binding works when binding an array value" { - foo 1 4 | Should Be "1 : 4" + foo 1 4 | Should -Be "1 : 4" } It "Positional binding works when binding an array value" { - foo -p2 4 1 | Should Be "1 : 4" + foo -p2 4 1 | Should -Be "1 : 4" } } @@ -1161,13 +1161,13 @@ try } # Sanity checks. - Invoke-Command $session {foo} | Should Be " : " - Invoke-Command $session {foo 1} | Should Be "1 : " - Invoke-Command $session {foo -first 1} | Should Be "1 : " - Invoke-Command $session {foo 1 2 3} | Should Be "1 : 2 3" - Invoke-Command $session {foo -first 1 2 3} | Should Be "1 : 2 3" - Invoke-Command $session {foo 2 3 -first 1 4 5} | Should Be "1 : 2 3 4 5" - Invoke-Command $session {foo -remainingArgs 2,3 1} | Should Be "1 : 2 3" + Invoke-Command $session {foo} | Should -Be " : " + Invoke-Command $session {foo 1} | Should -Be "1 : " + Invoke-Command $session {foo -first 1} | Should -Be "1 : " + Invoke-Command $session {foo 1 2 3} | Should -Be "1 : 2 3" + Invoke-Command $session {foo -first 1 2 3} | Should -Be "1 : 2 3" + Invoke-Command $session {foo 2 3 -first 1 4 5} | Should -Be "1 : 2 3 4 5" + Invoke-Command $session {foo -remainingArgs 2,3 1} | Should -Be "1 : 2 3" $module = Import-PSSession $session foo -AllowClobber } @@ -1178,31 +1178,31 @@ try } It "Value from remaining arguments works" { - $( foo ) | Should Be " : " + $( foo ) | Should -Be " : " } It "Value from remaining arguments works" { - $( foo 1 ) | Should Be "1 : " + $( foo 1 ) | Should -Be "1 : " } It "Value from remaining arguments works" { - $( foo -first 1 ) | Should Be "1 : " + $( foo -first 1 ) | Should -Be "1 : " } It "Value from remaining arguments works" { - $( foo 1 2 3 ) | Should Be "1 : 2 3" + $( foo 1 2 3 ) | Should -Be "1 : 2 3" } It "Value from remaining arguments works" { - $( foo -first 1 2 3 ) | Should Be "1 : 2 3" + $( foo -first 1 2 3 ) | Should -Be "1 : 2 3" } It "Value from remaining arguments works" { - $( foo 2 3 -first 1 4 5 ) | Should Be "1 : 2 3 4 5" + $( foo 2 3 -first 1 4 5 ) | Should -Be "1 : 2 3 4 5" } It "Value from remaining arguments works" { - $( foo -remainingArgs 2,3 1 ) | Should Be "1 : 2 3" + $( foo -remainingArgs 2,3 1 ) | Should -Be "1 : 2 3" } } @@ -1222,17 +1222,17 @@ try } # Sanity checks. - Invoke-Command $session { foo } | Should Be " : : " - Invoke-Command $session { foo 1 } | Should Be "1 : : " - Invoke-Command $session { foo -first 1 } | Should Be "1 : : " - Invoke-Command $session { foo 1 2 } | Should Be "1 : 2 : " - Invoke-Command $session { foo 1 -second 2 } | Should Be "1 : 2 : " - Invoke-Command $session { foo -first 1 -second 2 } | Should Be "1 : 2 : " - Invoke-Command $session { foo 1 2 3 4 } | Should Be "1 : 2 : 3 4" - Invoke-Command $session { foo -first 1 2 3 4 } | Should Be "1 : 2 : 3 4" - Invoke-Command $session { foo 1 -second 2 3 4 } | Should Be "1 : 2 : 3 4" - Invoke-Command $session { foo 1 3 -second 2 4 } | Should Be "1 : 2 : 3 4" - Invoke-Command $session { foo -first 1 -second 2 3 4 } | Should Be "1 : 2 : 3 4" + Invoke-Command $session { foo } | Should -Be " : : " + Invoke-Command $session { foo 1 } | Should -Be "1 : : " + Invoke-Command $session { foo -first 1 } | Should -Be "1 : : " + Invoke-Command $session { foo 1 2 } | Should -Be "1 : 2 : " + Invoke-Command $session { foo 1 -second 2 } | Should -Be "1 : 2 : " + Invoke-Command $session { foo -first 1 -second 2 } | Should -Be "1 : 2 : " + Invoke-Command $session { foo 1 2 3 4 } | Should -Be "1 : 2 : 3 4" + Invoke-Command $session { foo -first 1 2 3 4 } | Should -Be "1 : 2 : 3 4" + Invoke-Command $session { foo 1 -second 2 3 4 } | Should -Be "1 : 2 : 3 4" + Invoke-Command $session { foo 1 3 -second 2 4 } | Should -Be "1 : 2 : 3 4" + Invoke-Command $session { foo -first 1 -second 2 3 4 } | Should -Be "1 : 2 : 3 4" $module = Import-PSSession $session foo -AllowClobber } @@ -1243,47 +1243,47 @@ try } It "Non cmdlet-based binding works." { - foo | Should Be " : : " + foo | Should -Be " : : " } It "Non cmdlet-based binding works." { - foo 1 | Should Be "1 : : " + foo 1 | Should -Be "1 : : " } It "Non cmdlet-based binding works." { - foo -first 1 | Should Be "1 : : " + foo -first 1 | Should -Be "1 : : " } It "Non cmdlet-based binding works." { - foo 1 2 | Should Be "1 : 2 : " + foo 1 2 | Should -Be "1 : 2 : " } It "Non cmdlet-based binding works." { - foo 1 -second 2 | Should Be "1 : 2 : " + foo 1 -second 2 | Should -Be "1 : 2 : " } It "Non cmdlet-based binding works." { - foo -first 1 -second 2 | Should Be "1 : 2 : " + foo -first 1 -second 2 | Should -Be "1 : 2 : " } It "Non cmdlet-based binding works." { - foo 1 2 3 4 | Should Be "1 : 2 : 3 4" + foo 1 2 3 4 | Should -Be "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo -first 1 2 3 4 | Should Be "1 : 2 : 3 4" + foo -first 1 2 3 4 | Should -Be "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo 1 -second 2 3 4 | Should Be "1 : 2 : 3 4" + foo 1 -second 2 3 4 | Should -Be "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo 1 3 -second 2 4 | Should Be "1 : 2 : 3 4" + foo 1 3 -second 2 4 | Should -Be "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo -first 1 -second 2 3 4 | Should Be "1 : 2 : 3 4" + foo -first 1 -second 2 3 4 | Should -Be "1 : 2 : 3 4" } } @@ -1299,7 +1299,7 @@ try $remotePid = Invoke-Command $session { $PID } # Sanity check - $localPid | Should Not Be $remotePid + $localPid | Should -Not -Be $remotePid $module = Import-PSSession -Session $session -Name MyInitializerFunction -AllowClobber } @@ -1310,11 +1310,11 @@ try } It "Initializer run on the remote server" { - (MyInitializerFunction) | Should Be $remotePid + (MyInitializerFunction) | Should -Be $remotePid } It "Initializer not run when value provided" { - (MyInitializerFunction 123) | Should Be 123 + (MyInitializerFunction 123) | Should -Be 123 } } @@ -1331,21 +1331,21 @@ try } It "Importing by name/type should work" { - (Get-Variable -Name PID).Value | Should Not Be $PID + (Get-Variable -Name PID).Value | Should -Not -Be $PID } It "Test -AsJob parameter" { try { $job = Get-Variable -Name PID -AsJob - $job | Should Not Be NullOrEmpty - ($job -is [System.Management.Automation.Job]) | Should Be $true - ($job.Finished.WaitOne([TimeSpan]::FromSeconds(10), $false)) | Should Be $true - $job.JobStateInfo.State | Should Be 'Completed' + $job | Should -Not -Be NullOrEmpty + ($job -is [System.Management.Automation.Job]) | Should -Be $true + ($job.Finished.WaitOne([TimeSpan]::FromSeconds(10), $false)) | Should -Be $true + $job.JobStateInfo.State | Should -Be 'Completed' $childJob = $job.ChildJobs[0] - $childJob.Output.Count | Should Be 1 - $childJob.Output[0].Value | Should Be $remotePid + $childJob.Output.Count | Should -Be 1 + $childJob.Output[0].Value | Should -Be $remotePid } finally { Remove-Job $job -Force } @@ -1353,8 +1353,8 @@ try It "Test OutVariable" { $result1 = Get-Variable -Name PID -OutVariable global:result2 - $result1.Value | Should Be $remotePid - $global:result2[0].Value | Should Be $remotePid + $result1.Value | Should -Be $remotePid + $global:result2[0].Value | Should -Be $remotePid } } @@ -1374,7 +1374,7 @@ try $jobWithWarnings = write-remotewarning foo -WarningAction continue -Asjob $null = Wait-Job $jobWithWarnings - $jobWithWarnings.ChildJobs[0].Warning.Count | Should Be 1 + $jobWithWarnings.ChildJobs[0].Warning.Count | Should -Be 1 } finally { Remove-Job $jobWithWarnings -Force } @@ -1385,7 +1385,7 @@ try $jobWithoutWarnings = write-remotewarning foo -WarningAction silentlycontinue -Asjob $null = Wait-Job $jobWithoutWarnings - $jobWithoutWarnings.ChildJobs[0].Warning.Count | Should Be 0 + $jobWithoutWarnings.ChildJobs[0].Warning.Count | Should -Be 0 } finally { Remove-Job $jobWithoutWarnings -Force } @@ -1399,7 +1399,7 @@ try Invoke-Command $session { function foo { param($OutVariable) "OutVariable = $OutVariable" } } # Sanity check - Invoke-Command $session { foo -OutVariable x } | Should Be "OutVariable = x" + Invoke-Command $session { foo -OutVariable x } | Should -Be "OutVariable = x" $module = Import-PSSession -Session $session -Name foo -Type function -AllowClobber } @@ -1410,7 +1410,7 @@ try } It "Implicit remoting: OutVariable is not intercepted for non-cmdlet-bound functions" { - foo -OutVariable x | Should Be "OutVariable = x" + foo -OutVariable x | Should -Be "OutVariable = x" } } @@ -1428,12 +1428,12 @@ try It "Switch parameters work fine" { $proxiedPid = Get-RemoteVariable -Name pid -ValueOnly - $remotePid | Should Be $proxiedPid + $remotePid | Should -Be $proxiedPid } It "Positional parameters work fine" { $proxiedPid = Get-RemoteVariable pid - $remotePid | Should Be ($proxiedPid.Value) + $remotePid | Should -Be ($proxiedPid.Value) } } } @@ -1502,7 +1502,7 @@ try -Force $session = New-RemoteSession -ConfigurationName $myConfiguration.Name - $session | Should Not Be $null + $session | Should -Not -Be $null } AfterAll { @@ -1514,10 +1514,10 @@ try Context "restrictions works" { It "Get-Variable is private" { - @(Invoke-Command $session { Get-Command -Name Get-Variabl* }).Count | Should Be 0 + @(Invoke-Command $session { Get-Command -Name Get-Variabl* }).Count | Should -Be 0 } It "Only 9 commands are public" { - @(Invoke-Command $session { Get-Command }).Count | Should Be 9 + @(Invoke-Command $session { Get-Command }).Count | Should -Be 9 } } @@ -1532,24 +1532,24 @@ try } It "Import-PSSession works against the ISS-restricted runspace (Out-String)" { - @(Get-Command Out-String -Type Function).Count | Should Be 1 + @(Get-Command Out-String -Type Function).Count | Should -Be 1 } It "Import-PSSession works against the ISS-restricted runspace (Measure-Object)" { - @(Get-Command Measure-Object -Type Function).Count | Should Be 1 + @(Get-Command Measure-Object -Type Function).Count | Should -Be 1 } It "Invoking an implicit remoting proxy works against the ISS-restricted runspace (Out-String)" { $remoteResult = Out-String -input ("blah " * 10) -Width 10 $localResult = Microsoft.PowerShell.Utility\Out-String -input ("blah " * 10) -Width 10 - $localResult | Should Be $remoteResult + $localResult | Should -Be $remoteResult } It "Invoking an implicit remoting proxy works against the ISS-restricted runspace (Measure-Object)" { $remoteResult = 1..10 | Measure-Object $localResult = 1..10 | Microsoft.PowerShell.Utility\Measure-Object - ($localResult.Count) | Should Be ($remoteResult.Count) + ($localResult.Count) | Should -Be ($remoteResult.Count) } } } @@ -1578,27 +1578,27 @@ try } It "PSModuleInfo.Name shouldn't contain a psd1 extension" { - ($module.Name -notlike '*.psd1') | Should Be $true + ($module.Name -notlike '*.psd1') | Should -Be $true } It "PSModuleInfo.Name shouldn't contain a psm1 extension" { - ($module.Name -notlike '*.psm1') | Should Be $true + ($module.Name -notlike '*.psm1') | Should -Be $true } It "PSModuleInfo.Name shouldn't contain a path" { - ($module.Name -notlike "${env:TMP}*") | Should Be $true + ($module.Name -notlike "${env:TMP}*") | Should -Be $true } It "Get-Command returns only 1 public command from implicit remoting module (1)" { $c = @(Get-Command -Module $module) - $c.Count | Should Be 1 - $c[0].Name | Should Be "Get-MyVariable" + $c.Count | Should -Be 1 + $c[0].Name | Should -Be "Get-MyVariable" } It "Get-Command returns only 1 public command from implicit remoting module (2)" { $c = @(Get-Command -Module $module.Name) - $c.Count | Should Be 1 - $c[0].Name | Should Be "Get-MyVariable" + $c.Count | Should -Be 1 + $c[0].Name | Should -Be "Get-MyVariable" } } @@ -1617,7 +1617,7 @@ try } It "'Completed' progress record should be present" { - ($powerShell.Streams.Progress | Select-Object -last 1).RecordType.ToString() | Should Be "Completed" + ($powerShell.Streams.Progress | Select-Object -last 1).RecordType.ToString() | Should -Be "Completed" } } @@ -1631,10 +1631,10 @@ try # Since New-PSSession now only loads Microsoft.PowerShell.Core and for the session in the test, Autoloading is disabled, engine cannot find New-Object as it is part of Microsoft.PowerShell.Utility module. # The fix is to import this module before running the command. It "Display of local property-less objects" { - ($x | Out-String).Trim() | Should Be $expected + ($x | Out-String).Trim() | Should -Be $expected } It "Display of remote property-less objects" { - (Invoke-Command $session { Import-Module Microsoft.PowerShell.Utility; New-Object random } | out-string).Trim() | Should Be $expected + (Invoke-Command $session { Import-Module Microsoft.PowerShell.Utility; New-Object random } | out-string).Trim() | Should -Be $expected } } @@ -1642,7 +1642,7 @@ try try { $module = Import-PSSession -Session $session -Name Write-Output -AllowClobber $result = Write-Output 123 | Write-Output - $result | Should Be 123 + $result | Should -Be 123 } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -1652,7 +1652,7 @@ try try { Invoke-Command $session { function attack(${foo="$(calc)"}){echo "It is done."}} $module = Import-PSSession -Session $session -CommandName attack -ErrorAction SilentlyContinue -ErrorVariable expectedError -AllowClobber - $expectedError | Should Not Be NullOrEmpty + $expectedError | Should -Not -Be NullOrEmpty } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -1664,10 +1664,10 @@ try Invoke-Command $session { function Get-Command { write-error blah } } $module = Import-PSSession -Session $session -ErrorAction SilentlyContinue -ErrorVariable expectedError -AllowClobber - $expectedError | Should Not Be NullOrEmpty + $expectedError | Should -Not -Be NullOrEmpty $msg = [string]($expectedError[0]) - $msg.Contains("blah") | Should Be $true + $msg.Contains("blah") | Should -Be $true } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1680,10 +1680,10 @@ try Invoke-Command $session { function notRequested { "notRequested" }; function Get-Command { Microsoft.PowerShell.Core\Get-Command Get-Variable,notRequested } } $module = Import-PSSession -Session $session Get-Variable -AllowClobber -ErrorAction SilentlyContinue -ErrorVariable expectedError - $expectedError | Should Not Be NullOrEmpty + $expectedError | Should -Not -Be NullOrEmpty $msg = [string]($expectedError[0]) - $msg.Contains("notRequested") | Should Be $true + $msg.Contains("notRequested") | Should -Be $true } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1699,7 +1699,7 @@ try throw "Import-PSSession should throw" } catch { $msg = [string]($_) - $msg.Contains("Get-Command") | Should Be $true + $msg.Contains("Get-Command") | Should -Be $true } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1724,7 +1724,7 @@ try $module = Import-PSSession $session myOrder -CommandType All -AllowClobber $actualResult = myOrder -aliasParam 123 - $expectedResult | Should Be $actualResult + $expectedResult | Should -Be $actualResult } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { param($x) $env:PATH = $x; Remove-Item Alias:\myOrder, Function:\myOrder, Function:\helper -Force -ErrorAction SilentlyContinue } -ArgumentList $oldPath @@ -1735,12 +1735,12 @@ try It "Test -Prefix parameter" { try { $module = Import-PSSession -Session $session -Name Get-Variable -Type cmdlet -Prefix My -AllowClobber - (Get-MyVariable -Name pid).Value | Should Not Be $PID + (Get-MyVariable -Name pid).Value | Should -Not -Be $PID } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } - (Get-Item function:Get-MyVariable -ErrorAction SilentlyContinue) | Should Be $null + (Get-Item function:Get-MyVariable -ErrorAction SilentlyContinue) | Should -Be $null } Context "BadVerbs of functions should trigger a warning" { @@ -1758,8 +1758,8 @@ try $ps = [powershell]::Create().AddCommand("Import-PSSession", $true).AddParameter("Session", $session).AddParameter("CommandName", "BadVerb-Variable") $module = $ps.Invoke() | Select-Object -First 1 - $ps.Streams.Error.Count | Should Be 0 - $ps.Streams.Warning.Count | Should Not Be 0 + $ps.Streams.Error.Count | Should -Be 0 + $ps.Streams.Warning.Count | Should -Not -Be 0 } finally { if ($null -ne $module) { $ps.Commands.Clear() @@ -1776,18 +1776,18 @@ try $remotePid = Invoke-Command $session { $PID } $getVariablePid = Invoke-Command $session { (Get-Variable -Name PID).Value } - $getVariablePid | Should Be $remotePid + $getVariablePid | Should -Be $remotePid ## Get-Variable function should not be exported when importing a BadVerb-Variable function - Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should Be $null + Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -Be $null ## BadVerb-Variable should be a function, not an alias (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Not Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null ## BadVerb-Variable should be a function, not an alias (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null - (BadVerb-Variable -Name pid).Value | Should Be $remotePid + (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -1798,8 +1798,8 @@ try $ps = [powershell]::Create().AddCommand("Import-PSSession", $true).AddParameter("Session", $session).AddParameter("CommandName", "BadVerb-Variable").AddParameter("DisableNameChecking", $true) $module = $ps.Invoke() | Select-Object -First 1 - $ps.Streams.Error.Count | Should Be 0 - $ps.Streams.Warning.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 + $ps.Streams.Warning.Count | Should -Be 0 } finally { if ($null -ne $module) { $ps.Commands.Clear() @@ -1816,18 +1816,18 @@ try $remotePid = Invoke-Command $session { $PID } $getVariablePid = Invoke-Command $session { (Get-Variable -Name PID).Value } - $getVariablePid | Should Be $remotePid + $getVariablePid | Should -Be $remotePid ## Get-Variable function should not be exported when importing a BadVerb-Variable function - Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should Be $null + Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -Be $null ## BadVerb-Variable should be a function, not an alias (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Not Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null ## BadVerb-Variable should be a function, not an alias (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null - (BadVerb-Variable -Name pid).Value | Should Be $remotePid + (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -1849,8 +1849,8 @@ try $ps = [powershell]::Create().AddCommand("Import-PSSession", $true).AddParameter("Session", $session).AddParameter("CommandName", "BadVerb-Variable") $module = $ps.Invoke() | Select-Object -First 1 - $ps.Streams.Error.Count | Should Be 0 - $ps.Streams.Warning.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 + $ps.Streams.Warning.Count | Should -Be 0 } finally { if ($null -ne $module) { $ps.Commands.Clear() @@ -1867,15 +1867,15 @@ try $remotePid = Invoke-Command $session { $PID } $getVariablePid = Invoke-Command $session { (Get-Variable -Name PID).Value } - $getVariablePid | Should Be $remotePid + $getVariablePid | Should -Be $remotePid ## BadVerb-Variable should be an alias, not a function (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null ## BadVerb-Variable should be an alias, not a function (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should Not Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null - (BadVerb-Variable -Name pid).Value | Should Be $remotePid + (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -1890,10 +1890,10 @@ try $newNumberOfHandlers = $executionContext.GetType().GetProperty("Events").GetValue($executionContext, $null).Subscribers.Count ## Event should be unregistered when the module is removed - $oldNumberOfHandlers | Should Be $newNumberOfHandlers + $oldNumberOfHandlers | Should -Be $newNumberOfHandlers ## Private functions from the implicit remoting module shouldn't get imported into global scope - @(dir function:*Implicit* -ErrorAction SilentlyContinue).Count | Should Be 0 + @(dir function:*Implicit* -ErrorAction SilentlyContinue).Count | Should -Be 0 } } @@ -1929,11 +1929,11 @@ try $result = $ps.AddScript(" & $tempdir\TestBug450687.ps1").Invoke() ## The module created by Export-PSSession is imported successfully - ($null -ne $result -and $result.Count -eq 1 -and $result[0].Name -eq "Diag") | Should Be $true + ($null -ne $result -and $result.Count -eq 1 -and $result[0].Name -eq "Diag") | Should -Be $true ## The command Add-BitsFile is imported successfully $c = $result[0].ExportedCommands["New-Guid"] - ($null -ne $c -and $c.CommandType -eq "Function") | Should Be $true + ($null -ne $c -and $c.CommandType -eq "Function") | Should -Be $true } finally { $ps.Dispose() } @@ -1957,16 +1957,16 @@ try It "Remote session PID should be different" { $sessionPid = Get-RemoteVariable pid - $sessionPid.Value | Should Be $remotePid + $sessionPid.Value | Should -Be $remotePid } It "Disconnected session should be reconnected when calling proxied command" { Disconnect-PSSession $session $dSessionPid = Get-RemoteVariable pid - $dSessionPid.Value | Should Be $remotePid + $dSessionPid.Value | Should -Be $remotePid - $session.State | Should Be 'Opened' + $session.State | Should -Be 'Opened' } ## It requires 'New-PSSession' to work with implicit credential to allow proxied command to create new session. @@ -1980,7 +1980,7 @@ try ## This time a new session is created because the old one is unavailable. $dSessionPid = Get-RemoteVariable pid - $dSessionPid.Value | Should Not Be $remotePid + $dSessionPid.Value | Should -Not -Be $remotePid } } @@ -2001,10 +2001,10 @@ try It "Select -First should work with implicit remoting" { $bar = foo | Select-Object -First 2 - $bar | Should Not Be NullOrEmpty - $bar.Count | Should Be 2 - $bar[0] | Should Be "a" - $bar[1] | Should Be "b" + $bar | Should -Not -Be NullOrEmpty + $bar.Count | Should -Be 2 + $bar[0] | Should -Be "a" + $bar[1] | Should -Be "b" } } @@ -2038,7 +2038,7 @@ try try { $results = Export-PSSession -Session $session -OutputModule tempTest -CommandName Get-Process ` -AllowClobber -FormatTypeName * -Force -ErrorAction Stop - $results.Count | Should Not Be 0 + $results.Count | Should -Not -Be 0 } finally { if ($results.Count -gt 0) { Remove-Item -Path $results[0].DirectoryName -Recurse -Force -ErrorAction SilentlyContinue @@ -2062,7 +2062,7 @@ try It "Verifies that the number of local cmdlet command count is the same as remote cmdlet command count." { $localCommandCount = (Get-Command -Type Cmdlet).Count $remoteCommandCount = Invoke-Command { (Get-Command -Type Cmdlet).Count } - $localCommandCount | Should Be $remoteCommandCount + $localCommandCount | Should -Be $remoteCommandCount } } @@ -2097,7 +2097,7 @@ try if ($module -ne $null) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } - $errorVariable | Should BeNullOrEmpty + $errorVariable | Should -BeNullOrEmpty } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 index 2b72bb83cf8..50225ddca0f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 @@ -30,36 +30,36 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" } } It "Import-Alias From Exported Alias File Aliases Already Exist should throw SessionStateException" { $ErrorActionPreference = "Stop" - {Export-Alias $fulltestpath abcd*}| Should Not Throw + {Export-Alias $fulltestpath abcd*}| Should -Not -Throw try { Import-Alias $fulltestpath Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" } } It "Import-Alias Into Invalid Scope should throw PSArgumentException"{ - {Export-Alias $fulltestpath abcd*}| Should Not Throw + {Export-Alias $fulltestpath abcd*}| Should -Not -Throw try { Import-Alias $fulltestpath -scope bogus Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" } } It "Import-Alias From Exported Alias File Aliases Already Exist using force should not throw"{ - {Export-Alias $fulltestpath abcd*}| Should Not Throw - {Import-Alias $fulltestpath -Force}| Should Not Throw + {Export-Alias $fulltestpath abcd*}| Should -Not -Throw + {Import-Alias $fulltestpath -Force}| Should -Not -Throw } } @@ -84,20 +84,20 @@ Describe "Import-Alias" -Tags "CI" { } It "Should be able to import an alias file successfully" { - { Import-Alias $pesteraliasfile } | Should Not throw + { Import-Alias $pesteraliasfile } | Should -Not -throw } It "Should be able to import file via the Import-Alias alias of ipal" { - { ipal $pesteraliasfile } | Should Not throw + { ipal $pesteraliasfile } | Should -Not -throw } It "Should be able to import an alias file and perform imported aliased echo cmd" { (Import-Alias $pesteraliasfile) - (pesterecho pestertesting) | Should Be "pestertesting" + (pesterecho pestertesting) | Should -Be "pestertesting" } It "Should be able to use ipal alias to import an alias file and perform cmd" { (ipal $pesteraliasfile) - (pesterecho pestertesting) | Should be "pestertesting" + (pesterecho pestertesting) | Should -be "pestertesting" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 index 35cd18884dd..25d6ec0469a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 @@ -10,15 +10,15 @@ Describe "Import-Csv DRT Unit Tests" -Tags "CI" { $delimiter = ';' $psObject | Export-Csv -Path $fileToGenerate -Delimiter $delimiter $returnObject = Import-Csv -Path $fileToGenerate -Delimiter $delimiter - $returnObject.First | Should Be 1 - $returnObject.Second | Should Be 2 + $returnObject.First | Should -Be 1 + $returnObject.Second | Should -Be 2 } It "Test import-csv with UseCulture parameter" { $psObject | Export-Csv -Path $fileToGenerate -UseCulture $returnObject = Import-Csv -Path $fileToGenerate -UseCulture - $returnObject.First | Should Be 1 - $returnObject.Second | Should Be 2 + $returnObject.First | Should -Be 1 + $returnObject.Second | Should -Be 2 } } @@ -55,21 +55,21 @@ Describe "Import-Csv File Format Tests" -Tags "CI" { It "Should be able to import all fields" { $actual = Import-Csv -Path $testCsv @HeaderParams $actualfields = $actual[0].psobject.Properties.Name - $actualfields | Should Be $orginalHeader + $actualfields | Should -Be $orginalHeader } It "Should be able to import all fields with custom header" { $actual = Import-Csv -Path $testCsv @CustomHeaderParams $actualfields = $actual[0].psobject.Properties.Name - $actualfields | Should Be $customHeader + $actualfields | Should -Be $customHeader } It "Should be able to import correct values" { $actual = Import-Csv -Path $testCsv @HeaderParams - $actual.count | Should Be 4 - $actual[0].'Column1' | Should Be "data1" - $actual[0].'Column2' | Should Be "1" - $actual[0].'Column 3' | Should Be "A" + $actual.count | Should -Be 4 + $actual[0].'Column1' | Should -Be "data1" + $actual[0].'Column2' | Should -Be "1" + $actual[0].'Column 3' | Should -Be "A" } } @@ -87,12 +87,12 @@ Describe "Import-Csv #Type Tests" -Tags "CI" { It "Test import-csv import Object" { $importObjectList = Import-Csv -Path $testfile - $processlist.Count | Should Be $importObjectList.Count + $processlist.Count | Should -Be $importObjectList.Count $importTypes = $importObjectList[0].psobject.TypeNames - $importTypes.Count | Should Be $expectedProcessTypes.Count - $importTypes[0] | Should Be $expectedProcessTypes[0] - $importTypes[1] | Should Be $expectedProcessTypes[1] + $importTypes.Count | Should -Be $expectedProcessTypes.Count + $importTypes[0] | Should -Be $expectedProcessTypes[0] + $importTypes[1] | Should -Be $expectedProcessTypes[1] } } @@ -107,12 +107,12 @@ Describe "Import-Csv with different newlines" -Tags "CI" { $delimiter = ',' "h1,h2,h3$($newline)11,12,13$($newline)21,22,23$($newline)" | Out-File -FilePath $csvFile $returnObject = Import-Csv -Path $csvFile -Delimiter $delimiter - $returnObject.Count | Should Be 2 - $returnObject[0].h1 | Should Be 11 - $returnObject[0].h2 | Should Be 12 - $returnObject[0].h3 | Should Be 13 - $returnObject[1].h1 | Should Be 21 - $returnObject[1].h2 | Should Be 22 - $returnObject[1].h3 | Should Be 23 + $returnObject.Count | Should -Be 2 + $returnObject[0].h1 | Should -Be 11 + $returnObject[0].h2 | Should -Be 12 + $returnObject[0].h3 | Should -Be 13 + $returnObject[1].h1 | Should -Be 21 + $returnObject[1].h2 | Should -Be 22 + $returnObject[1].h3 | Should -Be 23 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 index db38f33b9e9..72fa60aa335 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 @@ -13,25 +13,25 @@ Describe "Import-LocalizedData" -Tags "CI" { It "Should be able to import string using default culture" { # Set-Culture is broken, but let's verify that default culture is en-US $culture = Get-Culture -$culture.Name | Should Be "en-US" +$culture.Name | Should -Be "en-US" $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -$d.d0 | Should be $sunday +$d.d0 | Should -be $sunday } It "Should be able to import string using en-US culture" { $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US - $d.d0 | Should be $sunday + $d.d0 | Should -be $sunday } It "Should be able to import string using de-DE culture" { $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE - $d.d0 | Should be $sundayInGerman + $d.d0 | Should -be $sundayInGerman } It "Should be able to import string and store in binding variable" { Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d - $d.d0 | Should be $sundayInGerman + $d.d0 | Should -be $sundayInGerman } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 index cf0bc73f09a..271ab6f9e58 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 @@ -42,22 +42,22 @@ Describe "Using delimiters with Export-CSV and Import-CSV behave correctly" -tag It "Disallow use of null delimiter" { $d | export-csv TESTDRIVE:/file.csv - { import-csv -path TESTDRIVE:/file.csv -delimiter $null } | Should Throw "Delimiter" + { import-csv -path TESTDRIVE:/file.csv -delimiter $null } | Should -Throw "Delimiter" } It "Disallow use of delimiter with useCulture parameter" { $d | export-csv TESTDRIVE:/file.csv - { import-csv -path TESTDRIVE:/file.csv -useCulture "," } | Should Throw "','" + { import-csv -path TESTDRIVE:/file.csv -useCulture "," } | Should -Throw "','" } It "Imports the same properties as exported" { $a = [pscustomobject]@{ a = 1; b = 2; c = 3 } $a | export-Csv TESTDRIVE:/file.csv $b = import-csv TESTDRIVE:/file.csv - @($b.psobject.properties).count | should be 3 - $b.a | Should be $a.a - $b.b | Should be $a.b - $b.c | Should be $a.c + @($b.psobject.properties).count | should -be 3 + $b.a | Should -be $a.a + $b.b | Should -be $a.b + $b.c | Should -be $a.c } # parameter generated tests @@ -66,7 +66,7 @@ Describe "Using delimiters with Export-CSV and Import-CSV behave correctly" -tag set-Delimiter $delimiter $Data | export-CSV TESTDRIVE:\File.csv -useCulture $i = Import-CSV TESTDRIVE:\File.csv - $i.Ticks | Should Not Be $ExpectedResult + $i.Ticks | Should -Not -Be $ExpectedResult } It 'Delimiter with CSV import will succeed when culture matches export' -testCases $testCases { @@ -74,13 +74,13 @@ Describe "Using delimiters with Export-CSV and Import-CSV behave correctly" -tag set-Delimiter $delimiter $Data | export-CSV TESTDRIVE:\File.csv -useCulture $i = Import-CSV TESTDRIVE:\File.csv -useCulture - $i.Ticks | Should Be $ExpectedResult + $i.Ticks | Should -Be $ExpectedResult } It 'Delimiter with CSV import will succeed when delimiter is used explicitly' -testCases $testCases { param ($delimiter, $Data, $ExpectedResult) $Data | export-CSV TESTDRIVE:\File.csv -delimiter $delimiter $i = Import-CSV TESTDRIVE:\File.csv -delimiter $delimiter - $i.Ticks | Should Be $ExpectedResult + $i.Ticks | Should -Be $ExpectedResult } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 index 909363b7bea..0d7b76743b1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 @@ -5,14 +5,14 @@ Describe "Invoke-Expression" -Tags "CI" { Context "Should execute the invoked command validly" { It "Should return the echoed text" { - (Invoke-Expression -command "echo pestertest1") | Should be "pestertest1" + (Invoke-Expression -command "echo pestertest1") | Should -be "pestertest1" } It "Should return the echoed text from a script" { $testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1 $testcommand = "echo pestertestscript" $testcommand | Add-Content -Path "$testfile" - (Invoke-Expression "& '$testfile'") | Should Be "pestertestscript" + (Invoke-Expression "& '$testfile'") | Should -Be "pestertestscript" Remove-Item "$testfile" } } @@ -20,6 +20,6 @@ Describe "Invoke-Expression" -Tags "CI" { Describe "Invoke-Expression DRT Unit Tests" -Tags "CI" { It "Invoke-Expression should work"{ $result=invoke-expression -Command 2+2 - $result|Should Be 4 + $result|Should -Be 4 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 index 4c8f47a444f..6c820847860 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 @@ -45,8 +45,8 @@ Describe "Invoke-Item basic tests" -Tags "Feature" { $title = 'tell application "TextEdit" to get name of front window' | osascript } $afterCount = [int]('tell application "TextEdit" to count of windows' | osascript) - $afterCount | Should Be ($beforeCount + 1) - $title | Should Be $expectedTitle + $afterCount | Should -Be ($beforeCount + 1) + $title | Should -Be $expectedTitle "tell application ""TextEdit"" to close window ""$expectedTitle""" | osascript 'tell application "TextEdit" to quit' | osascript } @@ -62,7 +62,7 @@ Describe "Invoke-Item basic tests" -Tags "Feature" { ## On headless SKUs, we use `UseShellExecute = false` ## 'ping.exe' on Windows writes out usage to stdout. & $powershell -noprofile -c "Invoke-Item '$ping'" > $redirectFile - Get-Content $redirectFile -Raw | Should Match "usage: ping" + Get-Content $redirectFile -Raw | Should -Match "usage: ping" } else { ## On full desktop, we use `UseShellExecute = true` to align with Windows PowerShell $notepad = Get-Command "notepad.exe" -CommandType Application | ForEach-Object Source @@ -71,14 +71,14 @@ Describe "Invoke-Item basic tests" -Tags "Feature" { Invoke-Item -Path $notepad $notepadProcess = Get-Process -Name $notepadProcessName # we need BeIn because multiple notepad processes could be running - $notepadProcess.Name | Should BeIn $notepadProcessName + $notepadProcess.Name | Should -BeIn $notepadProcessName Stop-Process -InputObject $notepadProcess } } else { ## On Unix, we use `UseShellExecute = false` ## 'ping' on Unix write out usage to stderr & $powershell -noprofile -c "Invoke-Item '$ping'" 2> $redirectFile - Get-Content $redirectFile -Raw | Should Match "usage: ping" + Get-Content $redirectFile -Raw | Should -Match "usage: ping" } } @@ -133,9 +133,9 @@ Categories=Application; Wait-UntilTrue -sb { $windows.Count -gt $before } -TimeoutInMilliseconds (10*1000) -IntervalInMilliseconds 100 > $null $after = $windows.Count - $before + 1 | Should Be $after + $before + 1 | Should -Be $after $item = $windows.Item($after - 1) - $item.LocationURL | Should Match ($PSHOME -replace '\\', '/') + $item.LocationURL | Should -Match ($PSHOME -replace '\\', '/') ## close the windows explorer $item.Quit() } @@ -145,7 +145,7 @@ Categories=Application; Invoke-Item -Path $PSHOME # may take time for handler to start Wait-FileToBePresent -File "$HOME/InvokeItemTest.Success" -TimeoutInSeconds 10 -IntervalInMilliseconds 100 - Get-Content $HOME/InvokeItemTest.Success | Should Be $PSHOME + Get-Content $HOME/InvokeItemTest.Success | Should -Be $PSHOME } else { @@ -161,8 +161,8 @@ Categories=Application; $title = 'tell application "Finder" to get name of front window' | osascript } $afterCount = [int]('tell application "Finder" to count of windows' | osascript) - $afterCount | Should Be ($beforeCount + 1) - $title | Should Be $expectedTitle + $afterCount | Should -Be ($beforeCount + 1) + $title | Should -Be $expectedTitle 'tell application "Finder" to close front window' | osascript } } @@ -212,11 +212,11 @@ Describe "Invoke-Item tests on Windows" -Tags "CI","RequireAdminOnWindows" { Start-Sleep -Milliseconds 100 if (([Datetime]::Now - $startTime) -ge [timespan]"00:00:05") { throw "Timeout exception" } } - } | Should Not throw + } | Should -Not -throw } It "Should start a file without error on Windows full SKUs" -Skip:(-not $isFullWin) { Start-Process $testfilepath -Wait - Test-Path $renamedtestfilepath | Should Be $true + Test-Path $renamedtestfilepath | Should -Be $true } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 index 030534357ef..2c3d2d6c412 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 @@ -20,7 +20,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { param ($str, $ReturnHashTable) $errRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($str, $ReturnHashTable, [ref]$errRecord) - $errRecord | Should BeNullOrEmpty + $errRecord | Should -BeNullOrEmpty } It 'Throw ArgumentException for invalid string '''' with -ReturnHashTable:$' -TestCase @( @@ -38,15 +38,15 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains empty key name' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should Be 'EmptyKeyInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -Be 'EmptyKeyInJsonString' } It 'Not throw when json contains empty key name when ReturnHashTable is true' { $errorRecord = $null $result = [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, $true, [ref]$errorRecord) - $result | Should Not Be $null - $result.Count | Should Be 1 - $result.'' | Should Be 'Value' + $result | Should -Not -Be $null + $result.Count | Should -Be 1 + $result.'' | Should -Be 'Value' } } @@ -55,16 +55,16 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains key with different casing' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should Be 'KeysWithDifferentCasingInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -Be 'KeysWithDifferentCasingInJsonString' } It 'Not throw when json contains key (same casing) when ReturnHashTable is true' { $errorRecord = $null $result = [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, $true, [ref]$errorRecord) - $result | Should Not Be $null - $result.Count | Should Be 2 - $result.key1 | Should Be 'Value1' - $result.Key1 | Should Be 'Value2' + $result | Should -Not -Be $null + $result.Count | Should -Be 2 + $result.key1 | Should -Be 'Value1' + $result.Key1 | Should -Be 'Value2' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Command.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Command.Tests.ps1 index c0ee88abe46..053a2043de3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Command.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Command.Tests.ps1 @@ -5,14 +5,14 @@ Describe "Measure-Command" -Tags "CI" { Context "Validate return types for Measure-Command" { It "Should return TimeSpan as the return type" { - Measure-Command { Get-Date } | Should BeOfType timespan + Measure-Command { Get-Date } | Should -BeOfType timespan } } Context "Validate that it is executing commands correctly" { It "Should return TimeSpan after executing a script" { - Measure-Command { echo hi } | Should BeOfType timespan + Measure-Command { echo hi } | Should -BeOfType timespan } It "Should return TimeSpan after executing a cmdlet" { @@ -21,7 +21,7 @@ Describe "Measure-Command" -Tags "CI" { $testcommand = "echo pestertestscript" $testcommand | Add-Content -Path $testfile - Measure-Command { $pesterscript } | Should BeOfType timespan + Measure-Command { $pesterscript } | Should -BeOfType timespan Remove-Item $testfile } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 index 6791d790a1a..4dfa2637675 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 @@ -6,38 +6,38 @@ Describe "Measure-Object" -Tags "CI" { } It "Should be able to be called without error" { - { Measure-Object | Out-Null } | Should Not Throw + { Measure-Object | Out-Null } | Should -Not -Throw } It "Should be able to call on piped input" { - { $testObject | Measure-Object } | Should Not Throw + { $testObject | Measure-Object } | Should -Not -Throw } It "Should be able to count the number of objects input to it" { - $($testObject | Measure-Object).Count | Should Be $testObject.Length + $($testObject | Measure-Object).Count | Should -Be $testObject.Length } It "Should be able to count using the Property switch" { $expected = $(Get-ChildItem $TestDrive).Length $actual = $(Get-ChildItem $TestDrive | Measure-Object -Property Length).Count - $actual | Should Be $expected + $actual | Should -Be $expected } It "Should be able to use wildcards for the Property argument" { $data = [pscustomobject]@{ A1 = 1; A2 = 2; C3 = 3 }, [pscustomobject]@{ A1 = 1; A2 = 2; A3 = 3 } $actual = $data | Measure-Object -Property A* -Sum - $actual.Count | Should Be 3 - $actual[0].Property | Should Be A1 - $actual[0].Sum | Should Be 2 - $actual[0].Count | Should Be 2 - $actual[1].Property | Should Be A2 - $actual[1].Sum | Should Be 4 - $actual[1].Count | Should Be 2 - $actual[2].Property | Should Be A3 - $actual[2].Sum | Should Be 3 - $actual[2].Count | Should Be 1 + $actual.Count | Should -Be 3 + $actual[0].Property | Should -Be A1 + $actual[0].Sum | Should -Be 2 + $actual[0].Count | Should -Be 2 + $actual[1].Property | Should -Be A2 + $actual[1].Sum | Should -Be 4 + $actual[1].Count | Should -Be 2 + $actual[2].Property | Should -Be A3 + $actual[2].Sum | Should -Be 3 + $actual[2].Count | Should -Be 1 } Context "Numeric tests" { @@ -50,7 +50,7 @@ Describe "Measure-Object" -Tags "CI" { $expected += $obj } - $actual.Sum | Should Be $expected + $actual.Sum | Should -Be $expected } It "Should be able to average" { @@ -64,7 +64,7 @@ Describe "Measure-Object" -Tags "CI" { $expected /= $testObject.length - $actual.Average | Should Be $expected + $actual.Average | Should -Be $expected } It "Should be able to return a minimum" { @@ -79,7 +79,7 @@ Describe "Measure-Object" -Tags "CI" { } } - $actual.Minimum | Should Be $expected + $actual.Minimum | Should -Be $expected } It "Should be able to return a minimum when multiple objects are the minimum" { @@ -95,7 +95,7 @@ Describe "Measure-Object" -Tags "CI" { } } - $actual.Minimum | Should Be $expected + $actual.Minimum | Should -Be $expected } It "Should be able to return a maximum" { @@ -110,7 +110,7 @@ Describe "Measure-Object" -Tags "CI" { } } - $actual.Maximum | Should Be $expected + $actual.Maximum | Should -Be $expected } It "Should be able to return a maximum when multiple objects are the maximum" { @@ -126,7 +126,7 @@ Describe "Measure-Object" -Tags "CI" { } } - $actual.Maximum | Should Be $expected + $actual.Maximum | Should -Be $expected } } @@ -140,21 +140,21 @@ Describe "Measure-Object" -Tags "CI" { $expectedLength = $testString.Replace($nl,"").Split().length $actualLength = $testString | Measure-Object -Word - $actualLength.Words | Should Be $expectedLength + $actualLength.Words | Should -Be $expectedLength } It "Should be able to count the number of characters in a string" { $expectedLength = $testString.length $actualLength = $testString | Measure-Object -Character - $actualLength.Characters | Should Be $expectedLength + $actualLength.Characters | Should -Be $expectedLength } It "Should be able to count the number of lines in a string" { $expectedLength = $testString.Split($nl, [System.StringSplitOptions]::RemoveEmptyEntries).length $actualLength = $testString | Measure-Object -Line - $actualLength.Lines | Should Be $expectedLength + $actualLength.Lines | Should -Be $expectedLength } } } @@ -203,11 +203,11 @@ Describe "Measure-Object DRT basic functionality" -Tags "CI" { $testMax = ($flags -band [TestMeasureGeneric]::TestMax) -gt 0 $testMin = ($flags -band [TestMeasureGeneric]::TestMin) -gt 0 $result = $employees | Measure-Object -Sum:$testSum -Average:$testAverage -Max:$testMax -Min:$testMin -Prop $property - $result.Count | Should Be 4 - $result.Sum | Should BeNullOrEmpty - $result.Average | Should BeNullOrEmpty - $result.Max | Should BeNullOrEmpty - $result.Min | Should BeNullOrEmpty + $result.Count | Should -Be 4 + $result.Sum | Should -BeNullOrEmpty + $result.Average | Should -BeNullOrEmpty + $result.Max | Should -BeNullOrEmpty + $result.Min | Should -BeNullOrEmpty for ($i = 1; $i -lt 8 * 2; $i++) { $flags = [TestMeasureGeneric]$i @@ -217,41 +217,41 @@ Describe "Measure-Object DRT basic functionality" -Tags "CI" { $testMax = ($flags -band [TestMeasureGeneric]::TestMax) -gt 0 $testMin = ($flags -band [TestMeasureGeneric]::TestMin) -gt 0 $result = $employees | Measure-Object -Sum:$testSum -Average:$testAverage -Max:$testMax -Min:$testMin -Prop $property - $result.Count | Should Be 4 + $result.Count | Should -Be 4 if($testSum) { - $result.Sum | Should Be 44 + $result.Sum | Should -Be 44 } else { - $result.Sum | Should BeNullOrEmpty + $result.Sum | Should -BeNullOrEmpty } if($testAverage) { - $result.Average | Should Be 11 + $result.Average | Should -Be 11 } else { - $result.Average | Should BeNullOrEmpty + $result.Average | Should -BeNullOrEmpty } if($testMax) { - $result.Maximum | Should Be 15 + $result.Maximum | Should -Be 15 } else { - $result.Maximum | Should BeNullOrEmpty + $result.Maximum | Should -BeNullOrEmpty } if($testMin) { - $result.Minimum | Should Be 5 + $result.Minimum | Should -Be 5 } else { - $result.Minimum | Should BeNullOrEmpty + $result.Minimum | Should -BeNullOrEmpty } } } @@ -271,40 +271,40 @@ Describe "Measure-Object DRT basic functionality" -Tags "CI" { { if($testIgnoreWS) { - $result.Characters | Should Be 25 + $result.Characters | Should -Be 25 } else { - $result.Characters | Should Be 29 + $result.Characters | Should -Be 29 } } else { - $result.Characters | Should BeNullOrEmpty + $result.Characters | Should -BeNullOrEmpty } if($testWord) { - $result.Words | Should Be 6 + $result.Words | Should -Be 6 } else { - $result.Words | Should BeNullOrEmpty + $result.Words | Should -BeNullOrEmpty } if($testLine) { - $result.Lines | Should Be 4 + $result.Lines | Should -Be 4 } else { - $result.Lines | Should BeNullOrEmpty + $result.Lines | Should -BeNullOrEmpty } } } It "Measure-Object with multiple lines should work"{ $result = "123`n4" | Measure-Object -Line - $result.Lines | Should Be 2 + $result.Lines | Should -Be 2 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 index 42895219e5e..6075ff4fa86 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 @@ -7,7 +7,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMdd}" -f $date $actualFormat = Get-Date -Date $date -Format FileDate - $actualFormat | Should be $expectedFormat + $actualFormat | Should -be $expectedFormat } It "Verifies that FileDateUniversal format works" { @@ -15,7 +15,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddZ}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateUniversal - $actualFormat | Should be $expectedFormat + $actualFormat | Should -be $expectedFormat } It "Verifies that FileDateTime format works" { @@ -23,7 +23,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddTHHmmssffff}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateTime - $actualFormat | Should be $expectedFormat + $actualFormat | Should -be $expectedFormat } It "Verifies that FileDateTimeUniversal format works" { @@ -31,7 +31,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddTHHmmssffffZ}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateTimeUniversal - $actualFormat | Should be $expectedFormat + $actualFormat | Should -be $expectedFormat } } @@ -51,6 +51,6 @@ Describe "GetRandomMiscTests" -Tags "Feature" { $hadError = $true } - $hadError | Should be $false + $hadError | Should -be $false } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index ec2f34ae3a8..7dab11be0da 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -8,42 +8,42 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.CategoryInfo| Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" } } It "New-Alias NamePositional And Value Valid" { New-Alias ABCD -Value "MyCommand" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "MyCommand" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "MyCommand" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "New-Alias NamePositional And ValuePositional Valid" { New-Alias ABCD "MyCommand" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "MyCommand" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "MyCommand" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "New-Alias Description Valid" { New-Alias -Name ABCD -Value "MyCommand" -Description "test description" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "MyCommand" - $result.Description| Should Be "test description" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "MyCommand" + $result.Description| Should -Be "test description" + $result.Options| Should -Be "None" } } Describe "New-Alias" -Tags "CI" { It "Should be able to be called using the name and value parameters without error" { - { New-Alias -Name testAlias -Value 100 } | Should Not Throw + { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw } It "Should have the same output between the alias and the original cmdlet" { @@ -53,12 +53,12 @@ Describe "New-Alias" -Tags "CI" { $cmdletId = $(Get-Command).Id foreach ($IdNumber in $aliasId) { - $aliasId[$IdNumber] | Should Be $cmdletId[$IdNumber] + $aliasId[$IdNumber] | Should -Be $cmdletId[$IdNumber] } } It "Should be able to call the New-Alias cmdlet using the nal alias without error" { - { nal -Name testAlias -Value 100 } | Should Not Throw + { nal -Name testAlias -Value 100 } | Should -Not -Throw } It "Should have the same output between the nal alias and the New-Alias cmdlet" { @@ -71,7 +71,7 @@ Describe "New-Alias" -Tags "CI" { foreach ($IdNumber in $aliasData) { - $aliasData[$IdNumber] | Should Be $cmdletData[$IdNumber] + $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber] } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 index facd177f412..bb5d2538cd3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 @@ -5,20 +5,20 @@ Describe "New-Event" -Tags "CI" { Context "Check return type of New-Event" { It "Should return PSEventArgs as return type of New-Event" { - New-Event -SourceIdentifier a | Should BeOfType System.Management.Automation.PSEventArgs + New-Event -SourceIdentifier a | Should -BeOfType System.Management.Automation.PSEventArgs } } Context "Check New-Event can register an event"{ It "Should return PesterTestMessage as the MessageData" { (New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage") - (Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage" + (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -Be "PesterTestMessage" Remove-Event -sourceidentifier PesterTimer } It "Should return Sender as Windows.timer" { (New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage") - (Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer + (Get-Event -SourceIdentifier PesterTimer).Sender | Should -be Windows.timer Remove-Event -sourceIdentifier PesterTimer } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index ee6411ed866..2508a616e35 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -6,7 +6,7 @@ Describe "New-Object" -Tags "CI" { { New-Object -ComObject "Shell.Application" } | ShouldBeErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } else { # It works on NanoServer and IoT too - (Get-Command "New-Object").Parameters.ContainsKey("ComObject") | Should Be $true + (Get-Command "New-Object").Parameters.ContainsKey("ComObject") | Should -Be $true } } @@ -14,15 +14,15 @@ Describe "New-Object" -Tags "CI" { $o = New-Object psobject $val = $o.GetType() - $val.IsPublic | Should Not BeNullOrEmpty - $val.Name | Should Not BeNullOrEmpty - $val.IsSerializable | Should Not BeNullOrEmpty - $val.BaseType | Should Not BeNullOrEmpty + $val.IsPublic | Should -Not -BeNullOrEmpty + $val.Name | Should -Not -BeNullOrEmpty + $val.IsSerializable | Should -Not -BeNullOrEmpty + $val.BaseType | Should -Not -BeNullOrEmpty - $val.IsPublic | Should Be $true - $val.IsSerializable | Should Be $false - $val.Name | Should Be 'PSCustomObject' - $val.BaseType | Should Be 'System.Object' + $val.IsPublic | Should -Be $true + $val.IsSerializable | Should -Be $false + $val.Name | Should -Be 'PSCustomObject' + $val.BaseType | Should -Be 'System.Object' } It "should create an object with using Property switch" { @@ -32,43 +32,43 @@ Describe "New-Object" -Tags "CI" { } $o = New-Object psobject -Property $hash - $o.FirstVal | Should Be 'test1' - $o.SecondVal | Should Be 'test2' + $o.FirstVal | Should -Be 'test1' + $o.SecondVal | Should -Be 'test2' } It "should create a .Net object with using ArgumentList switch" { $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" - $o.GetType() | Should Be ([System.Version]) + $o.GetType() | Should -Be ([System.Version]) - $o | Should Be "1.2.3.4" + $o | Should -Be "1.2.3.4" } } Describe "New-Object DRT basic functionality" -Tags "CI" { It "New-Object with int array should work"{ $result = New-Object -TypeName int[] -Arg 10 - $result.Count | Should Be 10 + $result.Count | Should -Be 10 } It "New-Object with char should work"{ $result = New-Object -TypeName char - $result.Count | Should Be 1 + $result.Count | Should -Be 1 $defaultChar = [char]0 - ([char]$result) | Should Be $defaultChar + ([char]$result) | Should -Be $defaultChar } It "New-Object with default Coordinates should work"{ $result = New-Object -TypeName System.Management.Automation.Host.Coordinates - $result.Count | Should Be 1 - $result.X | Should Be 0 - $result.Y | Should Be 0 + $result.Count | Should -Be 1 + $result.X | Should -Be 0 + $result.Y | Should -Be 0 } It "New-Object with specified Coordinates should work"{ $result = New-Object -TypeName System.Management.Automation.Host.Coordinates -ArgumentList 1,2 - $result.Count | Should Be 1 - $result.X | Should Be 1 - $result.Y | Should Be 2 + $result.Count | Should -Be 1 + $result.X | Should -Be 1 + $result.Y | Should -Be 2 } It "New-Object with Employ should work"{ @@ -77,10 +77,10 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } $result = New-Object -TypeName Employee -ArgumentList "Mary", "Soe", 11 - $result.Count | Should Be 1 - $result.FirstName | Should Be "Mary" - $result.LastName | Should Be "Soe" - $result.YearsInMS | Should Be 11 + $result.Count | Should -Be 1 + $result.FirstName | Should -Be "Mary" + $result.LastName | Should -Be "Soe" + $result.YearsInMS | Should -Be 11 } It "New-Object with invalid type should throw Exception"{ @@ -91,8 +91,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.CategoryInfo| Should -Match "PSArgumentException" + $_.FullyQualifiedErrorId | Should -be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -104,8 +104,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "MethodException" - $_.FullyQualifiedErrorId | Should be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.CategoryInfo| Should -Match "MethodException" + $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -118,8 +118,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "MethodInvocationException" - $_.FullyQualifiedErrorId | Should be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.CategoryInfo| Should -Match "MethodInvocationException" + $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -135,8 +135,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "MethodException" - $_.FullyQualifiedErrorId | Should be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.CategoryInfo| Should -Match "MethodException" + $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -153,7 +153,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -166,14 +166,14 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.CategoryInfo| Should -Match "PSArgumentException" + $_.FullyQualifiedErrorId | Should -be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } It "New-Object with TypeName and Property parameter should work"{ $result = New-Object -TypeName PSObject -property @{foo=123} - $result.foo | Should Be 123 + $result.foo | Should -Be 123 } } @@ -199,8 +199,8 @@ try It "Should be able to create with property of Type " -TestCases $testCases { param($Name, $Property, $Type) $comObject = New-Object -ComObject $name - $comObject.$Property | should not be $null - $comObject.$Property | should beoftype $Type + $comObject.$Property | should -not -be $null + $comObject.$Property | should -beoftype $Type } It "Should fail with correct error when creating a COM object that dose not exist" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-TimeSpan.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-TimeSpan.Tests.ps1 index 9cab87f089b..e4e193424dc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-TimeSpan.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-TimeSpan.Tests.ps1 @@ -4,11 +4,11 @@ Describe "New-TimeSpan DRT Unit Tests" -Tags "CI" { It "Should works proper with new-timespan"{ $results = New-TimeSpan -Days 10 -Hours 10 -Minutes 10 -Seconds 10 - $results | Should BeOfType "System.Timespan" - $results.Days | Should Be 10 - $results.Hours | Should Be 10 - $results.Minutes | Should Be 10 - $results.Seconds | Should Be 10 + $results | Should -BeOfType "System.Timespan" + $results.Days | Should -Be 10 + $results.Hours | Should -Be 10 + $results.Minutes | Should -Be 10 + $results.Seconds | Should -Be 10 } } @@ -16,7 +16,7 @@ Describe "New-TimeSpan" -Tags "CI" { It "Should be able to create a new timespan object" { New-Variable -Name testObject -Value $(New-TimeSpan) - $testObject | Should BeOfType "System.Timespan" + $testObject | Should -BeOfType "System.Timespan" } Context "Core Functionality Tests" { @@ -38,11 +38,11 @@ Describe "New-TimeSpan" -Tags "CI" { $TEN_MILLION = 10000000 It "Should have expected values for time properties set during creation" { - $testObject.Days | Should Be $expectedOutput["Days"] - $testObject.Hours | Should Be $expectedOutput["Hours"] - $testObject.Minutes | Should Be $expectedOutput["Minutes"] - $testObject.Seconds | Should Be $expectedOutput["Seconds"] - $testObject.Ticks | Should Be $expectedOutput["Ticks"] + $testObject.Days | Should -Be $expectedOutput["Days"] + $testObject.Hours | Should -Be $expectedOutput["Hours"] + $testObject.Minutes | Should -Be $expectedOutput["Minutes"] + $testObject.Seconds | Should -Be $expectedOutput["Seconds"] + $testObject.Ticks | Should -Be $expectedOutput["Ticks"] } } @@ -55,6 +55,6 @@ Describe "New-TimeSpan" -Tags "CI" { $difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds) # The difference between commands should be minimal - $difference | Should BeLessThan 100 + $difference | Should -BeLessThan 100 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index c5bf5edd2ce..73fc0011002 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -5,19 +5,19 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable variable with description should works"{ New-Variable foo bar -description "my description" $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "my description" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "my description" } It "New-Variable variable with option should works"{ New-Variable foo bar -option Constant $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "Constant" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "Constant" + $var1.Description|Should -Be "" } It "New-Variable variable twice should throw Exception"{ @@ -28,15 +28,15 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.CategoryInfo| Should Match "SessionStateException" - $_.FullyQualifiedErrorId | Should Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $_.CategoryInfo| Should -Match "SessionStateException" + $_.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "New-Variable ReadOnly variable twice should throw Exception"{ @@ -47,60 +47,60 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.CategoryInfo| Should Match "SessionStateException" - $_.FullyQualifiedErrorId | Should Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $_.CategoryInfo| Should -Match "SessionStateException" + $_.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } } Describe "New-Variable" -Tags "CI" { It "Should create a new variable with no parameters" { - { New-Variable var1 } | Should Not Throw + { New-Variable var1 } | Should -Not -Throw } It "Should be able to set variable name using the Name parameter" { - { New-Variable -Name var1 } | Should Not Throw + { New-Variable -Name var1 } | Should -Not -Throw } It "Should be able to assign a value to a variable using the value switch" { New-Variable var1 -Value 4 - $var1 | Should Be 4 + $var1 | Should -Be 4 } It "Should be able to assign a value to a new variable without using the value switch" { New-Variable var1 "test" - $var1 | Should Be "test" + $var1 | Should -Be "test" } It "Should assign a description to a new variable using the description switch" { New-Variable var1 100 -Description "Test Description" - (Get-Variable var1).Description | Should Be "Test Description" + (Get-Variable var1).Description | Should -Be "Test Description" } It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" { New-Variable var1 New-Variable var1 -ErrorAction SilentlyContinue -ErrorVariable newWhenExists - $newWhenExists.FullyQualifiedErrorId | Should Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $newWhenExists.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } It "Should change the value of an already existing variable using the Force switch" { New-Variable var1 -Value 1 - $var1 | Should Be 1 + $var1 | Should -Be 1 New-Variable var1 -Value 2 -Force - $var1 | Should Be 2 - $var1 | Should Not Be 1 + $var1 | Should -Be 2 + $var1 | Should -Not -Be 1 } @@ -109,33 +109,33 @@ Describe "New-Variable" -Tags "CI" { $in | New-Variable -Name var1 - $var1 | Should Be $in + $var1 | Should -Be $in } It "Should be able to pipe object properties to output using the PassThru switch" { $in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru - $in.Description | Should Be "test description" + $in.Description | Should -Be "test description" } It "Should be able to set the value using the value switch" { New-Variable -Name var1 -Value 2 - $var1 | Should Be 2 + $var1 | Should -Be 2 } Context "Option tests" { It "Should be able to use the options switch without error" { - { New-Variable -Name var1 -Value 2 -Option Unspecified } | Should Not Throw + { New-Variable -Name var1 -Value 2 -Option Unspecified } | Should -Not -Throw } It "Should default to none as the value for options" { - (new-variable -name var2 -value 4 -passthru).Options | should be "None" + (new-variable -name var2 -value 4 -passthru).Options | should -be "None" } It "Should be able to set ReadOnly option" { - { New-Variable -Name var1 -Value 2 -Option ReadOnly } | Should Not Throw + { New-Variable -Name var1 -Value 2 -Option ReadOnly } | Should -Not -Throw } It "Should not be able to change variable created using the ReadOnly option when the Force switch is not used" { @@ -143,11 +143,11 @@ Describe "New-Variable" -Tags "CI" { Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue - $var1 | Should Not Be 2 + $var1 | Should -Not -Be 2 } It "Should be able to set a new variable to constant" { - { New-Variable -Name var1 -Option Constant } | Should Not Throw + { New-Variable -Name var1 -Option Constant } | Should -Not -Throw } It "Should not be able to change an existing variable to constant" { @@ -155,7 +155,7 @@ Describe "New-Variable" -Tags "CI" { Set-Variable -Name var1 -Option Constant -ErrorAction SilentlyContinue - (Get-Variable var1).Options | should be "None" + (Get-Variable var1).Options | should -be "None" } It "Should not be able to delete a constant variable" { @@ -163,7 +163,7 @@ Describe "New-Variable" -Tags "CI" { Remove-Variable -Name var1 -ErrorAction SilentlyContinue - $var1 | Should Be 2 + $var1 | Should -Be 2 } It "Should not be able to change a constant variable" { @@ -171,35 +171,35 @@ Describe "New-Variable" -Tags "CI" { Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue - $var1 | Should Not Be 2 + $var1 | Should -Not -Be 2 } It "Should be able to create a variable as private without error" { - { New-Variable -Name var1 -Option Private } | Should Not Throw + { New-Variable -Name var1 -Option Private } | Should -Not -Throw } It "Should be able to see the value of a private variable when within scope" { New-Variable -Name var1 -Value 100 -Option Private - $var1 | Should Be 100 + $var1 | Should -Be 100 } It "Should not be able to see the value of a private variable when out of scope" { - {New-Variable -Name var1 -Value 1 -Option Private}| Should Not Throw + {New-Variable -Name var1 -Value 1 -Option Private}| Should -Not -Throw - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should be able to use the AllScope switch without error" { - { New-Variable -Name var1 -Option AllScope } | Should Not Throw + { New-Variable -Name var1 -Option AllScope } | Should -Not -Throw } It "Should be able to see variable created using the AllScope switch in a child scope" { New-Variable -Name var1 -Value 1 -Option AllScope &{ $var1 = 2 } - $var1 | Should Be 2 + $var1 | Should -Be 2 } } @@ -228,16 +228,16 @@ Describe "New-Variable" -Tags "CI" { } It "Should be able to create a global scope variable using the global switch" { new-variable -Scope global -name globalvar1 -value 1 - get-variable -Scope global -name globalVar1 -ValueOnly | Should be 1 + get-variable -Scope global -name globalVar1 -ValueOnly | Should -be 1 } It "Should be able to create a local scope variable using the local switch" { - Get-Variable -scope local -name localvar -ValueOnly -ea silentlycontinue | should BeNullOrEmpty + Get-Variable -scope local -name localvar -ValueOnly -ea silentlycontinue | should -BeNullOrEmpty New-Variable -Scope local -Name localVar -value 10 - get-variable -scope local -name localvar -ValueOnly | Should be 10 + get-variable -scope local -name localvar -ValueOnly | Should -be 10 } It "Should be able to create a script scope variable using the script switch" { new-variable -scope script -name scriptvar -value 100 - get-variable -scope script -name scriptvar -ValueOnly | should be 100 + get-variable -scope script -name scriptvar -ValueOnly | should -be 100 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 index d4925947de9..2ce6390d901 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 @@ -4,18 +4,18 @@ Describe "New-Guid" -Tags "CI" { It "returns a new guid" { $guid = New-Guid - $guid | Should BeOfType System.Guid + $guid | Should -BeOfType System.Guid } It "should not be all zeros" { $guid = New-Guid - $guid.ToString() | Should Not Be "00000000-0000-0000-0000-000000000000" + $guid.ToString() | Should -Not -Be "00000000-0000-0000-0000-000000000000" } It "should return different guids with each call" { $guid1 = New-Guid $guid2 = New-Guid - $guid1.ToString() | Should Not Be $guid2.ToString() + $guid1.ToString() | Should -Not -Be $guid2.ToString() } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 index aa73e1ccfea..7e3bc97c36d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 @@ -19,9 +19,9 @@ Describe "New-TemporaryFile" -Tags "CI" { It "creates a new temporary file" { $tempFile = New-TemporaryFile - $tempFile | Should Exist - $tempFile | Should BeOfType System.IO.FileInfo - $tempFile | Should BeLikeExactly "$([System.IO.Path]::GetTempPath())*" + $tempFile | Should -Exist + $tempFile | Should -BeOfType System.IO.FileInfo + $tempFile | Should -BeLikeExactly "$([System.IO.Path]::GetTempPath())*" if (Test-Path $tempFile) { Remove-Item $tempFile -ErrorAction SilentlyContinue -Force @@ -29,10 +29,10 @@ Describe "New-TemporaryFile" -Tags "CI" { } It "with WhatIf does not create a file" { - New-TemporaryFile -WhatIf | Should Be $null + New-TemporaryFile -WhatIf | Should -Be $null } It "has an OutputType of System.IO.FileInfo" { - (Get-Command New-TemporaryFile).OutputType | Should Be "System.IO.FileInfo" + (Get-Command New-TemporaryFile).OutputType | Should -Be "System.IO.FileInfo" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index 6d6b74a061e..9b8f2f7b060 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -3,18 +3,18 @@ Describe "Out-File DRT Unit Tests" -Tags "CI" { It "Should be able to write the contents into a file with -pspath" { $tempFile = Join-Path -Path $TestDrive -ChildPath "ExposeBug928965" - { 1 | Out-File -PSPath $tempFile } | Should Not Throw + { 1 | Out-File -PSPath $tempFile } | Should -Not -Throw $fileContents = Get-Content $tempFile - $fileContents | Should be 1 + $fileContents | Should -be 1 Remove-Item $tempFile -Force } It "Should be able to write the contents into a file with -pspath" { $tempFile = Join-Path -Path $TestDrive -ChildPath "outfileAppendTest.txt" - { 'This is first line.' | out-file $tempFile } | Should Not Throw - { 'This is second line.' | out-file -append $tempFile } | Should Not Throw - $tempFile |Should FileContentMatch "first" - $tempFile |Should FileContentMatch "second" + { 'This is first line.' | out-file $tempFile } | Should -Not -Throw + { 'This is second line.' | out-file -append $tempFile } | Should -Not -Throw + $tempFile |Should -FileContentMatch "first" + $tempFile |Should -FileContentMatch "second" Remove-Item $tempFile -Force } } @@ -31,64 +31,64 @@ Describe "Out-File" -Tags "CI" { } It "Should be able to be called without error" { - { Out-File -FilePath $testfile } | Should Not Throw + { Out-File -FilePath $testfile } | Should -Not -Throw } It "Should be able to accept string input via piping" { - { $expectedContent | Out-File -FilePath $testfile } | Should Not Throw + { $expectedContent | Out-File -FilePath $testfile } | Should -Not -Throw $actual = Get-Content $testfile - $actual | Should Be $expectedContent + $actual | Should -Be $expectedContent } It "Should be able to accept string input via the InputObject switch" { - { Out-File -FilePath $testfile -InputObject $expectedContent } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $expectedContent } | Should -Not -Throw $actual = Get-Content $testfile - $actual | Should Be $expectedContent + $actual | Should -Be $expectedContent } It "Should be able to accept object input" { - { $inObject | Out-File -FilePath $testfile } | Should Not Throw + { $inObject | Out-File -FilePath $testfile } | Should -Not -Throw - { Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inObject } | Should -Not -Throw } It "Should not overwrite when the noclobber switch is used" { Out-File -FilePath $testfile -InputObject $inObject - { Out-File -FilePath $testfile -InputObject $inObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists." - { Out-File -FilePath $testfile -InputObject $inObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists." + { Out-File -FilePath $testfile -InputObject $inObject -NoClobber -ErrorAction SilentlyContinue } | Should -Throw "already exists." + { Out-File -FilePath $testfile -InputObject $inObject -NoOverWrite -ErrorAction SilentlyContinue } | Should -Throw "already exists." $actual = Get-Content $testfile - $actual[0] | Should Be "" - $actual[1] | Should Match "text" - $actual[2] | Should Match "----" - $actual[3] | Should Match "some test text" + $actual[0] | Should -Be "" + $actual[1] | Should -Match "text" + $actual[2] | Should -Match "----" + $actual[3] | Should -Match "some test text" } It "Should Append a new line when the append switch is used" { - { Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw - { Out-File -FilePath $testfile -InputObject $inObject -Append } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inObject } | Should -Not -Throw + { Out-File -FilePath $testfile -InputObject $inObject -Append } | Should -Not -Throw $actual = Get-Content $testfile - $actual[0] | Should Be "" - $actual[1] | Should Match "text" - $actual[2] | Should Match "----" - $actual[3] | Should Match "some test text" - $actual[4] | Should Be "" - $actual[5] | Should Be "" - $actual[6] | Should Be "" - $actual[7] | Should Match "text" - $actual[8] | Should Match "----" - $actual[9] | Should Match "some test text" - $actual[10] | Should Be "" - $actual[11] | Should Be "" + $actual[0] | Should -Be "" + $actual[1] | Should -Match "text" + $actual[2] | Should -Match "----" + $actual[3] | Should -Match "some test text" + $actual[4] | Should -Be "" + $actual[5] | Should -Be "" + $actual[6] | Should -Be "" + $actual[7] | Should -Match "text" + $actual[8] | Should -Match "----" + $actual[9] | Should -Match "some test text" + $actual[10] | Should -Be "" + $actual[11] | Should -Be "" } It "Should limit each line to the specified number of characters when the width switch is used on objects" { @@ -97,41 +97,41 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile - $actual[0] | Should Be "" - $actual[1] | Should Be "text" - $actual[2] | Should Be "----" - $actual[3] | Should Be "some te..." + $actual[0] | Should -Be "" + $actual[1] | Should -Be "text" + $actual[2] | Should -Be "----" + $actual[3] | Should -Be "some te..." } It "Should allow the cmdlet to overwrite an existing read-only file" { # create a read-only text file - { Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inObject } | Should -Not -Throw Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true # write information to the RO file - { Out-File -FilePath $testfile -InputObject $inObject -Append -Force } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inObject -Append -Force } | Should -Not -Throw $actual = Get-Content $testfile - $actual[0] | Should Be "" - $actual[1] | Should Match "text" - $actual[2] | Should Match "----" - $actual[3] | Should Match "some test text" - $actual[4] | Should Be "" - $actual[5] | Should Be "" - $actual[6] | Should Be "" - $actual[7] | Should Match "text" - $actual[8] | Should Match "----" - $actual[9] | Should Match "some test text" - $actual[10] | Should Be "" - $actual[11] | Should Be "" + $actual[0] | Should -Be "" + $actual[1] | Should -Match "text" + $actual[2] | Should -Match "----" + $actual[3] | Should -Match "some test text" + $actual[4] | Should -Be "" + $actual[5] | Should -Be "" + $actual[6] | Should -Be "" + $actual[7] | Should -Match "text" + $actual[8] | Should -Match "----" + $actual[9] | Should -Match "some test text" + $actual[10] | Should -Be "" + $actual[11] | Should -Be "" # reset to not read only so it can be deleted Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false } It "Should be able to use the 'Path' alias for the 'FilePath' parameter" { - { Out-File -Path $testfile } | Should Not Throw + { Out-File -Path $testfile } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 index e29723bd520..e4f7f03f706 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 @@ -4,10 +4,10 @@ Describe "Out-String DRT Unit Tests" -Tags "CI" { It "check display of properties with names containing wildcard characters" { $results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string - $results.Length | Should BeGreaterThan 1 - $results | Should BeOfType "System.String" - $results.Contains("myvalue") | Should Be $true - $results.Contains("name with square brackets: [0]") | Should Be $true + $results.Length | Should -BeGreaterThan 1 + $results | Should -BeOfType "System.String" + $results.Contains("myvalue") | Should -Be $true + $results.Contains("name with square brackets: [0]") | Should -Be $true } } @@ -21,15 +21,15 @@ Describe "Out-String" -Tags "CI" { It "Should accumulate the strings and returns them as a single string" { $testArray = "a", " b" - $testArray | Out-String | Should Be "a$nl b$nl" - ,$($testArray | Out-String) | Should BeOfType "System.String" + $testArray | Out-String | Should -Be "a$nl b$nl" + ,$($testArray | Out-String) | Should -BeOfType "System.String" } It "Should be able to return an array of strings using the stream switch" { $testInput = "a", "b" - ,$($testInput | Out-String) | Should BeOfType "System.String" - ,$($testInput | Out-String -Stream) | Should BeOfType "System.Array" + ,$($testInput | Out-String) | Should -BeOfType "System.String" + ,$($testInput | Out-String -Stream) | Should -BeOfType "System.Array" } It "Should send all objects through a pipeline when not using the stream switch" { @@ -37,7 +37,7 @@ Describe "Out-String" -Tags "CI" { $streamoutputlength = $($testInput | Out-String -Stream).Length $nonstreamoutputlength = $($testInput | Out-String).Length - $nonstreamoutputlength| Should BeGreaterThan $streamoutputlength + $nonstreamoutputlength| Should -BeGreaterThan $streamoutputlength } It "Should send a single object through a pipeline when the stream switch is used" { @@ -45,17 +45,17 @@ Describe "Out-String" -Tags "CI" { $streamoutputlength = $($testInput | Out-String -Stream).Length $nonstreamoutputlength = $($testInput | Out-String).Length - $streamoutputlength | Should BeLessThan $nonstreamoutputlength + $streamoutputlength | Should -BeLessThan $nonstreamoutputlength } It "Should not print a newline when the nonewline switch is used" { $testArray = "a", "b" - $testArray | Out-String -NoNewLine | Should Be "ab" + $testArray | Out-String -NoNewLine | Should -Be "ab" } It "Should preserve embedded newline when the nonewline switch is used" { $testArray = "a$nl", "b" - $testArray | Out-String -NoNewLine | Should Be "a${nl}b" + $testArray | Out-String -NoNewLine | Should -Be "a${nl}b" } It "Should throw error when NoNewLine and Stream are used together" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index a2d1fe12844..bcb1769ddf9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -17,13 +17,13 @@ Describe "Json Tests" -Tags "Feature" { param ($result, [switch]$hasEmbeddedSampleObject ) Write-Verbose "validating deserialized SampleObject" -Verbose - $result.SampleInt | Should Be 98765 - $result.SampleString | Should Match "stringVal" - $result.SampleArray.Count | Should Be 2 - $result.SampleTrue | Should Be $true - $result.SampleFalse | Should Be $false - $result.SampleNull | Should Be $null - $result.SampleFloat | Should Be 9.8765E+43 + $result.SampleInt | Should -Be 98765 + $result.SampleString | Should -Match "stringVal" + $result.SampleArray.Count | Should -Be 2 + $result.SampleTrue | Should -Be $true + $result.SampleFalse | Should -Be $false + $result.SampleNull | Should -Be $null + $result.SampleFloat | Should -Be 9.8765E+43 if ($hasEmbeddedSampleObject) { @@ -50,7 +50,7 @@ Describe "Json Tests" -Tags "Feature" { } catch { - $_.FullyQualifiedErrorId | should be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | should -be $expectedFullyQualifiedErrorId } } @@ -63,7 +63,7 @@ Describe "Json Tests" -Tags "Feature" { $valueFromNotCompressedResult = ConvertFrom-Json -InputObject $notcompressed $valueFromCompressedResult = ConvertFrom-Json -InputObject $compressed - $valueFromNotCompressedResult.FirstName | Should Match $valueFromCompressedResult.FirstName + $valueFromNotCompressedResult.FirstName | Should -Match $valueFromCompressedResult.FirstName } It "Convertto-Json should handle Enum based on Int64" { @@ -85,9 +85,9 @@ Describe "Json Tests" -Tags "Feature" { }" } $op = [JsonEnumTest]::New() | convertto-json | convertfrom-json - $op.TestEnum1 | Should Be "One" - $op.TestEnum2 | Should Be "Two" - $op.TestEnum3 | Should Be 1 + $op.TestEnum1 | Should -Be "One" + $op.TestEnum2 | Should -Be "Two" + $op.TestEnum3 | Should -Be 1 } It "Test followup for Windows 8 bug 121627" { @@ -95,9 +95,9 @@ Describe "Json Tests" -Tags "Feature" { $JsonString = Get-Command Get-help |Select-Object Name, Noun, Verb| ConvertTo-Json $actual = ConvertFrom-Json $JsonString - $actual.Name | Should Be "Get-Help" - $actual.Noun | Should Be "Help" - $actual.Verb | Should Be "Get" + $actual.Name | Should -Be "Get-Help" + $actual.Noun | Should -Be "Help" + $actual.Verb | Should -Be "Get" } } @@ -106,7 +106,7 @@ Describe "Json Tests" -Tags "Feature" { It "Convert dictionary to PSObject" { $response = ConvertFrom-Json '{"d":{"__type":"SimpleJsonObject","Name":{"First":"Joel","Last":"Wood"},"Greeting":"Hello"}}' - $response.d.Name.First | Should Match "Joel" + $response.d.Name.First | Should -Match "Joel" } It "Convert to Json using PSObject" -pending:($IsCoreCLR) { @@ -117,11 +117,11 @@ Describe "Json Tests" -Tags "Feature" { $response2 = ConvertTo-Json -InputObject $response -ErrorAction Inquire $response2 = ConvertTo-Json -InputObject $response -ErrorAction SilentlyContinue $response2 = ConvertTo-Json -InputObject $response -Depth 2 -Compress - $response2 | Should Be '{"d":{"Name":{"First":"Joel","Last":"Wood"},"Greeting":"Hello"}}' + $response2 | Should -Be '{"d":{"Name":{"First":"Joel","Last":"Wood"},"Greeting":"Hello"}}' $response2 = ConvertTo-Json -InputObject $response -Depth 1 -Compress $nameString = [System.Management.Automation.LanguagePrimitives]::ConvertTo($response.d.Name, [string]) - $response2 | Should Be "{`"d`":{`"Name`":`"$nameString`",`"Greeting`":`"Hello`"}}" + $response2 | Should -Be "{`"d`":{`"Name`":`"$nameString`",`"Greeting`":`"Hello`"}}" $result1 = @" { @@ -135,7 +135,7 @@ Describe "Json Tests" -Tags "Feature" { } "@ $response2 = ConvertTo-Json -InputObject $response -Depth 2 - $response2 | Should Match $result1 + $response2 | Should -Match $result1 $result2 = @" { @@ -146,14 +146,14 @@ Describe "Json Tests" -Tags "Feature" { } "@ $response2 = ConvertTo-Json -InputObject $response -Depth 1 - $response2 | Should Match $result2 + $response2 | Should -Match $result2 $arraylist = new-Object System.Collections.ArrayList [void]$arraylist.Add("one") [void]$arraylist.Add("two") [void]$arraylist.Add("three") $response2 = ConvertTo-Json -InputObject $arraylist -Compress - $response2 | Should Be '["one","two","three"]' + $response2 | Should -Be '["one","two","three"]' $result3 = @" [ @@ -163,10 +163,10 @@ Describe "Json Tests" -Tags "Feature" { ] "@ $response2 = ConvertTo-Json -InputObject $arraylist - $response2 | Should Be $result3 + $response2 | Should -Be $result3 $response2 = $arraylist | ConvertTo-Json - $response2 | Should Be $result3 + $response2 | Should -Be $result3 } It "Convert to Json using hashtable" -pending:($IsCoreCLR) { @@ -175,10 +175,10 @@ Describe "Json Tests" -Tags "Feature" { $dHash = @{Name=$nameHash; Greeting="Hello"} $rootHash = @{d=$dHash} $response3 = ConvertTo-Json -InputObject $rootHash -Depth 2 -Compress - $response3 | Should Be '{"d":{"Greeting":"Hello","Name":{"Last":"Wood","First":"Joe1"}}}' + $response3 | Should -Be '{"d":{"Greeting":"Hello","Name":{"Last":"Wood","First":"Joe1"}}}' $response3 = ConvertTo-Json -InputObject $rootHash -Depth 1 -Compress - $response3 | Should Be '{"d":{"Greeting":"Hello","Name":"System.Collections.Hashtable"}}' + $response3 | Should -Be '{"d":{"Greeting":"Hello","Name":"System.Collections.Hashtable"}}' $result4 = @" { @@ -192,7 +192,7 @@ Describe "Json Tests" -Tags "Feature" { } "@ $response3 = ConvertTo-Json -InputObject $rootHash -Depth 2 - $response3 | Should Be $result4 + $response3 | Should -Be $result4 $result5 = @" { @@ -203,13 +203,13 @@ Describe "Json Tests" -Tags "Feature" { } "@ $response3 = ConvertTo-Json -InputObject $rootHash -Depth 1 - $response3 | Should Be $result5 + $response3 | Should -Be $result5 } It "Convert from Json allows an empty string" { $emptyStringResult = ConvertFrom-Json "" - $emptyStringResult | Should Be $null + $emptyStringResult | Should -Be $null } It "Convert enumerated values to Json" { @@ -221,10 +221,10 @@ Describe "Json Tests" -Tags "Feature" { } $response4 = ConvertTo-Json -InputObject $sampleObject -Compress - $response4 | Should Be '{"SampleSimpleEnum":4,"SampleBitwiseEnum":11}' + $response4 | Should -Be '{"SampleSimpleEnum":4,"SampleBitwiseEnum":11}' $response4 = ConvertTo-Json -InputObject $sampleObject -Compress -EnumsAsStrings - $response4 | Should Be '{"SampleSimpleEnum":"Ignore","SampleBitwiseEnum":"Alias, Function, Cmdlet"}' + $response4 | Should -Be '{"SampleSimpleEnum":"Ignore","SampleBitwiseEnum":"Alias, Function, Cmdlet"}' } @@ -251,32 +251,32 @@ Describe "Json Tests" -Tags "Feature" { $json = ConvertFrom-Json $jstr # Check the basic properties - $json.Major | Should Be 2 - $json.Minor | Should Be 3 - $json.Build | Should Be 4 - $json.Revision | Should Be 14 - $json.Note | Should Match "a version object" + $json.Major | Should -Be 2 + $json.Minor | Should -Be 3 + $json.Build | Should -Be 4 + $json.Revision | Should -Be 14 + $json.Note | Should -Match "a version object" # Check the AliasProperty - $json.Rev | Should Be $json.Revision + $json.Rev | Should -Be $json.Revision # Check the ScriptProperty - $json.IsOld | Should Be $true + $json.IsOld | Should -Be $true } It "ConvertFrom-Json with a key value pair" { $json = "{name:1}" $result = ConvertFrom-Json $json - $result.name | Should Be 1 + $result.name | Should -Be 1 } It "ConvertFrom-Json with a simple array" { $json = "[1,2,3,4,5,6]" $result = ConvertFrom-Json $json - $result.Count | Should Be 6 - ,$result | Should BeOfType "System.Array" + $result.Count | Should -Be 6 + ,$result | Should -BeOfType "System.Array" } It "ConvertFrom-Json with a float value" { @@ -285,10 +285,10 @@ Describe "Json Tests" -Tags "Feature" { $result = ConvertFrom-Json $json $sampleFloat1 = Invoke-Expression 1.2345E67 - $result.SampleFloat1 | Should Be $sampleFloat1 + $result.SampleFloat1 | Should -Be $sampleFloat1 $sampleFloat2 = Invoke-Expression -7.6543E-12 - $result.SampleFloat2 | Should Be $sampleFloat2 + $result.SampleFloat2 | Should -Be $sampleFloat2 } It "ConvertFrom-Json hash table nested in array" { @@ -296,18 +296,18 @@ Describe "Json Tests" -Tags "Feature" { $json = "['one', 'two', {'First':1,'Second':2,'Third':['Five','Six', 'Seven']}, 'four']" $result = ConvertFrom-Json $json - $result.Count | Should Be 4 - $result[0] | Should Be "one" - $result[1] | Should Be "two" - $result[3] | Should Be "four" + $result.Count | Should -Be 4 + $result[0] | Should -Be "one" + $result[1] | Should -Be "two" + $result[3] | Should -Be "four" $hash = $result[2] - $hash.First | Should Be 1 - $hash.Second | Should Be 2 - $hash.Third.Count | Should Be 3 - $hash.Third[0] | Should Be "Five" - $hash.Third[1] | Should Be "Six" - $hash.Third[2] | Should Be "Seven" + $hash.First | Should -Be 1 + $hash.Second | Should -Be 2 + $hash.Third.Count | Should -Be 3 + $hash.Third[0] | Should -Be "Five" + $hash.Third[1] | Should -Be "Six" + $hash.Third[2] | Should -Be "Seven" } It "ConvertFrom-Json array nested in hash table" { @@ -315,16 +315,16 @@ Describe "Json Tests" -Tags "Feature" { $json = '{"First":["one", "two", "three"], "Second":["four", "five"], "Third": {"blah": 4}}' $result = ConvertFrom-Json $json - $result.First.Count | Should Be 3 - $result.First[0] | Should Be "one" - $result.First[1] | Should Be "two" - $result.First[2] | Should Be "three" + $result.First.Count | Should -Be 3 + $result.First[0] | Should -Be "one" + $result.First[1] | Should -Be "two" + $result.First[2] | Should -Be "three" - $result.Second.Count | Should Be 2 - $result.Second[0] | Should Be "four" - $result.Second[1] | Should Be "five" + $result.Second.Count | Should -Be 2 + $result.Second[0] | Should -Be "four" + $result.Second[1] | Should -Be "five" - $result.Third.blah | Should Be "4" + $result.Third.blah | Should -Be "4" } It "ConvertFrom-Json case insensitive test" { @@ -332,7 +332,7 @@ Describe "Json Tests" -Tags "Feature" { $json = '{"sAMPleValUE":12345}' $result = ConvertFrom-Json $json - $result.SampleValue | Should Be 12345 + $result.SampleValue | Should -Be 12345 } It "ConvertFrom-Json sample values" { @@ -357,15 +357,15 @@ Describe "Json Tests" -Tags "Feature" { $json = '{"SampleValue":"\"\\\b\f\n\r\t\u4321\uD7FF"}' $result = ConvertFrom-Json $json - $result.SampleValue[0] | Should Be '"' - $result.SampleValue[1] | Should Be '\' - $result.SampleValue[2] | Should Be 0x8 - $result.SampleValue[3] | Should Be 0xC - $result.SampleValue[4] | Should Be 0xA - $result.SampleValue[5] | Should Be 0xD - $result.SampleValue[6] | Should Be 0x9 - $result.SampleValue[7] | Should Be 0x4321 - $result.SampleValue[8] | Should Be 0xD7FF + $result.SampleValue[0] | Should -Be '"' + $result.SampleValue[1] | Should -Be '\' + $result.SampleValue[2] | Should -Be 0x8 + $result.SampleValue[3] | Should -Be 0xC + $result.SampleValue[4] | Should -Be 0xA + $result.SampleValue[5] | Should -Be 0xD + $result.SampleValue[6] | Should -Be 0x9 + $result.SampleValue[7] | Should -Be 0x4321 + $result.SampleValue[8] | Should -Be 0xD7FF } } } @@ -1032,15 +1032,15 @@ Describe "Validate Json serialization" -Tags "CI" { if ($testCase.FromJson) { - $result.FromJson | Should Be $testCase.FromJson + $result.FromJson | Should -Be $testCase.FromJson } else { # There are two char for which the deserialized object must be compare to the serialized one via "Should Match" # These values are [char]0 and [char]13. - $result.FromJson | Should Match $testCase.FromJson + $result.FromJson | Should -Match $testCase.FromJson } - $result.ToJson | Should Be $testCase.ToJson + $result.ToJson | Should -Be $testCase.ToJson } } @@ -1257,8 +1257,8 @@ Describe "Validate Json serialization" -Tags "CI" { FromJson = $expression | ConvertTo-Json | ConvertFrom-Json } - $result.ToJson | Should Be $testCase.ToJson - $result.FromJson | Should Be $testCase.FromJson + $result.ToJson | Should -Be $testCase.ToJson + $result.FromJson | Should -Be $testCase.FromJson } } @@ -1279,7 +1279,7 @@ Describe "Validate Json serialization" -Tags "CI" { ) # Validate that the two collections are the same size. - $expected.Count | Should Be $serialized.Count + $expected.Count | Should -Be $serialized.Count for ($index = 0; $index -lt $serialized.Count; $index++) { @@ -1290,11 +1290,11 @@ Describe "Validate Json serialization" -Tags "CI" { # Write-Verbose "Validating $property" -Verbose if ($property -eq "Qualifiers") { - $serializedObject.$property.Count | Should Be $expectedObject.$property.Count + $serializedObject.$property.Count | Should -Be $expectedObject.$property.Count } else { - $serializedObject.$property | Should Be $expectedObject.$property + $serializedObject.$property | Should -Be $expectedObject.$property } } } @@ -1362,7 +1362,7 @@ Describe "Validate Json serialization" -Tags "CI" { } '@ $expectedNoWhiteSpace = $expected -replace "\s" - $actual | Should Be $expectedNoWhiteSpace + $actual | Should -Be $expectedNoWhiteSpace } } @@ -1371,7 +1371,7 @@ Describe "Validate Json serialization" -Tags "CI" { It "Should print a pretty Array" { $array = 'one', 'two', 'three' $response = $array | ConvertTo-Json - ($response -split "\r?\n")[1] | Should Be ' "one",' + ($response -split "\r?\n")[1] | Should -Be ' "one",' } It "Should print a pretty dictionary" { @@ -1381,11 +1381,11 @@ Describe "Validate Json serialization" -Tags "CI" { 'three' = 3 } $response2 = $dictionary | ConvertTo-Json - ($response2 -split "\r?\n")[1] | Should Be ' "one": 1,' + ($response2 -split "\r?\n")[1] | Should -Be ' "one": 1,' } It "Should minify Json with Compress switch" { - (@{ a = 1 } | ConvertTo-Json -Compress).Length | Should Be 7 + (@{ a = 1 } | ConvertTo-Json -Compress).Length | Should -Be 7 } } } @@ -1422,7 +1422,7 @@ Describe "Json Bug fixes" -Tags "Feature" { } catch { - $_.FullyQualifiedErrorId | Should Be $testCase.FullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $testCase.FullyQualifiedErrorId } } else @@ -1436,7 +1436,7 @@ Describe "Json Bug fixes" -Tags "Feature" { { $theError = $_ } - $theError | Should Be $null + $theError | Should -Be $null } } } @@ -1480,12 +1480,12 @@ Describe "Json Bug fixes" -Tags "Feature" { # Read the object as an array of PSObjects and deserialize it. $result = Get-Content $filePath | ConvertFrom-Json - $result.Count | Should be 2 + $result.Count | Should -be 2 } It "ConvertFrom-Json deserializes an array of strings (in multiple lines) as a single string." { $result = "[1,","2,","3]" | ConvertFrom-Json - $result.Count | Should be 3 + $result.Count | Should -be 3 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 index 53e2c66b2d5..7a142da3e47 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 @@ -11,7 +11,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" + $_.FullyQualifiedErrorId | Should -be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } } @@ -24,7 +24,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" + $_.FullyQualifiedErrorId | Should -be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } } @@ -39,7 +39,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" + $_.FullyQualifiedErrorId | Should -be "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } } @@ -53,7 +53,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" + $_.FullyQualifiedErrorId | Should -be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } } @@ -62,7 +62,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { $path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass $result = Import-PowerShellDataFile $path -ErrorAction Stop - $result.Hello | Should be "World" + $result.Hello | Should -be "World" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 index 587a9ca2518..0516bea67e5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 @@ -19,18 +19,18 @@ Describe "Read-Host Test" -tag "CI" { } It "Read-Host returns expected string" { $result = $ps.AddCommand("Read-Host").Invoke() - $result | Should Be $th.UI.ReadLineData + $result | Should -Be $th.UI.ReadLineData } It "Read-Host sets the prompt correctly" { $result = $ps.AddScript("Read-Host -prompt myprompt").Invoke() $prompt = $th.ui.streams.prompt[0] - $prompt | should Not BeNullOrEmpty - $prompt.split(":")[-1] | should be myprompt + $prompt | should -Not -BeNullOrEmpty + $prompt.split(":")[-1] | should -be myprompt } It "Read-Host returns a secure string when using -AsSecureString parameter" { $result = $ps.AddScript("Read-Host -AsSecureString").Invoke() | select-object -first 1 - $result | Should BeOfType SecureString - [pscredential]::New("foo",$result).GetNEtworkCredential().Password | should BeExactly TEST + $result | Should -BeOfType SecureString + [pscredential]::New("foo",$result).GetNEtworkCredential().Password | should -BeExactly TEST } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-EngineEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-EngineEvent.Tests.ps1 index 4ec75cfd81f..4a9eac67b33 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-EngineEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-EngineEvent.Tests.ps1 @@ -4,7 +4,7 @@ Describe "Register-EngineEvent" -Tags "CI" { Context "Check return type of Register-ObjectEvent" { It "Should return System.Management.Automation.PSEventJob as return type of Register-EngineEvent" { - Register-EngineEvent -SourceIdentifier PesterTestRegister -Action {echo registerengineevent} | Should BeOfType System.Management.Automation.PSEventJob + Register-EngineEvent -SourceIdentifier PesterTestRegister -Action {echo registerengineevent} | Should -BeOfType System.Management.Automation.PSEventJob Unregister-Event -sourceidentifier PesterTestRegister } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 index ee10db39724..683024fefff 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 @@ -14,19 +14,19 @@ Describe "Register-ObjectEvent" -Tags "CI" { It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event with the registered sourceidentifier" { Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - Get-EventSubscriber -SourceIdentifier PesterTestRegister | Should BeOfType System.Management.Automation.PSEventSubscriber + Get-EventSubscriber -SourceIdentifier PesterTestRegister | Should -BeOfType System.Management.Automation.PSEventSubscriber } } Context "Check Register-ObjectEvent can validly register events"{ It "Should return source identifier of PesterTimer " { Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister" + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -Be "PesterTestRegister" } It "Should return an integer greater than 0 for the SubscriptionId" { Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0 + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should -BeGreaterThan 0 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1 index 5b91a18aceb..5c3b8683a06 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1 @@ -39,7 +39,7 @@ Describe "Remove-Alias" -Tags "CI" { It "Remove-Alias should throw if alias does not exist"{ { - Get-Alias -Name $testAliasName -ErrorAction SilentlyContinue | Should BeNullorEmpty + Get-Alias -Name $testAliasName -ErrorAction SilentlyContinue | Should -BeNullorEmpty Remove-Alias -Name $testAliasName -ErrorAction Stop } | ShouldBeErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.RemoveAliasCommand' } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Event.Tests.ps1 index 9a113970d1f..4300514b6dc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Event.Tests.ps1 @@ -14,7 +14,7 @@ Describe "Remove-Event" -Tags "CI" { It "Should remove an event given a sourceidentifier" { { Remove-Event -sourceidentifier PesterTimer } - { Get-Event -ErrorAction SilentlyContinue | Should Not FileMatchContent PesterTimer } + { Get-Event -ErrorAction SilentlyContinue | Should -Not FileMatchContent PesterTimer } } It "Should remove an event given an event identifier" { @@ -22,19 +22,19 @@ Describe "Remove-Event" -Tags "CI" { { $events = $events.EventIdentifier } { Remove-Event -EventIdentifier $events } { $events = Get-Event -ErrorAction SilentlyContinue} - { $events.SourceIdentifier | Should Not FileMatchContent "PesterTimer" } + { $events.SourceIdentifier | Should -Not FileMatchContent "PesterTimer" } } It "Should be able to remove an event given a pipe from Get-Event" { { Get-Event -sourceidentifier PesterTimer | Remove-Event } - { Get-Event -ErrorAction SilentlyContinue | Should Not FileMatchContent "PesterTimer" } + { Get-Event -ErrorAction SilentlyContinue | Should -Not FileMatchContent "PesterTimer" } } It "Should NOT remove an event given the whatif flag" { { Remove-Event -sourceidentifier PesterTimer -whatif } { $events = Get-Event } - { $events.SourceIdentifier | Should FileContentMatch "PesterTimer" } + { $events.SourceIdentifier | Should -FileContentMatch "PesterTimer" } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-PSBreakpoint.Tests.ps1 index cd43e2c54a2..96386ab485c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-PSBreakpoint.Tests.ps1 @@ -26,37 +26,37 @@ Get-Date $BreakID = $(Get-PSBreakpoint).Id[0] Remove-PSBreakpoint -Id $BreakID - $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + $(Get-PSBreakpoint).Id.length | Should -Be ($NumberOfBreakpoints -1) } It "Should be able to remove a breakpoint by variable" { $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length Remove-PSBreakpoint -Breakpoint $variable - $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + $(Get-PSBreakpoint).Id.length | Should -Be ($NumberOfBreakpoints -1) } It "Should be able to remove a breakpoint by command" { $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length Remove-PSBreakpoint -Breakpoint $command - $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + $(Get-PSBreakpoint).Id.length | Should -Be ($NumberOfBreakpoints -1) } It "Should be able to pipe breakpoint objects to Remove-PSBreakpoint" { $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length $variable | Remove-PSBreakpoint - $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + $(Get-PSBreakpoint).Id.length | Should -Be ($NumberOfBreakpoints -1) } } It "Should Remove all breakpoints" { - $(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty + $(Get-PSBreakpoint).Id.Length | Should -Not -BeNullOrEmpty Get-PSBreakpoint | Remove-PSBreakpoint - $(Get-PSBreakpoint).Id.Length | Should Be 0 + $(Get-PSBreakpoint).Id.Length | Should -Be 0 } #Clean up after ourselves diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 index 17b85f019fa..6e06636d04c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 @@ -50,10 +50,10 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { It "Remove With Pipe line Input Pass Type Shortcut String" { $null = $ps.AddScript("Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value TestNote -TypeName int").Invoke() $ps.Commands.Clear() - $ps.AddScript("(Get-TypeData System.Int32).TypeName").Invoke() | Should Be System.Int32 + $ps.AddScript("(Get-TypeData System.Int32).TypeName").Invoke() | Should -Be System.Int32 $ps.Commands.Clear() $null = $ps.AddScript("'int' | Remove-TypeData").Invoke() - $ps.HadErrors | Should be $false + $ps.HadErrors | Should -be $false } It "Remove Type File In Initial Session State" { @@ -65,21 +65,21 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { $null = $ps.AddScript('$a = 1..3').Invoke() $ps.Commands.Clear() # test - $ps.AddScript('$a.Yada').Invoke() | Should be 3 + $ps.AddScript('$a.Yada').Invoke() | Should -be 3 $ps.Commands.Clear() - $ps.AddScript('$a.Yoda').Invoke() | Should Be 3 + $ps.AddScript('$a.Yoda').Invoke() | Should -Be 3 $ps.Commands.Clear() $null = $ps.AddScript("Remove-TypeData -Path $XMLFile1").Invoke() $ps.Commands.Clear() - $ps.AddScript('$a.Yada').Invoke() | Should BeNullOrEmpty + $ps.AddScript('$a.Yada').Invoke() | Should -BeNullOrEmpty $ps.Commands.Clear() - $ps.AddScript('$a.Yoda').Invoke() | Should Be 3 + $ps.AddScript('$a.Yoda').Invoke() | Should -Be 3 $ps.Commands.Clear() } It "Remove Type File In Initial Session State File Not In Cache" { $null = $ps.AddScript("Remove-TypeData -Path fakefile").Invoke() - $ps.HadErrors | Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorID | Should Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" + $ps.HadErrors | Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorID | Should -Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 304f68221e2..fe02af7059f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable -Name var1 -Value 4 Remove-Variable $var1 -ErrorAction SilentlyContinue -ErrorVariable err - $err.FullyQualifiedErrorId | Should Be "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $err.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" } It "Should not throw error when used without the Name field, and named variable is properly specified and exists" { @@ -17,7 +17,7 @@ Describe "Remove-Variable" -Tags "CI" { Remove-Variable var1 - $var1 | Should Be #nothing. it should be Nothing at all. + $var1 | Should -Be #nothing. it should be Nothing at all. } It "Should not throw error when used with the Name field, and named variable is specified and exists" { @@ -25,11 +25,11 @@ Describe "Remove-Variable" -Tags "CI" { Remove-Variable -Name var1 - $var1 | Should Be #nothing. it should be Nothing at all. + $var1 | Should -Be #nothing. it should be Nothing at all. } It "Should throw error when used with Name field, and named variable does not exist" { - { Remove-Variable -Name nonexistentVariable -ErrorAction Stop } | Should Throw + { Remove-Variable -Name nonexistentVariable -ErrorAction Stop } | Should -Throw } It "Should be able to remove a set of variables using wildcard characters" { @@ -37,15 +37,15 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpvar2 -Value 2 New-Variable tmpmyvar1 -Value 234 - $tmpvar1 | Should Be "tempvalue" - $tmpvar2 | Should Be 2 - $tmpmyvar1 | Should Be 234 + $tmpvar1 | Should -Be "tempvalue" + $tmpvar2 | Should -Be 2 + $tmpmyvar1 | Should -Be 234 Remove-Variable -Name tmp* - $tmpvar1 | Should Be #nothing. it should be Nothing at all. - $tmpvar2 | Should Be #nothing. it should be Nothing at all. - $tmpmyvar1 | Should Be #nothing. it should be Nothing at all. + $tmpvar1 | Should -Be #nothing. it should be Nothing at all. + $tmpvar2 | Should -Be #nothing. it should be Nothing at all. + $tmpmyvar1 | Should -Be #nothing. it should be Nothing at all. } It "Should be able to exclude a set of variables to remove using the Exclude switch" { @@ -53,15 +53,15 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpvar2 -Value 2 New-Variable tmpmyvar1 -Value 234 - $tmpvar1 | Should Be "tempvalue" - $tmpvar2 | Should Be 2 - $tmpmyvar1 | Should Be 234 + $tmpvar1 | Should -Be "tempvalue" + $tmpvar2 | Should -Be 2 + $tmpmyvar1 | Should -Be 234 Remove-Variable -Name tmp* -Exclude *my* - $tmpvar1 | Should Be #nothing. it should be Nothing at all. - $tmpvar2 | Should Be #nothing. it should be Nothing at all. - $tmpmyvar1 | Should Be 234 + $tmpvar1 | Should -Be #nothing. it should be Nothing at all. + $tmpvar2 | Should -Be #nothing. it should be Nothing at all. + $tmpmyvar1 | Should -Be 234 } It "Should be able to include a set of variables to remove using the Include switch" { @@ -70,17 +70,17 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpmyvar1 -Value 234 New-Variable thevar -Value 1 - $tmpvar1 | Should Be "tempvalue" - $tmpvar2 | Should Be 2 - $tmpmyvar1 | Should Be 234 - $thevar | Should Be 1 + $tmpvar1 | Should -Be "tempvalue" + $tmpvar2 | Should -Be 2 + $tmpmyvar1 | Should -Be 234 + $thevar | Should -Be 1 Remove-Variable -Name tmp* -Include *my* - $tmpvar1 | Should Be "tempvalue" - $tmpvar2 | Should Be 2 - $tmpmyvar1 | Should Be #nothing. it should be Nothing at all. - $thevar | should Be 1 + $tmpvar1 | Should -Be "tempvalue" + $tmpvar2 | Should -Be 2 + $tmpmyvar1 | Should -Be #nothing. it should be Nothing at all. + $thevar | should -Be 1 Remove-Variable tmpvar1 Remove-Variable tmpvar2 @@ -91,9 +91,9 @@ Describe "Remove-Variable" -Tags "CI" { It "Should throw an error when attempting to remove a read-only variable and the Force switch is not used" { New-Variable -Name var1 -Value 2 -Option ReadOnly - { Remove-Variable -Name var1 -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -ErrorAction Stop } | Should -Throw - $var1 | Should Be 2 + $var1 | Should -Be 2 Remove-Variable -Name var1 -Force } @@ -103,7 +103,7 @@ Describe "Remove-Variable" -Tags "CI" { Remove-Variable -Name var1 -Force - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } Context "Scope Tests" { @@ -112,75 +112,75 @@ Describe "Remove-Variable" -Tags "CI" { Remove-Variable -Name var1 -Scope global - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should not be able to clear a global variable using the local switch" { New-Variable -Name var1 -Value "context" -Scope global - { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should -Throw - $var1 | Should Be "context" + $var1 | Should -Be "context" Remove-Variable -Name var1 -Scope global - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should not be able to clear a global variable using the script switch" { New-Variable -Name var1 -Value "context" -Scope global - { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should -Throw - $var1 | Should Be "context" + $var1 | Should -Be "context" Remove-Variable -Name var1 -Scope global - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should be able to remove an item locally using the local switch" { New-Variable -Name var1 -Value "context" -Scope local - { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should -Throw - $var1 | Should Be context + $var1 | Should -Be context } It "Should be able to remove an item locally using the global switch" { New-Variable -Name var1 -Value "context" -Scope local - { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should -Throw - $var1 | Should Be "context" + $var1 | Should -Be "context" Remove-Variable -Name var1 -Scope local - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should be able to remove a local variable using the script scope switch" { New-Variable -Name var1 -Value "context" -Scope local - { Remove-Variable -Name var1 -Scope script -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope script -ErrorAction Stop } | Should -Throw - $var1 | Should Be "context" + $var1 | Should -Be "context" Remove-Variable -Name var1 -Scope local - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should be able to remove a script variable created using the script switch" { New-Variable -Name var1 -Value "context" -Scope script - { Remove-Variable -Name var1 -Scope script } | Should Not Throw + { Remove-Variable -Name var1 -Scope script } | Should -Not -Throw - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Should not be able to remove a global script variable that was created using the script scope switch" { New-Variable -Name var1 -Value "context" -Scope script - { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should Throw + { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should -Throw - $var1 | Should Be "context" + $var1 | Should -Be "context" } } } @@ -190,7 +190,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { New-Variable foo bar Remove-Variable foo $var1 = Get-Variable -Name foo -EA SilentlyContinue - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException"{ @@ -202,8 +202,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } } @@ -216,12 +216,12 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo| Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue - $var1 | Should BeNullOrEmpty + $var1 | Should -BeNullOrEmpty } It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException and force remove should also throw exception"{ @@ -233,8 +233,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } try @@ -244,8 +244,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } } @@ -260,16 +260,16 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "ItemNotFoundException" - $_.FullyQualifiedErrorId | Should Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.CategoryInfo | Should -Match "ItemNotFoundException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } $var1 = Get-Variable -Name foo - $var1.Name | Should Be "foo" - $var1.Value | Should Be "bar" - $var1.Options | Should Be "None" - $var1.Description | Should Be "" + $var1.Name | Should -Be "foo" + $var1.Value | Should -Be "bar" + $var1.Options | Should -Be "None" + $var1.Description | Should -Be "" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 index 07f301a63d1..3807d49196c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 @@ -8,19 +8,19 @@ Describe "Get-Runspace cmdlet tests" -Tag "CI" { } It "Get-Runspace should return the current runspace" { $runspace = get-runspace |Sort-Object -property id | Select-Object -first 1 - $runspace.InstanceId | Should be $ExpectedInstanceId + $runspace.InstanceId | Should -be $ExpectedInstanceId } It "Get-Runspace with runspace InstanceId should return the correct runspace" { $runspace = get-runspace -instanceid $CurrentRunspace.InstanceId - $runspace.InstanceId | Should be $ExpectedInstanceId + $runspace.InstanceId | Should -be $ExpectedInstanceId } It "Get-Runspace with runspace name should return the correct runspace" { $runspace = get-runspace -name $currentRunspace.Name - $runspace.InstanceId | Should be $ExpectedInstanceId + $runspace.InstanceId | Should -be $ExpectedInstanceId } It "Get-Runspace with runspace Id should return the correct runspace" { $runspace = get-runspace -id $CurrentRunspace.Id - $runspace.InstanceId | Should be $ExpectedInstanceId + $runspace.InstanceId | Should -be $ExpectedInstanceId } Context "Multiple Runspaces" { BeforeAll { @@ -36,8 +36,8 @@ Describe "Get-Runspace cmdlet tests" -Tag "CI" { It "Get-Runspace should return the new runspaces" { $result = get-runspace # if the ids don't match, we'll get null passed to should - $result.id | Where-Object {$_ -eq $r1.id } | should be $r1.id - $result.id | Where-Object {$_ -eq $r2.id } | should be $r2.id + $result.id | Where-Object {$_ -eq $r1.id } | should -be $r1.id + $result.id | Where-Object {$_ -eq $r2.id } | should -be $r2.id } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index 825b168c65c..6f9883b721e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -9,46 +9,46 @@ Describe "Select-Object" -Tags "CI" { } It "Handle piped input without error" { - { $dirObject | Select-Object } | Should Not Throw + { $dirObject | Select-Object } | Should -Not -Throw } It "Should treat input as a single object with the inputObject parameter" { $result = $(Select-Object -inputObject $dirObject -last $TestLength).Length $expected = $dirObject.Length - $result | Should Be $expected + $result | Should -Be $expected } It "Should be able to use the alias" { - { $dirObject | select } | Should Not Throw + { $dirObject | select } | Should -Not -Throw } It "Should have same result when using alias" { $result = $dirObject | select $expected = $dirObject | Select-Object - $result | Should Be $expected + $result | Should -Be $expected } It "Should return correct object with First parameter" { $result = $dirObject | Select-Object -First $TestLength - $result.Length | Should Be $TestLength + $result.Length | Should -Be $TestLength for ($i=0; $i -lt $TestLength; $i++) { - $result[$i].Name | Should Be $dirObject[$i].Name + $result[$i].Name | Should -Be $dirObject[$i].Name } } It "Should return correct object with Last parameter" { $result = $dirObject | Select-Object -Last $TestLength - $result.Length | Should Be $TestLength + $result.Length | Should -Be $TestLength for ($i=0; $i -lt $TestLength; $i++) { - $result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name + $result[$i].Name | Should -Be $dirObject[$dirObject.Length - $TestLength + $i].Name } } @@ -56,31 +56,31 @@ Describe "Select-Object" -Tags "CI" { $result = ("a","b","c","a","a","a" | Select-Object -Unique).Length $expected = 3 - $result | Should Be $expected + $result | Should -Be $expected } It "Should return correct object with Skip parameter" { $result = $dirObject | Select-Object -Skip $TestLength - $result.Length | Should Be ($dirObject.Length - $TestLength) + $result.Length | Should -Be ($dirObject.Length - $TestLength) for ($i=0; $i -lt $TestLength; $i++) { - $result[$i].Name | Should Be $dirObject[$TestLength + $i].Name + $result[$i].Name | Should -Be $dirObject[$TestLength + $i].Name } } It "Should return an object with selected columns" { $result = $dirObject | Select-Object -Property Name, Size - $result.Length | Should Be $dirObject.Length - $result[0].Name | Should Be $dirObject[0].Name - $result[0].Size | Should Be $dirObject[0].Size - $result[0].Mode | Should BeNullOrEmpty + $result.Length | Should -Be $dirObject.Length + $result[0].Name | Should -Be $dirObject[0].Name + $result[0].Size | Should -Be $dirObject[0].Size + $result[0].Mode | Should -BeNullOrEmpty } It "Should send output to pipe properly" { - {$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw + {$dirObject | Select-Object -Unique | pipelineConsume} | Should -Not -Throw } It "Should select array indices with Index parameter" { @@ -88,8 +88,8 @@ Describe "Select-Object" -Tags "CI" { $secondIndex = 4 $result = $dirObject | Select-Object -Index $firstIndex, $secondIndex - $result[0].Name | Should Be $dirObject[$firstIndex].Name - $result[1].Name | Should Be $dirObject[$secondIndex].Name + $result[0].Name | Should -Be $dirObject[$firstIndex].Name + $result[1].Name | Should -Be $dirObject[$secondIndex].Name } # Note that these two tests will modify original values of $dirObject @@ -99,9 +99,9 @@ Describe "Select-Object" -Tags "CI" { $orig2 = $dirObject[$TestLength].Size $result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength - $result[0].Size | Should Be ($orig1 + 1) - $dirObject[0].Size | Should Be ($orig1 + 1) - $dirObject[$TestLength].Size | Should Be $orig2 + $result[0].Size | Should -Be ($orig1 + 1) + $dirObject[0].Size | Should -Be ($orig1 + 1) + $dirObject[$TestLength].Size | Should -Be $orig2 } It "Should wait when used with -Wait option" { @@ -109,9 +109,9 @@ Describe "Select-Object" -Tags "CI" { $orig2 = $dirObject[$TestLength].Size $result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength -Wait - $result[0].Size | Should Be ($orig1 + 1) - $dirObject[0].Size | Should Be ($orig1 + 1) - $dirObject[$TestLength].Size | Should Be ($orig2 + 1) + $result[0].Size | Should -Be ($orig1 + 1) + $dirObject[0].Size | Should -Be ($orig1 + 1) + $dirObject[$TestLength].Size | Should -Be ($orig2 + 1) } } @@ -131,82 +131,82 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { } catch { - $_.CategoryInfo | Should Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should be "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $_.CategoryInfo | Should -Match "PSArgumentException" + $_.FullyQualifiedErrorId | Should -be "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" } } It "Select-Object with string property should work"{ $result = "bar" | select-object -Prop foo | Measure-Object - $result.Count | Should Be 1 + $result.Count | Should -Be 1 } It "Select-Object with Property First Last Overlap should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -First 2 -Last 3 - $results.Count | Should Be 4 + $results.Count | Should -Be 4 - $results[0].LastName | Should Be $employees[0].LastName - $results[1].LastName | Should Be $employees[1].LastName - $results[2].LastName | Should Be $employees[2].LastName - $results[3].LastName | Should Be $employees[3].LastName + $results[0].LastName | Should -Be $employees[0].LastName + $results[1].LastName | Should -Be $employees[1].LastName + $results[2].LastName | Should -Be $employees[2].LastName + $results[3].LastName | Should -Be $employees[3].LastName - $results[0].YearsInMS | Should Be $employees[0].YearsInMS - $results[1].YearsInMS | Should Be $employees[1].YearsInMS - $results[2].YearsInMS | Should Be $employees[2].YearsInMS - $results[3].YearsInMS | Should Be $employees[3].YearsInMS + $results[0].YearsInMS | Should -Be $employees[0].YearsInMS + $results[1].YearsInMS | Should -Be $employees[1].YearsInMS + $results[2].YearsInMS | Should -Be $employees[2].YearsInMS + $results[3].YearsInMS | Should -Be $employees[3].YearsInMS } It "Select-Object with Property First Last should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -First 2 -Last 1 - $results.Count | Should Be 3 + $results.Count | Should -Be 3 - $results[0].LastName | Should Be $employees[0].LastName - $results[1].LastName | Should Be $employees[1].LastName - $results[2].LastName | Should Be $employees[3].LastName + $results[0].LastName | Should -Be $employees[0].LastName + $results[1].LastName | Should -Be $employees[1].LastName + $results[2].LastName | Should -Be $employees[3].LastName - $results[0].YearsInMS | Should Be $employees[0].YearsInMS - $results[1].YearsInMS | Should Be $employees[1].YearsInMS - $results[2].YearsInMS | Should Be $employees[3].YearsInMS + $results[0].YearsInMS | Should -Be $employees[0].YearsInMS + $results[1].YearsInMS | Should -Be $employees[1].YearsInMS + $results[2].YearsInMS | Should -Be $employees[3].YearsInMS } It "Select-Object with Property First should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -First 2 - $results.Count | Should Be 2 + $results.Count | Should -Be 2 - $results[0].LastName | Should Be $employees[0].LastName - $results[1].LastName | Should Be $employees[1].LastName + $results[0].LastName | Should -Be $employees[0].LastName + $results[1].LastName | Should -Be $employees[1].LastName - $results[0].YearsInMS | Should Be $employees[0].YearsInMS - $results[1].YearsInMS | Should Be $employees[1].YearsInMS + $results[0].YearsInMS | Should -Be $employees[0].YearsInMS + $results[1].YearsInMS | Should -Be $employees[1].YearsInMS } It "Select-Object with Property First Zero should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -First 0 - $results.Count | Should Be 0 + $results.Count | Should -Be 0 } It "Select-Object with Property Last Zero should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -Last 0 - $results.Count | Should Be 0 + $results.Count | Should -Be 0 } It "Select-Object with Unique should work"{ $results = $employees | Select-Object -Property "YearsInMS", "L*" -Unique:$true - $results.Count | Should Be 3 + $results.Count | Should -Be 3 - $results[0].LastName | Should Be $employees[1].LastName - $results[1].LastName | Should Be $employees[2].LastName - $results[2].LastName | Should Be $employees[3].LastName + $results[0].LastName | Should -Be $employees[1].LastName + $results[1].LastName | Should -Be $employees[2].LastName + $results[2].LastName | Should -Be $employees[3].LastName - $results[0].YearsInMS | Should Be $employees[1].YearsInMS - $results[1].YearsInMS | Should Be $employees[2].YearsInMS - $results[2].YearsInMS | Should Be $employees[3].YearsInMS + $results[0].YearsInMS | Should -Be $employees[1].YearsInMS + $results[1].YearsInMS | Should -Be $employees[2].YearsInMS + $results[2].YearsInMS | Should -Be $employees[3].YearsInMS } It "Select-Object with Simple should work"{ @@ -216,38 +216,38 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { $employees3 = @($employee1,$employee2,$employee3,$employee4) $results = $employees3 | Select-Object -Property "FirstName", "YearsInMS" - $results.Count | Should Be 3 + $results.Count | Should -Be 3 - $results[0].FirstName | Should Be $employees3[0].FirstName - $results[1].FirstName | Should Be $employees3[1].FirstName - $results[2].FirstName | Should Be $employees3[2].FirstName + $results[0].FirstName | Should -Be $employees3[0].FirstName + $results[1].FirstName | Should -Be $employees3[1].FirstName + $results[2].FirstName | Should -Be $employees3[2].FirstName - $results[0].YearsInMS | Should Be $employees3[0].YearsInMS - $results[1].YearsInMS | Should Be $employees3[1].YearsInMS - $results[2].YearsInMS | Should Be $employees3[2].YearsInMS + $results[0].YearsInMS | Should -Be $employees3[0].YearsInMS + $results[1].YearsInMS | Should -Be $employees3[1].YearsInMS + $results[2].YearsInMS | Should -Be $employees3[2].YearsInMS } It "Select-Object with no input should work"{ $results = $null | Select-Object -Property "FirstName", "YearsInMS", "FirstNa*" - $results.Count | Should Be 0 + $results.Count | Should -Be 0 } It "Select-Object with Start-Time In Idle Process should work"{ $results = Get-Process i* | Select-Object ProcessName - $results.Count | Should Not Be 0 + $results.Count | Should -Not -Be 0 } It "Select-Object with Skip should work"{ $results = "1","2","3" | Select-Object -Skip 1 - $results.Count | Should Be 2 - $results[0] | Should Be 2 - $results[1] | Should Be 3 + $results.Count | Should -Be 2 + $results[0] | Should -Be 2 + $results[1] | Should -Be 3 } It "Select-Object with Index should work"{ $results = "1","2","3" | Select-Object -Index 2 - $results.Count | Should Be 1 - $results[0] | Should Be "3" + $results.Count | Should -Be 1 + $results[0] | Should -Be "3" } } @@ -256,45 +256,45 @@ Describe "Select-Object with Property = '*'" -Tags "CI" { # Issue #2420 It "Select-Object with implicit Property = '*' don't return property named '*'"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -ExcludeProperty thing - $results.psobject.Properties.Item("*") | Should Be $null + $results.psobject.Properties.Item("*") | Should -Be $null } # Issue #2420 It "Select-Object with explicit Property = '*' don't return property named '*'"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -Property * -ExcludeProperty thing - $results.psobject.Properties.Item("*") | Should Be $null + $results.psobject.Properties.Item("*") | Should -Be $null } # Issue #2351 It "Select-Object with implicit Property = '*' exclude single property"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -ExcludeProperty thing - $results.psobject.Properties.Item("Thing") | Should Be $null - $results.psobject.Properties.Item("*") | Should Be $null + $results.psobject.Properties.Item("Thing") | Should -Be $null + $results.psobject.Properties.Item("*") | Should -Be $null } # Issue #2351 It "Select-Object with explicit Property = '*' exclude single property"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -Property * -ExcludeProperty thing - $results.psobject.Properties.Item("Thing") | Should Be $null - $results.psobject.Properties.Item("*") | Should Be $null + $results.psobject.Properties.Item("Thing") | Should -Be $null + $results.psobject.Properties.Item("*") | Should -Be $null } # Issue #2351 It "Select-Object with implicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -ExcludeProperty Param2 - $results.Param2 | Should Be $null - $results.Thing | Should Be "thing1" + $results.Param2 | Should -Be $null + $results.Thing | Should -Be "thing1" } # Issue #2351 It "Select-Object with explicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -Property * -ExcludeProperty Param2 - $results.Param2 | Should Be $null - $results.Thing | Should Be "thing1" + $results.Param2 | Should -Be $null + $results.Thing | Should -Be "thing1" } It "Select-Object with ExpandProperty and Property don't skip processing ExcludeProperty" { $p = Get-Process -Id $pid | Select-Object -Property Process* -ExcludeProperty ProcessorAffinity -ExpandProperty Modules - $p[0].psobject.Properties.Item("ProcessorAffinity") | Should Be $null + $p[0].psobject.Properties.Item("ProcessorAffinity") | Should -Be $null } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 index 46454251ebb..8156c127cdf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 @@ -8,26 +8,26 @@ Describe "Select-String" -Tags "CI" { $testinputtwo = "hello","Hello" it "Should be called without errors" { - { $testinputone | Select-String -Pattern "hello" } | Should Not Throw + { $testinputone | Select-String -Pattern "hello" } | Should -Not -Throw } it "Should return an array data type when multiple matches are found" { $result = $testinputtwo | Select-String -Pattern "hello" - ,$result | Should BeOfType "System.Array" + ,$result | Should -BeOfType "System.Array" } it "Should return an object type when one match is found" { $result = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive - ,$result | Should BeOfType "System.Object" + ,$result | Should -BeOfType "System.Object" } it "Should return matchinfo type" { $result = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive - ,$result | Should BeOfType "Microsoft.PowerShell.Commands.MatchInfo" + ,$result | Should -BeOfType "Microsoft.PowerShell.Commands.MatchInfo" } it "Should be called without an error using ca for casesensitive " { - {$testinputone | Select-String -Pattern "hello" -ca } | Should Not Throw + {$testinputone | Select-String -Pattern "hello" -ca } | Should -Not -Throw } it "Should use the ca alias for casesensitive" { @@ -35,40 +35,40 @@ Describe "Select-String" -Tags "CI" { $secondMatch = $testinputtwo | Select-String -Pattern "hello" -ca $equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0 - $equal | Should Be True + $equal | Should -Be True } it "Should only return the case sensitive match when the casesensitive switch is used" { - $testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should Be "hello" + $testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should -Be "hello" } it "Should accept a collection of strings from the input object" { - { Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should Not Throw + { Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should -Not -Throw } it "Should return system.object when the input object switch is used on a collection" { $result = Select-String -InputObject "some stuff", "other stuff" -pattern "other" - ,$result | Should BeOfType "System.Object" + ,$result | Should -BeOfType "System.Object" } it "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" { - Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should BeNullOrEmpty + Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should -BeNullOrEmpty } it "Should return a bool type when the quiet switch is used" { - ,($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should BeOfType "System.Boolean" + ,($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should -BeOfType "System.Boolean" } it "Should be true when select string returns a positive result when the quiet switch is used" { - ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should Be $True + ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should -Be $True } it "Should be empty when select string does not return a result when the quiet switch is used" { - $testinputtwo | Select-String -Quiet "goodbye" | Should BeNullOrEmpty + $testinputtwo | Select-String -Quiet "goodbye" | Should -BeNullOrEmpty } it "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" { - $testinputone | Select-String -Pattern "goodbye" -NotMatch | Should Be "hello", "hello" + $testinputone | Select-String -Pattern "goodbye" -NotMatch | Should -Be "hello", "hello" } it "Should return the same as NotMatch" { @@ -76,7 +76,7 @@ Describe "Select-String" -Tags "CI" { $secondMatch = $testinputone | Select-String -pattern "goodbye" -n $equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0 - $equal | Should Be True + $equal | Should -Be True } } @@ -94,25 +94,25 @@ Describe "Select-String" -Tags "CI" { It "Should return an object when a match is found is the file on only one line" { $result = Select-String $testInputFile -Pattern "string" - ,$result | Should BeOfType "System.Object" + ,$result | Should -BeOfType "System.Object" } It "Should return an array when a match is found is the file on several lines" { $result = Select-String $testInputFile -Pattern "in" - ,$result | Should BeOfType "System.Array" - $result[0] | Should BeOfType "Microsoft.PowerShell.Commands.MatchInfo" + ,$result | Should -BeOfType "System.Array" + $result[0] | Should -BeOfType "Microsoft.PowerShell.Commands.MatchInfo" } It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" { $expected = $testInputFile + ":1:This is a text string, and another string" - Select-String $testInputFile -Pattern "string" | Should Be $expected + Select-String $testInputFile -Pattern "string" | Should -Be $expected } It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" { $expected = $testInputFile + ":2:This is the second line" - Select-String $testInputFile -Pattern "second"| Should Be $expected + Select-String $testInputFile -Pattern "second"| Should -Be $expected } It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" { @@ -121,15 +121,15 @@ Describe "Select-String" -Tags "CI" { $expected3 = "This is the third line" $expected4 = "This is the fourth line" - (Select-String in $testInputFile)[0].Line | Should Be $expected1 - (Select-String in $testInputFile)[1].Line | Should Be $expected2 - (Select-String in $testInputFile)[2].Line | Should Be $expected3 - (Select-String in $testInputFile)[3].Line | Should Be $expected4 - (Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty + (Select-String in $testInputFile)[0].Line | Should -Be $expected1 + (Select-String in $testInputFile)[1].Line | Should -Be $expected2 + (Select-String in $testInputFile)[2].Line | Should -Be $expected3 + (Select-String in $testInputFile)[3].Line | Should -Be $expected4 + (Select-String in $testInputFile)[4].Line | Should -BeNullOrEmpty } It "Should return empty because 'for' is not found in testfile1 " { - Select-String for $testInputFile | Should BeNullOrEmpty + Select-String for $testInputFile | Should -BeNullOrEmpty } It "Should return the third line in testfile1 and the lines above and below it " { @@ -137,13 +137,13 @@ Describe "Select-String" -Tags "CI" { $expectedLineBefore = "testfile1.txt:3:This is the third line" $expectedLineAfter = "testfile1.txt:4:This is the fourth line" - Select-String third $testInputFile -Context 1 | Should Match $expectedLine - Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore - Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter + Select-String third $testInputFile -Context 1 | Should -Match $expectedLine + Select-String third $testInputFile -Context 1 | Should -Match $expectedLineBefore + Select-String third $testInputFile -Context 1 | Should -Match $expectedLineAfter } It "Should return the number of matches for 'is' in textfile1 " { - (Select-String is $testInputFile -CaseSensitive).count| Should Be 4 + (Select-String is $testInputFile -CaseSensitive).count| Should -Be 4 } It "Should return the third line in testfile1 when a relative path is used" { @@ -152,7 +152,7 @@ Describe "Select-String" -Tags "CI" { $relativePath = Join-Path -Path $testDirectory -ChildPath ".." $relativePath = Join-Path -Path $relativePath -ChildPath $TestDirectory.Name $relativePath = Join-Path -Path $relativePath -ChildPath testfile1.txt - Select-String third $relativePath | Should Match $expected + Select-String third $relativePath | Should -Match $expected } It "Should return the fourth line in testfile1 when a relative path is used" { @@ -160,20 +160,20 @@ Describe "Select-String" -Tags "CI" { pushd $testDirectory - Select-String matches (Join-Path -Path $testDirectory -ChildPath testfile1.txt) | Should Match $expected + Select-String matches (Join-Path -Path $testDirectory -ChildPath testfile1.txt) | Should -Match $expected popd } It "Should return the fourth line in testfile1 when a regular expression is used" { $expected = "testfile1.txt:5:No matches" - Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected + Select-String 'matc*' $testInputFile -CaseSensitive | Should -Match $expected } It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" { $expected = "testfile1.txt:5:No matches" - Select-String 'matc*' $testInputFile -ca | Should Match $expected + Select-String 'matc*' $testInputFile -ca | Should -Match $expected } } Push-Location $currentDirectory diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 index aaa6f60baba..520523e7ed5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 @@ -23,8 +23,8 @@ Describe "Select-XML DRT Unit Tests" -Tags "CI" { It "Select-XML should work"{ $results = Select-XML -Path $testfile -XPath "/bookstore/book/title" - $results.Count | Should Be 2 - $results[0].Node."#text" | Should Be "Harry Potter" - $results[1].Node."#text" | Should Be "Learning XML" + $results.Count | Should -Be 2 + $results[0].Node."#text" | Should -Be "Harry Potter" + $results[1].Node."#text" | Should -Be "Learning XML" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index 4564490c865..a00d9bbaf1f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -137,13 +137,13 @@ Describe "Basic Send-MailMessage tests" -Tags CI { $body = "Greetings from me." $subject = "Test message" Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1 - Test-Path -Path $mailBox | Should Be $true + Test-Path -Path $mailBox | Should -Be $true $mail = read-mail $mailBox - $mail.From | Should BeExactly $address - $mail.To.Count | Should BeExactly 1 - $mail.To[0] | Should BeExactly $address - $mail.Subject | Should BeExactly $subject - $mail.Body.Count | Should BeExactly 1 - $mail.Body[0] | Should BeExactly $body + $mail.From | Should -BeExactly $address + $mail.To.Count | Should -BeExactly 1 + $mail.To[0] | Should -BeExactly $address + $mail.Subject | Should -BeExactly $subject + $mail.Body.Count | Should -BeExactly 1 + $mail.Body[0] | Should -BeExactly $body } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index 21ecb6cbb33..5347ed4de0a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -8,71 +8,71 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" } } It "Set-Alias ReadOnly Force"{ Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "ReadOnly" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "ReadOnly" Set-Alias -Name ABCD -Value "foo" -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Set-Alias Name And Value Valid"{ Set-Alias -Name ABCD -Value "MyCommand" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "MyCommand" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "MyCommand" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Set-Alias Name And Value Positional Valid"{ Set-Alias -Name ABCD "foo" $result=Get-Alias ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Set-Alias Description Valid"{ Set-Alias -Name ABCD -Value "MyCommand" -Description "test description" $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "MyCommand" - $result.Description| Should Be "test description" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "MyCommand" + $result.Description| Should -Be "test description" + $result.Options| Should -Be "None" } It "Set-Alias Scope Valid"{ Set-Alias -Name ABCD -Value "localfoo" -scope local -Force:$true Set-Alias -Name ABCD -Value "foo1" -scope "1" -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "localfoo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "localfoo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope local - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "localfoo" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "localfoo" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "1" - $result.Name| Should Be "ABCD" - $result.Definition| Should Be "foo1" - $result.Description| Should Be "" - $result.Options| Should Be "None" + $result.Name| Should -Be "ABCD" + $result.Definition| Should -Be "foo1" + $result.Description| Should -Be "" + $result.Options| Should -Be "None" } It "Set-Alias Expose Bug 1062958, BugId:905449"{ try { @@ -80,7 +80,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" } } } @@ -89,16 +89,16 @@ Describe "Set-Alias" -Tags "CI" { Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" } It "Should be able to set alias without error" { - { set-alias -Name gd -Value Get-Date } | Should Not Throw + { set-alias -Name gd -Value Get-Date } | Should -Not -Throw } It "Should be able to have the same output between set-alias and the output of the function being aliased" { set-alias -Name gd -Value Get-Date - gd | Should Be $(Get-Date) + gd | Should -Be $(Get-Date) } It "Should be able to use the sal alias" { - { sal gd Get-Date } | Should Not Throw + { sal gd Get-Date } | Should -Not -Throw } It "Should have the same output between the sal alias and the original set-alias cmdlet" { @@ -106,6 +106,6 @@ Describe "Set-Alias" -Tags "CI" { Set-Alias -Name gd2 -Value Get-Date - gd2 | Should Be $(gd) + gd2 | Should -Be $(gd) } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index 387bea1bfc8..2e2234d2336 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -2,13 +2,13 @@ # Licensed under the MIT License. Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') { It "Set-Date should be able to set the date in an elevated context" { - { Get-Date | Set-Date } | Should Not Throw + { Get-Date | Set-Date } | Should -Not -Throw } It "Set-Date should be able to set the date with -Date parameter" { $target = Get-Date $expected = $target - Set-Date -Date $target | Should Be $expected + Set-Date -Date $target | Should -Be $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 index a5bb84d2f19..6e037f52ba2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 @@ -40,99 +40,99 @@ set-psbreakpoint -command foo It "Should be able to set psbreakpoints for -Line" { $brk = Set-PSBreakpoint -Line 13 -Script $scriptFileName - $brk.Line | Should Be 13 + $brk.Line | Should -Be 13 Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -Line and -column" { $brk = set-psbreakpoint -line 13 -column 1 -script $scriptFileName - $brk.Line | Should Be 13 - $brk.Column | Should Be 1 + $brk.Line | Should -Be 13 + $brk.Column | Should -Be 1 Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -Line and -action" { $brk = set-psbreakpoint -line 13 -action {{ break; }} -script $scriptFileName - $brk.Line | Should Be 13 - $brk.Action | Should Match "break" + $brk.Line | Should -Be 13 + $brk.Action | Should -Match "break" Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -Line, -column and -action" { $brk = set-psbreakpoint -line 13 -column 1 -action {{ break; }} -script $scriptFileName - $brk.Line | Should Be 13 - $brk.Column | Should Be 1 - $brk.Action | Should Match "break" + $brk.Line | Should -Be 13 + $brk.Column | Should -Be 1 + $brk.Action | Should -Match "break" Remove-PSBreakPoint -Id $brk.Id } It "-script and -line can take multiple items" { $brk = sbp -line 11,12,13 -column 1 -script $scriptFileName,$scriptFileName - $brk.Line | Should BeIn 11,12,13 - $brk.Column | Should BeIn 1 + $brk.Line | Should -BeIn 11,12,13 + $brk.Column | Should -BeIn 1 Remove-PSBreakPoint -Id $brk.Id } It "-script and -line are positional" { $brk = sbp $scriptFileName 13 - $brk.Line | Should Be 13 + $brk.Line | Should -Be 13 Remove-PSBreakPoint -Id $brk.Id } It "-script, -line and -column are positional" { $brk = sbp $scriptFileName 13 1 - $brk.Line | Should Be 13 - $brk.Column | Should Be 1 + $brk.Line | Should -Be 13 + $brk.Column | Should -Be 1 Remove-PSBreakPoint -Id $brk.Id } It "Should throw Exception when missing mandatory parameter -line" -Pending { $output = & $ps -noninteractive -command "sbp -column 1 -script $scriptFileName" - [system.string]::Join(" ", $output) | Should Match "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + [system.string]::Join(" ", $output) | Should -Match "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } It "Should throw Exception when missing mandatory parameter" -Pending { $output = & $ps -noprofile -noninteractive -command "sbp -line 1" - [system.string]::Join(" ", $output) | Should Match "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + [system.string]::Join(" ", $output) | Should -Match "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } It "Should be able to set psbreakpoints for -command" { $brk = set-psbreakpoint -command "write-host" - $brk.Command | Should Be "write-host" + $brk.Command | Should -Be "write-host" Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -command, -script" { $brk = set-psbreakpoint -command "write-host" -script $scriptFileName - $brk.Command | Should Be "write-host" + $brk.Command | Should -Be "write-host" Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -command, -action and -script" { $brk = set-psbreakpoint -command "write-host" -action {{ break; }} -script $scriptFileName - $brk.Action | Should Match "break" + $brk.Action | Should -Match "break" Remove-PSBreakPoint -Id $brk.Id } It "-Command can take multiple items" { $brk = set-psbreakpoint -command write-host,Hello - $brk.Command | Should Be write-host,Hello + $brk.Command | Should -Be write-host,Hello Remove-PSBreakPoint -Id $brk.Id } It "-Script is positional" { $brk = set-psbreakpoint -command "Hello" $scriptFileName - $brk.Command | Should Be "Hello" + $brk.Command | Should -Be "Hello" Remove-PSBreakPoint -Id $brk.Id $brk = set-psbreakpoint $scriptFileName -command "Hello" - $brk.Command | Should Be "Hello" + $brk.Command | Should -Be "Hello" Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set breakpoints on functions" { $brk = set-psbreakpoint -command Hello,Goodbye -script $scriptFileName - $brk.Command | Should Be Hello,Goodbye + $brk.Command | Should -Be Hello,Goodbye Remove-PSBreakPoint -Id $brk.Id } @@ -142,7 +142,7 @@ set-psbreakpoint -command foo Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } } @@ -153,7 +153,7 @@ set-psbreakpoint -command foo Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should Be "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + $_.FullyQualifiedErrorId | Should -Be "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } $ErrorActionPreference = "SilentlyContinue" } @@ -162,7 +162,7 @@ set-psbreakpoint -command foo & $ps -noprofile $scriptFileNameBug $breakpoint = Get-PSBreakpoint -Script $scriptFileNameBug - $breakpoint | Should BeNullOrEmpty + $breakpoint | Should -BeNullOrEmpty } It "Fail to set psbreakpoints when script is a file of wrong type" { @@ -170,7 +170,7 @@ set-psbreakpoint -command foo $ErrorActionPreference = "Stop" { Set-PSBreakpoint -Script $tempFile -Line 1 - } | Should Throw + } | Should -Throw $ErrorActionPreference = "SilentlyContinue" Remove-Item $tempFile -Force } @@ -180,7 +180,7 @@ set-psbreakpoint -command foo ${script.ps1} = 10 { Set-PSBreakpoint -Script variable:\script.ps1 -Line 1 - } | Should Throw + } | Should -Throw $ErrorActionPreference = "SilentlyContinue" } @@ -198,7 +198,7 @@ Describe "Set-PSBreakpoint" -Tags "CI" { It "Should be able to set a psbreakpoint on a line" { $lineNumber = 1 $brk = Set-PSBreakpoint -Line $lineNumber -Script $testScript - $brk.Line | Should Be $lineNumber + $brk.Line | Should -Be $lineNumber Remove-PSBreakPoint -Id $brk.Id } @@ -207,20 +207,20 @@ Describe "Set-PSBreakpoint" -Tags "CI" { $lineNumber = "one" Set-PSBreakpoint -Line $lineNumber -Script $testScript - } | Should Throw + } | Should -Throw } It "Should be able to set a psbreakpoint on a Command" { $command = "theCommand" $brk = Set-PSBreakpoint -Command $command -Script $testScript - $brk.Command | Should Be $command + $brk.Command | Should -Be $command Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set a psbreakpoint on a variable" { $var = "theVariable" $brk = Set-PSBreakpoint -Command $var -Script $testScript - $brk.Command | Should Be $var + $brk.Command | Should -Be $var Remove-PSBreakPoint -Id $brk.Id } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index dab857ca09f..823796dbe5e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -5,19 +5,19 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable normal variable Name should works"{ Set-Variable foo bar $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "Set-Variable normal variable Name with position should works"{ Set-Variable -Name foo bar $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "Set-Variable normal variable Name with scope should works"{ @@ -25,24 +25,24 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable -Name foo -Value bar -Scope "1" $var1=Get-Variable -Name foo -scope "1" - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" Set-Variable -Name foo -Value newValue -Scope "local" $var1=Get-Variable -Name foo -scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be "newValue" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "newValue" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" Set-Variable -Name foo -Value newValue2 -Scope "script" $var1=Get-Variable -Name foo -scope "script" - $var1.Name|Should Be "foo" - $var1.Value|Should Be "newValue2" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "newValue2" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } It "Set-Variable normal variable Name with position should works"{ @@ -53,40 +53,40 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable -Name "*aV*" -Value "overwrite" -Include "*Var*" -Exclude "bcd*" $var1=Get-Variable -Name "*aVar*" -Scope "local" - $var1[0].Name|Should Be "abcaVar" - $var1[0].Value|Should Be "overwrite" - $var1[0].Options|Should Be "None" - $var1[0].Description|Should Be "" - - $var1[1].Name|Should Be "aVarfoo" - $var1[1].Value|Should Be "overwrite" - $var1[1].Options|Should Be "None" - $var1[1].Description|Should Be "" - - $var1[2].Name|Should Be "bcdaVar" - $var1[2].Value|Should Be "anotherVal" - $var1[2].Options|Should Be "None" - $var1[2].Description|Should Be "" + $var1[0].Name|Should -Be "abcaVar" + $var1[0].Value|Should -Be "overwrite" + $var1[0].Options|Should -Be "None" + $var1[0].Description|Should -Be "" + + $var1[1].Name|Should -Be "aVarfoo" + $var1[1].Value|Should -Be "overwrite" + $var1[1].Options|Should -Be "None" + $var1[1].Description|Should -Be "" + + $var1[2].Name|Should -Be "bcdaVar" + $var1[2].Value|Should -Be "anotherVal" + $var1[2].Options|Should -Be "None" + $var1[2].Description|Should -Be "" } It "Set-Variable normal variable Name with Description and Value should works"{ Set-Variable foo bar Set-Variable -Name foo $null -Description "new description" -PassThru:$true -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be $null - $var1.Options|Should Be "None" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be $null + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "new description" } It "Set-Variable normal variable Name with just Description should works"{ Set-Variable foo bar Set-Variable -Name foo -Description "new description" -PassThru:$true -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "new description" } It "Set-Variable overwrite Constant Option should throw SessionStateUnauthorizedAccessException"{ @@ -96,24 +96,24 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.FullyQualifiedErrorId | Should -be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } It "Set-Variable of existing Private variable without force should throw Exception"{ Set-Variable abcaVar bar -Description "new description" -Option Private $var1=Get-Variable -Name abcaVar - $var1.Name|Should Be "abcaVar" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "Private" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "abcaVar" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "Private" + $var1.Description|Should -Be "new description" Set-Variable abcaVar other -Description "new description" $var1=Get-Variable -Name abcaVar - $var1.Name|Should Be "abcaVar" - $var1.Value|Should Be "other" - $var1.Options|Should Be "Private" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "abcaVar" + $var1.Value|Should -Be "other" + $var1.Options|Should -Be "Private" + $var1.Description|Should -Be "new description" } It "Set-Variable with Exclude, then Get-Variable it should throw ItemNotFoundException"{ @@ -123,83 +123,83 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } It "Set-Variable of existing ReadOnly variable without force should throw Exception"{ Set-Variable abcaVar bar -Description "new description" -Option ReadOnly $var1=Get-Variable -Name abcaVar - $var1.Name|Should Be "abcaVar" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "ReadOnly" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "abcaVar" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "ReadOnly" + $var1.Description|Should -Be "new description" try { Set-Variable abcaVar -Option None -EA Stop Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.FullyQualifiedErrorId | Should -be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } It "Set-Variable of ReadOnly variable with private scope should work"{ Set-Variable foo bar -Description "new description" -Option ReadOnly -scope "private" $var1=Get-Variable -Name foo - $var1.Name|Should Be "foo" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "ReadOnly, Private" - $var1.Description|Should Be "new description" + $var1.Name|Should -Be "foo" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "ReadOnly, Private" + $var1.Description|Should -Be "new description" } It "Set-Variable pipeline with Get-Variable should work"{ $footest1="bar" ${Get-Variable footest1 -valueonly|Set-Variable bootest1 -passthru} $var1=Get-Variable -Name footest1 - $var1.Name|Should Be "footest1" - $var1.Value|Should Be "bar" - $var1.Options|Should Be "None" - $var1.Description|Should Be "" + $var1.Name|Should -Be "footest1" + $var1.Value|Should -Be "bar" + $var1.Options|Should -Be "None" + $var1.Description|Should -Be "" } } Describe "Set-Variable" -Tags "CI" { It "Should create a new variable with no parameters" { - { Set-Variable testVar } | Should Not Throw + { Set-Variable testVar } | Should -Not -Throw } It "Should assign a value to a variable it has to create" { Set-Variable -Name testVar -Value 4 - Get-Variable testVar -ValueOnly | Should Be 4 + Get-Variable testVar -ValueOnly | Should -Be 4 } It "Should change the value of an already existing variable" { $testVar=1 - $testVar | Should Not Be 2 + $testVar | Should -Not -Be 2 Set-Variable testVar -Value 2 - $testVar | Should Be 2 + $testVar | Should -Be 2 } It "Should be able to be called with the set alias" { set testVar -Value 1 - $testVar | Should Be 1 + $testVar | Should -Be 1 } It "Should be able to be called with the sv alias" { sv testVar -Value 2 - $testVar | Should Be 2 + $testVar | Should -Be 2 } It "Should be able to set variable name using the Name parameter" { Set-Variable -Name testVar -Value 1 - $testVar | Should Be 1 + $testVar | Should -Be 1 } It "Should be able to set the value of a variable by piped input" { @@ -207,7 +207,7 @@ Describe "Set-Variable" -Tags "CI" { $testValue | Set-Variable -Name testVar - $testVar | Should Be $testValue + $testVar | Should -Be $testValue } It "Should be able to pipe object properties to output using the PassThru switch" { @@ -216,30 +216,30 @@ Describe "Set-Variable" -Tags "CI" { $output = $in | Format-List -Property Description | Out-String # This will cause errors running these tests in Windows - $output.Trim() | Should Be "Description : test description" + $output.Trim() | Should -Be "Description : test description" } It "Should be able to set the value using the value switch" { Set-Variable -Name testVar -Value 4 - $testVar | Should Be 4 + $testVar | Should -Be 4 Set-Variable -Name testVar -Value "test" - $testVar | Should Be "test" + $testVar | Should -Be "test" } Context "Scope Tests" { It "Should be able to set a global scope variable using the global switch" { - { Set-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw + { Set-Variable globalVar -Value 1 -Scope global -Force } | Should -Not -Throw } It "Should be able to set a global variable using the script scope switch" { - { Set-Variable globalVar -Value 1 -Scope script -Force } | Should Not Throw + { Set-Variable globalVar -Value 1 -Scope script -Force } | Should -Not -Throw } It "Should be able to set an item locally using the local switch" { - { Set-Variable globalVar -Value 1 -Scope local -Force } | Should Not Throw + { Set-Variable globalVar -Value 1 -Scope local -Force } | Should -Not -Throw } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 index 875454e7fb2..0a5e19a020a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 @@ -3,22 +3,22 @@ Describe "Sort-Object" -Tags "CI" { It "should be able to sort object in ascending with using Property switch" { - { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length } | Should Not Throw + { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length } | Should -Not -Throw $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -First 1).Length $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -Last 1).Length - $firstLen -lt $lastLen | Should be $true + $firstLen -lt $lastLen | Should -be $true } It "should be able to sort object in descending with using Descending switch" { - { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending } | Should Not Throw + { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending } | Should -Not -Throw $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -First 1).Length $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -Last 1).Length - $firstLen -gt $lastLen | Should be $true + $firstLen -gt $lastLen | Should -be $true } } @@ -31,20 +31,20 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3,$employee4) $results = $employees | Sort-Object -Property YearsInMS - $results[0].FirstName | Should Be "Minus" - $results[0].LastName | Should Be "Two" - $results[0].YearsInMS | Should Be -2 + $results[0].FirstName | Should -Be "Minus" + $results[0].LastName | Should -Be "Two" + $results[0].YearsInMS | Should -Be -2 - $results[1].FirstName | Should Be "Eight" - $results[1].YearsInMS | Should BeNullOrEmpty + $results[1].FirstName | Should -Be "Eight" + $results[1].YearsInMS | Should -BeNullOrEmpty - $results[2].FirstName | Should Be "One" - $results[2].LastName | Should Be "One" - $results[2].YearsInMS | Should Be 1 + $results[2].FirstName | Should -Be "One" + $results[2].LastName | Should -Be "One" + $results[2].YearsInMS | Should -Be 1 - $results[3].FirstName | Should Be "Eight" - $results[3].LastName | Should Be "Eight" - $results[3].YearsInMS | Should Be 8 + $results[3].FirstName | Should -Be "Eight" + $results[3].LastName | Should -Be "Eight" + $results[3].YearsInMS | Should -Be 8 } It "Sort-Object with Non Conflicting Order Entry Keys should work"{ @@ -55,9 +55,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $ht = @{"e"="YearsInMS"; "descending"=$false; "ascending"=$true} $results = $employees | Sort-Object -Property $ht -Descending - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[1] + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[1] } It "Sort-Object with Conflicting Order Entry Keys should work"{ @@ -68,9 +68,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $ht = @{"e"="YearsInMS"; "descending"=$false; "ascending"=$false} $results = $employees | Sort-Object -Property $ht -Descending - $results[0] | Should Be $employees[1] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[2] + $results[0] | Should -Be $employees[1] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[2] } It "Sort-Object with One Order Entry Key should work"{ @@ -81,9 +81,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $ht = @{"e"="YearsInMS"; "descending"=$false} $results = $employees | Sort-Object -Property $ht -Descending - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[1] + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[1] } It "Sort-Object with HistoryInfo object should work"{ @@ -97,9 +97,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $results = $historyInfos | Sort-Object - $results[0] | Should Be $historyInfos[0] - $results[1] | Should Be $historyInfos[1] - $results[2] | Should Be $historyInfos[2] + $results[0] | Should -Be $historyInfos[0] + $results[1] | Should -Be $historyInfos[1] + $results[2] | Should -Be $historyInfos[2] } It "Sort-Object with Non Existing And Null Script Property should work"{ @@ -111,10 +111,10 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $a = new-object microsoft.powershell.commands.newobjectcommand $a.TypeName = 'atype' $results = $n, $d, $b, 'b', $a | Sort-Object -proper {$_.TypeName} - $results.Count | Should Be 5 - $results[2] | Should Be $a - $results[3] | Should Be $b - $results[4] | Should Be $d + $results.Count | Should -Be 5 + $results[2] | Should -Be $a + $results[3] | Should -Be $b + $results[4] | Should -Be $d #results[0] and [1] can be any order } @@ -128,12 +128,12 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $a = new-object microsoft.powershell.commands.newobjectcommand $a.TypeName = 'atype' $results = $n, $d, $b, 'b', $a | Sort-Object -prop TypeName - $results.Count | Should Be 5 - $results[0] | Should Be $n - $results[1] | Should Be $a - $results[2] | Should Be $b - $results[3] | Should Be $d - $results[4] | Should Be 'b' + $results.Count | Should -Be 5 + $results[0] | Should -Be $n + $results[1] | Should -Be $a + $results[2] | Should -Be $b + $results[3] | Should -Be $d + $results[4] | Should -Be 'b' } It "Sort-Object with Non Case-Sensitive Unique should work"{ @@ -143,9 +143,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3) $results = $employees | Sort-Object -Property "LastName" -Descending -Unique - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[1] - $results[2] | Should BeNullOrEmpty + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[1] + $results[2] | Should -BeNullOrEmpty } It "Sort-Object with Case-Sensitive Unique should work"{ @@ -155,9 +155,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3) $results = $employees | Sort-Object -Property "LastName","FirstName" -Descending -Unique -CaseSensitive - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[1] + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[1] } It "Sort-Object with Two Order Entry Keys should work"{ @@ -169,9 +169,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $ht2 = @{"expression"="FirstName"; "ascending"=$true} $results = $employees | Sort-Object -Property @($ht1,$ht2) -Descending - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[1] - $results[2] | Should Be $employees[0] + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[1] + $results[2] | Should -Be $employees[0] } It "Sort-Object with -Descending:$false and Two Order Entry Keys should work"{ @@ -181,9 +181,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3) $results = $employees | Sort-Object -Property "LastName","FirstName" -Descending:$false - $results[0] | Should Be $employees[1] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[2] + $results[0] | Should -Be $employees[1] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[2] } It "Sort-Object with -Descending and Two Order Entry Keys should work"{ @@ -193,9 +193,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3) $results = $employees | Sort-Object -Property "LastName","FirstName" -Descending - $results[0] | Should Be $employees[2] - $results[1] | Should Be $employees[0] - $results[2] | Should Be $employees[1] + $results[0] | Should -Be $employees[2] + $results[1] | Should -Be $employees[0] + $results[2] | Should -Be $employees[1] } It "Sort-Object with Two Order Entry Keys with asc=true should work"{ @@ -207,9 +207,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $ht2 = @{"e"="LastName";} $results = $employees | Sort-Object -Property @($ht1,$ht2) -Descending - $results[0] | Should Be $employees[1] - $results[1] | Should Be $employees[2] - $results[2] | Should Be $employees[0] + $results[0] | Should -Be $employees[1] + $results[1] | Should -Be $employees[2] + $results[2] | Should -Be $employees[0] } It "Sort-Object with Descending No Property should work"{ @@ -219,9 +219,9 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3) $results = $employees | Sort-Object -Descending - $results[0] | Should Be 3 - $results[1] | Should Be 2 - $results[2] | Should Be 1 + $results[0] | Should -Be 3 + $results[1] | Should -Be 2 + $results[2] | Should -Be 1 } } @@ -234,9 +234,9 @@ Describe 'Sort-Object Top and Bottom Unit Tests' -Tags 'CI' { if ($nSortEntry -is [System.Array]) { # Arrays are compared using reference equality to ensure that the original array was # moved to the correct position in both sorts; value equality doesn't verify this - [object]::ReferenceEquals($nSortEntry, $fullSortEntry) | Should Be $true + [object]::ReferenceEquals($nSortEntry, $fullSortEntry) | Should -Be $true } else { - $nSortEntry | Should Be $fullSortEntry + $nSortEntry | Should -Be $fullSortEntry } } @@ -251,8 +251,8 @@ Describe 'Sort-Object Top and Bottom Unit Tests' -Tags 'CI' { $nSortResults = $unsortedData | Sort-Object @baseSortParameters @nSortParameters # Verify the counts when not doing a -Unique sort if (-not $baseSortParameters.ContainsKey('Unique')) { - $nSortResults.Count | Should Be $(if ($nSortParameters[$nSortType] -gt $unsortedData.Length) {$unsortedData.Length} else {$nSortParameters[$nSortType]}) - $fullSortResults.Count | Should Be $unsortedData.Length + $nSortResults.Count | Should -Be $(if ($nSortParameters[$nSortType] -gt $unsortedData.Length) {$unsortedData.Length} else {$nSortParameters[$nSortType]}) + $fullSortResults.Count | Should -Be $unsortedData.Length } # Compare the n-sort result entries with their corresponding full sort result entries if ($nSortType -eq 'Top') { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 index e535f973cd3..f427e7f923c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 @@ -10,24 +10,24 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" { $watch = [System.Diagnostics.Stopwatch]::StartNew() Start-Sleep -Seconds 1 $watch.Stop() - $watch.ElapsedMilliseconds | Should BeGreaterThan 950 - $watch.ElapsedMilliseconds | Should BeLessThan 1100 + $watch.ElapsedMilliseconds | Should -BeGreaterThan 950 + $watch.ElapsedMilliseconds | Should -BeLessThan 1100 } It "Should work properly when sleeping with Milliseconds" { $watch = [System.Diagnostics.Stopwatch]::StartNew() Start-Sleep -Milliseconds 1000 $watch.Stop() - $watch.ElapsedMilliseconds | Should BeGreaterThan 950 - $watch.ElapsedMilliseconds | Should BeLessThan 1100 + $watch.ElapsedMilliseconds | Should -BeGreaterThan 950 + $watch.ElapsedMilliseconds | Should -BeLessThan 1100 } It "Should work properly when sleeping with ms alias" { $watch = [System.Diagnostics.Stopwatch]::StartNew() Start-Sleep -ms 1000 $watch.Stop() - $watch.ElapsedMilliseconds | Should BeGreaterThan 950 - $watch.ElapsedMilliseconds | Should BeLessThan 1100 + $watch.ElapsedMilliseconds | Should -BeGreaterThan 950 + $watch.ElapsedMilliseconds | Should -BeLessThan 1100 } } @@ -36,7 +36,7 @@ Describe "Start-Sleep" -Tags "CI" { Context "Validate Start-Sleep works properly" { It "Should only sleep for at least 1 second" { $result = Measure-Command { Start-Sleep -s 1 } - $result.TotalSeconds | Should BeGreaterThan 0.25 + $result.TotalSeconds | Should -BeGreaterThan 0.25 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 index afa306f48a7..2aad275703f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 @@ -9,14 +9,14 @@ Describe "Tee-Object" -Tags "CI" { It "Should return the output to the screen and to the variable" { $teefile = $testfile echo teeobjecttest1 | Tee-Object -variable teeresults - $teeresults | Should Be "teeobjecttest1" + $teeresults | Should -Be "teeobjecttest1" Remove-Item $teefile -ErrorAction SilentlyContinue } It "Should tee the output to a file" { $teefile = $testfile echo teeobjecttest3 | Tee-Object $teefile - Get-Content $teefile | Should Be "teeobjecttest3" + Get-Content $teefile | Should -Be "teeobjecttest3" Remove-Item $teefile -ErrorAction SilentlyContinue } } @@ -29,31 +29,31 @@ Describe "Tee-Object DRT Unit Tests" -Tags "CI" { It "Positive File Test" { $expected = "1", "2", "3" $results = $expected | Tee-Object -FilePath $tempFile - $results.Length | Should be 3 - $results | Should Be $expected + $results.Length | Should -be 3 + $results | Should -Be $expected $content = Get-Content $tempFile - $content | Should Be $expected + $content | Should -Be $expected } It "Positive File Test with Path parameter alias" { $expected = "1", "2", "3" $results = $expected | Tee-Object -Path $tempFile - $results.Length | Should be 3 - $results | Should Be $expected + $results.Length | Should -be 3 + $results | Should -Be $expected $content = Get-Content $tempFile - $content | Should Be $expected + $content | Should -Be $expected } It "Positive Variable Test" { $expected = "1", "2", "3" $varName = "teeObjectTestVar" $results = $expected | Tee-Object -Variable $varName - $results.Length | Should be 3 - $results | Should Be $expected + $results.Length | Should -be 3 + $results | Should -Be $expected $results = Get-Variable -Name $varName -ValueOnly - $results.Length | Should be 3 - $results | Should Be $expected + $results.Length | Should -be 3 + $results | Should -Be $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 index cf364e7a1a8..91ff1eefd95 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 @@ -24,14 +24,14 @@ Describe "Trace-Command" -tags "CI" { Trace-Command -Name * -Expression {echo Foo} -ListenerOption LogicalOperationStack -FilePath $logfile $log = Get-Content $logfile | Where-Object {$_ -like "*LogicalOperationStack=$keyword*"} - $log.Count | Should BeGreaterThan 0 + $log.Count | Should -BeGreaterThan 0 } # GetStackTrace is not in .NET Core It "Callstack works" -Skip:$IsCoreCLR { Trace-Command -Name * -Expression {echo Foo} -ListenerOption Callstack -FilePath $logfile $log = Get-Content $logfile | Where-Object {$_ -like "*Callstack= * System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)*"} - $log.Count | Should BeGreaterThan 0 + $log.Count | Should -BeGreaterThan 0 } It "Datetime works" { @@ -48,7 +48,7 @@ Describe "Trace-Command" -tags "CI" { $actualGap = $expectedDate - $_; } - $allowedGap | Should BeGreaterThan $actualGap + $allowedGap | Should -BeGreaterThan $actualGap } } @@ -56,7 +56,7 @@ Describe "Trace-Command" -tags "CI" { Trace-Command -Name * -Expression {echo Foo} -ListenerOption None -FilePath $actualLogfile Trace-Command -name * -Expression {echo Foo} -FilePath $logfile - Compare-Object (Get-Content $actualLogfile) (Get-Content $logfile) | Should BeNullOrEmpty + Compare-Object (Get-Content $actualLogfile) (Get-Content $logfile) | Should -BeNullOrEmpty } It "ThreadID works" { @@ -64,7 +64,7 @@ Describe "Trace-Command" -tags "CI" { $log = Get-Content $logfile | Where-Object {$_ -like "*ThreadID=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} - $results | ForEach-Object { $_ | Should Be ([threading.thread]::CurrentThread.ManagedThreadId) } + $results | ForEach-Object { $_ | Should -Be ([threading.thread]::CurrentThread.ManagedThreadId) } } It "Timestamp creates logs in ascending order" { @@ -72,7 +72,7 @@ Describe "Trace-Command" -tags "CI" { $log = Get-Content $logfile | Where-Object {$_ -like "*Timestamp=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} $sortedResults = $results | Sort-Object - $sortedResults | Should Be $results + $sortedResults | Should -Be $results } It "ProcessId logs current process Id" { @@ -80,7 +80,7 @@ Describe "Trace-Command" -tags "CI" { $log = Get-Content $logfile | Where-Object {$_ -like "*ProcessID=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} - $results | ForEach-Object { $_ | Should Be $pid } + $results | ForEach-Object { $_ | Should -Be $pid } } } @@ -101,7 +101,7 @@ Describe "Trace-Command" -tags "CI" { It "Set-TraceSource to file and RemoveFileListener wildcard" { $null = Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -PassThru Set-TraceSource -Name "ParameterBinding" -RemoveFileListener * - Get-Content $filePath -Raw | Should Match 'ParameterBinding Information' + Get-Content $filePath -Raw | Should -Match 'ParameterBinding Information' } It "Trace-Command -Command with error" { @@ -116,18 +116,18 @@ Describe "Trace-Command" -tags "CI" { $null = New-Item $filePath -Force Set-ItemProperty $filePath -name IsReadOnly -value $true Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -FilePath $filePath -Force - Get-Content $filePath -Raw | Should Match 'ParameterBinding Information' + Get-Content $filePath -Raw | Should -Match 'ParameterBinding Information' } It "Trace-Command using Path parameter alias" { $null = New-Item $filePath -Force Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -Path $filePath -Force - Get-Content $filePath -Raw | Should Match 'ParameterBinding Information' + Get-Content $filePath -Raw | Should -Match 'ParameterBinding Information' } It "Trace-Command contains wildcard characters" { $a = Trace-Command -Name ParameterB* -Command 'get-alias' - $a.count | Should BeGreaterThan 0 + $a.count | Should -BeGreaterThan 0 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 index 670773072ce..6b4eb220dae 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 @@ -48,15 +48,15 @@ Describe "Unblock-File" -Tags "CI" { It "With '-Path': file exist" { Unblock-File -Path $testfilepath - Test-UnblockFile | Should Be $true + Test-UnblockFile | Should -Be $true # If a file is not blocked we silently return without an error. - { Unblock-File -Path $testfilepath -ErrorAction Stop } | Should Not Throw + { Unblock-File -Path $testfilepath -ErrorAction Stop } | Should -Not -Throw } It "With '-LiteralPath': file exist" { Unblock-File -LiteralPath $testfilepath - Test-UnblockFile | Should Be $true + Test-UnblockFile | Should -Be $true } It "Write an error if a file is read only" { @@ -70,7 +70,7 @@ Describe "Unblock-File" -Tags "CI" { Set-ItemProperty -Path $TestFile -Name IsReadOnly -Value $True $TestFileCreated = Get-ChildItem $TestFile - $TestFileCreated.IsReadOnly | Should Be $true + $TestFileCreated.IsReadOnly | Should -Be $true { Unblock-File -LiteralPath $TestFile -ErrorAction Stop } | ShouldBeErrorId "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.UnblockFileCommand" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unimplemented-Cmdlet.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unimplemented-Cmdlet.Tests.ps1 index e2af8a3d85b..ea19c7d4130 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unimplemented-Cmdlet.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unimplemented-Cmdlet.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Unimplemented Utility Cmdlet Tests" -Tags "CI" { foreach ($Command in $Commands) { It "$Command should only be available on Windows" { - [bool](Get-Command $Command -ErrorAction SilentlyContinue) | Should Be $IsWindows + [bool](Get-Command $Command -ErrorAction SilentlyContinue) | Should -Be $IsWindows } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 index 8ceba23cfd4..caf82ac0ef3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 @@ -17,14 +17,14 @@ Describe "Update-FormatData" -Tags "CI" { Context "Validate Update-FormatData update correctly" { It "Should not throw upon reloading previous formatting file" { - { Update-FormatData } | Should Not throw + { Update-FormatData } | Should -Not -throw } It "Should validly load formatting data" { Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path $path $null = $ps.AddScript("Update-FormatData -prependPath $path") $ps.Invoke() - $ps.HadErrors | Should be $false + $ps.HadErrors | Should -be $false } } } @@ -55,8 +55,8 @@ Describe "Update-FormatData basic functionality" -Tags "CI" { It "Update-FormatData with WhatIf should work"{ - { Update-FormatData -Append $testfile -WhatIf } | Should Not Throw - { Update-FormatData -Prepend $testfile -WhatIf } | Should Not Throw + { Update-FormatData -Append $testfile -WhatIf } | Should -Not -Throw + { Update-FormatData -Prepend $testfile -WhatIf } | Should -Not -Throw } It "Update with invalid format xml should fail" -Pending { @@ -96,7 +96,7 @@ Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { $null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath") $ps.Streams.Error.Clear() $ps.Invoke() - $ps.Streams.Error | Should BeNullOrEmpty + $ps.Streams.Error | Should -BeNullOrEmpty } It "Resources in CorePS syntax should be loaded successfully" { @@ -105,7 +105,7 @@ Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { $null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath") $ps.Streams.Error.Clear() $ps.Invoke() - $ps.Streams.Error | Should BeNullOrEmpty + $ps.Streams.Error | Should -BeNullOrEmpty } It "Verify assembly path in error message when resource is Not found" { $format = Get-Content -Path $templatePath -Raw @@ -115,8 +115,8 @@ Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { $ps.Invoke() $sma = [appdomain]::CurrentDomain.GetAssemblies() | ? { if ($_.Location) {$_.Location.EndsWith("System.Management.Automation.dll")}} $smaLocation = $sma.Location - $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } - $ps.Streams.Error | %{ $_.FullyQualifiedErrorId | Should Match 'FormatXmlUpdateException' } + $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should -be $true } + $ps.Streams.Error | %{ $_.FullyQualifiedErrorId | Should -Match 'FormatXmlUpdateException' } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index 3e8f843c7d7..22be7858026 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -51,8 +51,8 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid TypesXml should throw Exception" { $null = $ps.AddScript("Update-TypeData -PrependPath $testfile") $ps.Invoke() - $ps.HadErrors | Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorID | Should be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors | Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorID | Should -be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid File Extension should throw Exception"{ @@ -60,8 +60,8 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $xmlContent>$invalidFileExtensionFile $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") $ps.Invoke() - $ps.HadErrors | Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should be "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors | Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Dynamic Type NoteProperty with Force should work"{ @@ -69,19 +69,19 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke() | should be 2 + $ps.Invoke() | should -be 2 $ps.Commands.Clear() $null = $ps.AddScript("Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value 'test' -TypeName System.String -Force") $ps.Invoke() $ps.commands.clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke()| Should Be "test" + $ps.Invoke()| Should -Be "test" $ps.commands.clear() $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value $null -TypeName System.String -Force') $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke()| Should BeNullOrEmpty + $ps.Invoke()| Should -BeNullOrEmpty } It "Update-TypeData with Valid Dynamic Type AliasProperty with Force should work"{ @@ -90,12 +90,12 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should Be "Int32" + $ps.Invoke()| Should -Be "Int32" # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias") - $ps.Invoke()| Should Be 6 + $ps.Invoke()| Should -Be 6 # setup $ps.Commands.Clear() @@ -105,12 +105,12 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should Be "String" + $ps.Invoke()| Should -Be "String" # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias") - $ps.Invoke()| Should Be 6 + $ps.Invoke()| Should -Be 6 } It "Update-TypeData with Valid Dynamic Type ScriptMethod with Force should work"{ @@ -120,7 +120,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $null = $ps.AddScript('"string".TestScriptMethod()') - $ps.Invoke()| Should Be "script method" + $ps.Invoke()| Should -Be "script method" $ps.Commands.Clear() $script2="new script method" $null = $ps.AddScript("Update-TypeData -MemberType ScriptMethod -MemberName TestScriptMethod -Value {'$script2'} -TypeName System.String -Force") @@ -128,7 +128,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $null = $ps.AddScript('"string".TestScriptMethod()') - $ps.Invoke() | Should Be "new script method" + $ps.Invoke() | Should -Be "new script method" } It "Update-TypeData with Valid Dynamic Type Accept TypeData Object should work"{ @@ -143,102 +143,102 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { # tests $ps.Commands.Clear() - $ps.AddScript('$result.TestNote1').Invoke() | Should Be "Hello" + $ps.AddScript('$result.TestNote1').Invoke() | Should -Be "Hello" $ps.Commands.Clear() - $ps.AddScript('$result.TestNote').Invoke() | Should Be 2 + $ps.AddScript('$result.TestNote').Invoke() | Should -Be 2 } It "Update-TypeData with Invalid DynamicType Null Value For AliasProperty should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType AliasProperty -MemberName TestAlias -Value $null -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No MemberName should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -Value "Error" -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should be "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No Value should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with Empty TypeData should throw Exception"{ $null = $ps.AddScript("Update-TypeData -TypeName System.String") $ps.Invoke() - $ps.HadErrors |Should be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should be "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -be $true + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Standard Members Serialization Method String should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod string -StringSerializationSource Length -TargetTypeForDeserialization string -TypeName System.String') $ps.Invoke() $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should Be "String" + $ps.Invoke()| Should -Be "String" $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.StringSerializationSource') - $ps.Invoke()| Should Be 6 + $ps.Invoke()| Should -Be 6 $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should Be "string" + $ps.Invoke()| Should -Be "string" } It "Update-TypeData with Valid Standard Members Serialization Method SpecificProperties should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod SpecificProperties -StringSerializationSource Length -PropertySerializationSet Length -InheritPropertySerializationSet $true -SerializationDepth 2 -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke() | Should Be "SpecificProperties" + $ps.Invoke() | Should -Be "SpecificProperties" $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.StringSerializationSource') - $ps.Invoke() | Should Be 6 + $ps.Invoke() | Should -Be 6 $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke() | Should Be 2 + $ps.Invoke() | Should -Be 2 $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.InheritPropertySerializationSet') - $ps.Invoke() | Should Be "True" + $ps.Invoke() | Should -Be "True" } It "Update-TypeData with Valid Standard Members Serialization Method AllPublicProperties should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod AllPublicProperties -StringSerializationSource Length -SerializationDepth 2 -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should Be "AllPublicProperties" + $ps.Invoke()| Should -Be "AllPublicProperties" $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.StringSerializationSource') - $ps.Invoke()| Should Be 6 + $ps.Invoke()| Should -Be 6 $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should Be 2 + $ps.Invoke()| Should -Be 2 } It "Update-TypeData with Valid ISS UpdateType Command Test With DynamicType Set should work"{ $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName "TestNote" -Value "test the note" -SerializationMethod SpecificProperties -SerializationDepth 5 -PropertySerializationSet Length -DefaultDisplayPropertySet Length -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should Be "test the note" + $ps.Invoke()| Should -Be "test the note" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should Be "SpecificProperties" + $ps.Invoke()| Should -Be "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should Be 5 + $ps.Invoke()| Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should Be "Length" + $ps.Invoke()| Should -Be "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should Be "Length" + $ps.Invoke()| Should -Be "Length" $ps.Commands.Clear();$null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value "test the note again" -TargetTypeForDeserialization string -Force -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should Be "test the note again" + $ps.Invoke()| Should -Be "test the note again" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should Be "SpecificProperties" + $ps.Invoke()| Should -Be "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should Be 5 + $ps.Invoke()| Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should Be "Length" + $ps.Invoke()| Should -Be "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should Be "Length" + $ps.Invoke()| Should -Be "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should Be "string" + $ps.Invoke()| Should -Be "string" } It "Update-TypeData with Valid ISS UpdateType Command Test With StrongType Set should work"{ @@ -254,14 +254,14 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.AddStatement() $ps.AddScript('Update-TypeData -TypeName System.Array -SerializationMethod AllPublicProperties -SerializationDepth 2 -StringSerializationSource Length -TargetTypeForDeserialization string') $ps.Invoke() - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestNote').Invoke() | Should Be "TestNote" - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestAlias').Invoke() | Should Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptMethod()').Invoke() | Should Be "script method" - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptProperty').Invoke() | Should Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationMethod').Invoke() | Should Be "AllPublicProperties" - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationDepth').Invoke() | Should Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.StringSerializationSource').Invoke() | Should Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.TargetTypeForDeserialization').Invoke() | Should Be "string" + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestNote').Invoke() | Should -Be "TestNote" + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestAlias').Invoke() | Should -Be 2 + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptMethod()').Invoke() | Should -Be "script method" + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptProperty').Invoke() | Should -Be 2 + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationMethod').Invoke() | Should -Be "AllPublicProperties" + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationDepth').Invoke() | Should -Be 2 + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.StringSerializationSource').Invoke() | Should -Be 2 + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.TargetTypeForDeserialization').Invoke() | Should -Be "string" } # this looks identical to the test directly above @@ -274,14 +274,14 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $script2={$this.Length} Update-TypeData -TypeName System.Object[] -MemberType ScriptProperty -MemberName TestScriptProperty -Value $script2 Update-TypeData -TypeName System.Object[] -SerializationMethod AllPublicProperties -SerializationDepth 2 -StringSerializationSource Length -TargetTypeForDeserialization string - (1, 3).TestNote | Should Be "TestNote" - (1, 3).TestAlias | Should Be 2 - (1, 3).TestScriptMethod() | Should Be "script method" - (1, 3).TestScriptProperty | Should Be 2 - (1, 3).PSStandardMembers.SerializationMethod | Should Be "AllPublicProperties" - (1, 3).PSStandardMembers.SerializationDepth | Should Be 2 - (1, 3).PSStandardMembers.StringSerializationSource | Should Be 2 - (1, 3).PSStandardMembers.TargetTypeForDeserialization | Should Be "string" + (1, 3).TestNote | Should -Be "TestNote" + (1, 3).TestAlias | Should -Be 2 + (1, 3).TestScriptMethod() | Should -Be "script method" + (1, 3).TestScriptProperty | Should -Be 2 + (1, 3).PSStandardMembers.SerializationMethod | Should -Be "AllPublicProperties" + (1, 3).PSStandardMembers.SerializationDepth | Should -Be 2 + (1, 3).PSStandardMembers.StringSerializationSource | Should -Be 2 + (1, 3).PSStandardMembers.TargetTypeForDeserialization | Should -Be "string" } finally { @@ -312,9 +312,9 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $ps.AddScript('$a=1..3').Invoke() $ps.Commands.Clear() - $ps.AddScript('$a.Yada').Invoke() | Should Be 3 + $ps.AddScript('$a.Yada').Invoke() | Should -Be 3 $ps.AddScript("Remove-TypeData -Path $testfile").Invoke() - $ps.HadErrors|Should be $false + $ps.HadErrors|Should -be $false } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Wait-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Wait-Event.Tests.ps1 index a0bddee2daf..72b6952ab19 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Wait-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Wait-Event.Tests.ps1 @@ -10,8 +10,8 @@ $stopwatch = [System.Diagnostics.Stopwatch]::startNew() # raised because it is fake Wait-Event -Timeout 1 -SourceIdentifier "FakeEvent" $stopwatch.Stop() -$stopwatch.ElapsedMilliseconds | Should BeGreaterThan 500 -$stopwatch.ElapsedMilliseconds | Should BeLessThan 1500 +$stopwatch.ElapsedMilliseconds | Should -BeGreaterThan 500 +$stopwatch.ElapsedMilliseconds | Should -BeLessThan 1500 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 350cc1f07cd..7ebc639e813 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # This is a Pester test suite which validate the Web cmdlets. diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Debug.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Debug.Tests.ps1 index 7675ef8d2b5..1102b9f2e28 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Debug.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Debug.Tests.ps1 @@ -10,7 +10,7 @@ Describe "Write-Debug tests" -Tags "CI" { $DebugPreference = "Continue" try { $out = Write-Debug $text 5>&1 - $out | Should BeExactly $text + $out | Should -BeExactly $text } finally { $DebugPreference = $origDebugPref diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 index 21a1466d5c2..d6e2740044b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 @@ -3,86 +3,86 @@ Describe "Write-Error Tests" -Tags "CI" { It "Should be works with command: write-error myerrortext" { $e = Write-Error myerrortext 2>&1 - $e | Should BeOfType 'System.Management.Automation.ErrorRecord' + $e | Should -BeOfType 'System.Management.Automation.ErrorRecord' #Exception verification - $e.Exception | Should BeOfType 'Microsoft.PowerShell.Commands.WriteErrorException' - $e.Exception.Message | Should Be 'myerrortext' - $e.Exception.Data.Count | Should Be 0 - $e.Exception.InnerException | Should BeNullOrEmpty + $e.Exception | Should -BeOfType 'Microsoft.PowerShell.Commands.WriteErrorException' + $e.Exception.Message | Should -Be 'myerrortext' + $e.Exception.Data.Count | Should -Be 0 + $e.Exception.InnerException | Should -BeNullOrEmpty #ErrorCategoryInfo verification - $e.CategoryInfo | Should Not BeNullOrEmpty - $e.CategoryInfo.Category | Should Be 'NotSpecified' - $e.CategoryInfo.Activity | Should Be 'Write-Error' - $e.CategoryInfo.Reason | Should Be 'WriteErrorException' - $e.CategoryInfo.TargetName | Should BeNullOrEmpty - $e.CategoryInfo.TargetType | Should BeNullOrEmpty - $e.CategoryInfo.GetMessage() | Should Be 'NotSpecified: (:) [Write-Error], WriteErrorException' + $e.CategoryInfo | Should -Not -BeNullOrEmpty + $e.CategoryInfo.Category | Should -Be 'NotSpecified' + $e.CategoryInfo.Activity | Should -Be 'Write-Error' + $e.CategoryInfo.Reason | Should -Be 'WriteErrorException' + $e.CategoryInfo.TargetName | Should -BeNullOrEmpty + $e.CategoryInfo.TargetType | Should -BeNullOrEmpty + $e.CategoryInfo.GetMessage() | Should -Be 'NotSpecified: (:) [Write-Error], WriteErrorException' #ErrorDetails verification - $e.ErrorDetails | Should BeNullOrEmpty + $e.ErrorDetails | Should -BeNullOrEmpty #FullyQualifiedErrorId verification - $e.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException' + $e.FullyQualifiedErrorId | Should -Be 'Microsoft.PowerShell.Commands.WriteErrorException' #InvocationInfo verification - $e.InvocationInfo | Should Not BeNullOrEmpty - $e.InvocationInfo.MyCommand.Name | Should BeNullOrEmpty + $e.InvocationInfo | Should -Not -BeNullOrEmpty + $e.InvocationInfo.MyCommand.Name | Should -BeNullOrEmpty } It "Should be works with all parameters" { $exception = New-Object -TypeName System.ArgumentNullException -ArgumentList paramname $e = Write-Error -Message myerrortext -Exception $exception -ErrorId myerrorid -Category syntaxerror -TargetObject TargetObject -CategoryActivity myactivity -CategoryReason myreason -CategoryTargetName mytargetname -CategoryTargetType mytargettype -RecommendedAction myrecommendedaction 2>&1 - $e | Should Not BeNullOrEmpty - $e | Should BeOfType 'System.Management.Automation.ErrorRecord' + $e | Should -Not -BeNullOrEmpty + $e | Should -BeOfType 'System.Management.Automation.ErrorRecord' #Exception verification - $e.Exception | Should BeOfType 'System.ArgumentNullException' - $e.Exception.ParamName | Should Be 'paramname' - $e.Exception.Data.Count | Should Be 0 - $e.Exception.InnerException | Should BeNullOrEmpty + $e.Exception | Should -BeOfType 'System.ArgumentNullException' + $e.Exception.ParamName | Should -Be 'paramname' + $e.Exception.Data.Count | Should -Be 0 + $e.Exception.InnerException | Should -BeNullOrEmpty #TargetObject verification - $e.TargetObject | Should Be 'TargetObject' + $e.TargetObject | Should -Be 'TargetObject' #FullyQualifiedErrorId verification - $e.FullyQualifiedErrorId | Should Be 'myerrorid' + $e.FullyQualifiedErrorId | Should -Be 'myerrorid' #ErrorCategoryInfo verification - $e.CategoryInfo | Should Not BeNullOrEmpty - $e.CategoryInfo.Category | Should Be 'SyntaxError' - $e.CategoryInfo.Activity | Should Be 'myactivity' - $e.CategoryInfo.Reason | Should Be 'myreason' - $e.CategoryInfo.TargetName | Should Be 'mytargetname' - $e.CategoryInfo.TargetType | Should Be 'mytargettype' - $e.CategoryInfo.GetMessage() | Should Be 'SyntaxError: (mytargetname:mytargettype) [myactivity], myreason' + $e.CategoryInfo | Should -Not -BeNullOrEmpty + $e.CategoryInfo.Category | Should -Be 'SyntaxError' + $e.CategoryInfo.Activity | Should -Be 'myactivity' + $e.CategoryInfo.Reason | Should -Be 'myreason' + $e.CategoryInfo.TargetName | Should -Be 'mytargetname' + $e.CategoryInfo.TargetType | Should -Be 'mytargettype' + $e.CategoryInfo.GetMessage() | Should -Be 'SyntaxError: (mytargetname:mytargettype) [myactivity], myreason' #ErrorDetails verification - $e.ErrorDetails | Should Not BeNullOrEmpty - $e.ErrorDetails.Message | Should Be 'myerrortext' - $e.ErrorDetails.RecommendedAction | Should Be 'myrecommendedaction' + $e.ErrorDetails | Should -Not -BeNullOrEmpty + $e.ErrorDetails.Message | Should -Be 'myerrortext' + $e.ErrorDetails.RecommendedAction | Should -Be 'myrecommendedaction' #InvocationInfo verification - $e.InvocationInfo | Should Not BeNullOrEmpty - $e.InvocationInfo.MyCommand.Name | Should BeNullOrEmpty + $e.InvocationInfo | Should -Not -BeNullOrEmpty + $e.InvocationInfo.MyCommand.Name | Should -BeNullOrEmpty } It "Should be works with all parameters" { $e = write-error -Activity fooAct -Reason fooReason -TargetName fooTargetName -TargetType fooTargetType -Message fooMessage 2>&1 - $e.CategoryInfo.Activity | Should Be 'fooAct' - $e.CategoryInfo.Reason | Should Be 'fooReason' - $e.CategoryInfo.TargetName | Should Be 'fooTargetName' - $e.CategoryInfo.TargetType | Should Be 'fooTargetType' - $e.CategoryInfo.GetMessage() | Should Be 'NotSpecified: (fooTargetName:fooTargetType) [fooAct], fooReason' + $e.CategoryInfo.Activity | Should -Be 'fooAct' + $e.CategoryInfo.Reason | Should -Be 'fooReason' + $e.CategoryInfo.TargetName | Should -Be 'fooTargetName' + $e.CategoryInfo.TargetType | Should -Be 'fooTargetType' + $e.CategoryInfo.GetMessage() | Should -Be 'NotSpecified: (fooTargetName:fooTargetType) [fooAct], fooReason' } It "Should be able to throw with -ErrorAction stop" { - { Write-Error "test throw" -ErrorAction Stop } | Should Throw + { Write-Error "test throw" -ErrorAction Stop } | Should -Throw } It "Should throw a non-terminating error" { - { Write-Error "test throw" -ErrorAction SilentlyContinue } | Should Not Throw + { Write-Error "test throw" -ErrorAction SilentlyContinue } | Should -Not -Throw } It "Should trip an exception using the exception switch" { @@ -98,7 +98,7 @@ Describe "Write-Error Tests" -Tags "CI" { } finally { - $var | Should Be 1 + $var | Should -Be 1 } } @@ -106,7 +106,7 @@ Describe "Write-Error Tests" -Tags "CI" { $theError = "Error: Too many input values." write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue - [string]$error[0]| Should Be $theError + [string]$error[0]| Should -Be $theError } It "ErrorRecord should not be truncated or have inserted newlines when redirected from another process" { @@ -116,7 +116,7 @@ Describe "Write-Error Tests" -Tags "CI" { } $pwsh = $pshome + "/pwsh" $result = & $pwsh -c Write-Error -Message $longtext 2>&1 - $result.Count | Should BeExactly 4 - $result[0] | Should Match $longtext + $result.Count | Should -BeExactly 4 + $result[0] | Should -Match $longtext } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 index c3fbf1afafc..c7742e9e593 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 @@ -17,10 +17,10 @@ Describe "Write-Host with default Console Host" -Tags "Slow","Feature" { [array]$result = & $powershell -noprofile -c $Command - $result.Count | Should Be $returnCount + $result.Count | Should -Be $returnCount foreach ($i in 0..($returnCount - 1)) { - $result[$i] | Should Be $returnValue[$i] + $result[$i] | Should -Be $returnValue[$i] } } } @@ -43,7 +43,7 @@ Describe "Write-Host with wrong colors" -Tags "CI" { Write-Host "No output from Write-Host" -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should Be 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } + catch { $_.FullyQualifiedErrorId | Should -Be 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } } } @@ -86,12 +86,12 @@ Describe "Write-Host with TestHostCS" -Tags "CI" { $result = $th.ui.Streams.ConsoleOutput - $result.Count | Should Be $returnCount - (Compare-Object $result $returnValue -SyncWindow 0).length | Should Be 0 + $result.Count | Should -Be $returnCount + (Compare-Object $result $returnValue -SyncWindow 0).length | Should -Be 0 $result = $th.ui.Streams.Information - $result.Count | Should Be $returnCount - (Compare-Object $result $returnInfo -SyncWindow 0).length | Should Be 0 + $result.Count | Should -Be $returnCount + (Compare-Object $result $returnInfo -SyncWindow 0).length | Should -Be 0 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 index cfe3e63910c..9fed5063426 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 @@ -4,22 +4,22 @@ Describe "Write-Output DRT Unit Tests" -Tags "CI" { It "Simple Write Object Test" { $objectWritten = 1, 2.2, @("John", "Smith", 10), "abc" $results = Write-Output $objectWritten - $results.Length | Should Be $objectWritten.Length + $results.Length | Should -Be $objectWritten.Length - $results[0] | Should Be $objectWritten[0] - $results[1] | Should Be $objectWritten[1] + $results[0] | Should -Be $objectWritten[0] + $results[1] | Should -Be $objectWritten[1] - $results[2] | Should Be $objectWritten[2] - $results[2] -is [System.Array] | Should Be $true + $results[2] | Should -Be $objectWritten[2] + $results[2] -is [System.Array] | Should -Be $true - $results[3] | Should Be $objectWritten[3] - $results[3] -is [System.String] | Should Be $true + $results[3] | Should -Be $objectWritten[3] + $results[3] -is [System.String] | Should -Be $true } It "Works with NoEnumerate switch" { $objectWritten = 1, 2.2, @("John", "Smith", 10), "abc" [string]$s = Write-Output $objectWritten -NoEnumerate 6>&1 - $s | Should be '1 2.2 System.Object[] abc' + $s | Should -be '1 2.2 System.Object[] abc' } } @@ -27,36 +27,36 @@ Describe "Write-Output" -Tags "CI" { $testString = $testString Context "Input Tests" { It "Should allow piped input" { - { $testString | Write-Output } | Should Not Throw + { $testString | Write-Output } | Should -Not -Throw } It "Should write output to the output stream when using piped input" { - $testString | Write-Output | Should Be $testString + $testString | Write-Output | Should -Be $testString } It "Should use inputobject switch" { - { Write-Output -InputObject $testString } | Should Not Throw + { Write-Output -InputObject $testString } | Should -Not -Throw } It "Should write output to the output stream when using inputobject switch" { - Write-Output -InputObject $testString | Should Be $testString + Write-Output -InputObject $testString | Should -Be $testString } It "Should be able to write to a variable" { Write-Output -InputObject $testString -OutVariable var - $var | Should Be $testString + $var | Should -Be $testString } } Context "Pipeline Command Tests" { It "Should send object to the next command in the pipeline" { - Write-Output -InputObject (1+1) | Should Be 2 + Write-Output -InputObject (1+1) | Should -Be 2 } It "Should have the same result between inputobject switch and piped input" { - Write-Output -InputObject (1+1) | Should Be 2 + Write-Output -InputObject (1+1) | Should -Be 2 - 1+1 | Write-Output | Should Be 2 + 1+1 | Write-Output | Should -Be 2 } } @@ -65,13 +65,13 @@ Describe "Write-Output" -Tags "CI" { It "Should see individual objects when not using the NoEnumerate switch" { $singleCollection = $(Write-Output $enumerationObject| Measure-Object).Count - $singleCollection | Should Be $enumerationObject.length + $singleCollection | Should -Be $enumerationObject.length } It "Should be able to treat a collection as a single object using the NoEnumerate switch" { $singleCollection = $(Write-Output $enumerationObject -NoEnumerate | Measure-Object).Count - $singleCollection | Should Be 1 + $singleCollection | Should -Be 1 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 index 4a5fa6a281a..c309821f1a0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' } } @@ -21,7 +21,7 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } } @@ -33,15 +33,15 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } } It "all mandatory params works" -Pending { - { write-progress -activity 'myactivity' -status 'mystatus' } | Should Not Throw + { write-progress -activity 'myactivity' -status 'mystatus' } | Should -Not -Throw } It "all params works" -Pending { - { write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentId 2 -completed:$false -current 'current' -sec 1 -percent 1 } | Should Not Throw + { write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentId 2 -completed:$false -current 'current' -sec 1 -percent 1 } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 index 83e286b7286..534fd4da9bb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 @@ -24,25 +24,25 @@ Describe "Stream writer tests" -Tags "CI" { It "Should write warnings to the warning stream" { Write-Warning "Test Warning" 3>&1 > $targetfile - Get-Content $targetfile | Should Be "Test Warning" + Get-Content $targetfile | Should -Be "Test Warning" } It "Should write error messages to the error stream" { Write-Error "Testing Error" 2>&1 > $targetfile # The contents of the error stream should contain the expected text - $targetfile | Should FileContentMatch ": Testing Error" + $targetfile | Should -FileContentMatch ": Testing Error" } It "Should write debug messages to the debug stream" { Write-Messages -Debug -EA SilentlyContinue 5>&1 > $targetfile # The contents of the debug stream should contain the expected text - $targetfile | Should FileContentMatch "Debug Message" + $targetfile | Should -FileContentMatch "Debug Message" } It "Should write messages to the verbose stream" { Write-Messages -Verbose 4>&1 > $targetfile # The contents of the debug stream should contain the expected text - $targetfile | Should FileContentMatch "Verbose Message" + $targetfile | Should -FileContentMatch "Verbose Message" } } @@ -50,7 +50,7 @@ Describe "Stream writer tests" -Tags "CI" { It "Should write error messages to the `$Error automatic variable" { Write-Error "Test Error Message" -ErrorAction SilentlyContinue - $Error[0] | Should Match "Test Error Message" + $Error[0] | Should -Match "Test Error Message" } } @@ -79,30 +79,30 @@ Describe "Stream writer tests" -Tags "CI" { It "Write-Information outputs an information object" { # redirect the streams is sufficient $result = Write-Information "Test Message" *>&1 - $result.NativeThreadId | Should Not Be 0 - $result.ProcessId | Should Be $pid - $result | Should BeOfType System.Management.Automation.InformationRecord + $result.NativeThreadId | Should -Not -Be 0 + $result.ProcessId | Should -Be $pid + $result | Should -BeOfType System.Management.Automation.InformationRecord # Use Match instead of Be so we can avoid dealing with a potential domain name - $result.Computer | Should Match "^($([environment]::MachineName)){1}(\.[a-zA-Z0-9]+)*$|^localhost$" + $result.Computer | Should -Match "^($([environment]::MachineName)){1}(\.[a-zA-Z0-9]+)*$|^localhost$" if ($IsWindows) { - $result.User | Should Match ".*${env:USERNAME}" + $result.User | Should -Match ".*${env:USERNAME}" } else { - $result.User | Should Be $(whoami) + $result.User | Should -Be $(whoami) } - "$result" | Should be "Test Message" + "$result" | Should -be "Test Message" } It "Write-Information accept objects from pipe" { $ps.AddScript("'teststring',12345 | Write-Information -InformationAction Continue").Invoke() $result = $ps.Streams.Information - $result.Count | Should be 2 - $result[0].MessageData | Should be "teststring" - $result[1].MessageData | Should be "12345" + $result.Count | Should -be 2 + $result[0].MessageData | Should -be "teststring" + $result[1].MessageData | Should -be "12345" } It "Write-Information works with " -TestCases:$testInfoData { @@ -111,8 +111,8 @@ Describe "Stream writer tests" -Tags "CI" { $result = $ps.Streams.Information - $result.Count | Should Be $returnCount - (Compare-Object $result $returnValue -SyncWindow 0).length | Should Be 0 + $result.Count | Should -Be $returnCount + (Compare-Object $result $returnValue -SyncWindow 0).length | Should -Be 0 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 index b32452cf39c..f4caee8e1bc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 @@ -2,31 +2,31 @@ # Licensed under the MIT License. Describe "Write-Verbose" -Tags "CI" { It "Should be able to call cmdlet without error" { - { Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should Not Throw + { Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should -Not -Throw } It "Should not display verbose output by default" { - $VerbosePreference | Should Be SilentlyContinue + $VerbosePreference | Should -Be SilentlyContinue - Write-Verbose -Message "test" | Should BeNullOrEmpty + Write-Verbose -Message "test" | Should -BeNullOrEmpty } It "Should be able to set verbose output to display by changing the `$VerbosePreference automatic variable" { $VerbosePreference = "Continue" - Write-Verbose -Message "test" 4>&1 | Should Not BeNullOrEmpty + Write-Verbose -Message "test" 4>&1 | Should -Not -BeNullOrEmpty $VerbosePreference = "SilentlyContinue" } It "Should be able to set verbose output to display by using the verbose switch" { - Write-Verbose -Message "test" -Verbose 4>&1 | Should Be "test" + Write-Verbose -Message "test" -Verbose 4>&1 | Should -Be "test" } It "Should be able to set verbose switch using a colon and boolean" { - { Write-Verbose -Message "test" -Verbose:$false } | Should Not Throw + { Write-Verbose -Message "test" -Verbose:$false } | Should -Not -Throw - $(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should Be "test" + $(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should -Be "test" } It "Should not have added line breaks" { @@ -38,7 +38,7 @@ Describe "Write-Verbose" -Tags "CI" { $VerbosePreference = "continue" try { $out = Write-Verbose $text 4>&1 - $out | Should BeExactly $text + $out | Should -BeExactly $text } finally { $VerbosePreference = $origVerbosePref diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 index 5d14185cd33..3971e0e8efa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 @@ -38,8 +38,8 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { It "Import with CliXml directive should work" { Get-Command export* -Type Cmdlet | Select-Object -First 3 | Export-Clixml -Path $testfile $results = Import-Clixml $testfile - $results.Count | Should BeExactly 3 - $results[0].PSTypeNames[0] | Should Be "Deserialized.System.Management.Automation.CmdletInfo" + $results.Count | Should -BeExactly 3 + $results[0].PSTypeNames[0] | Should -Be "Deserialized.System.Management.Automation.CmdletInfo" } It "Import with Rehydration should work" { @@ -48,8 +48,8 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $isHiddenTestType = [IsHiddenTestType]::New($property1,$property2) $isHiddenTestType | Export-Clixml $testfile $results = Import-Clixml $testfile - $results.Property1 | Should Be $property1 - $results.Property2 | Should Be $property2 + $results.Property1 | Should -Be $property1 + $results.Property2 | Should -Be $property2 } It "Export-Clixml StopProcessing should succeed" { @@ -62,7 +62,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $null = $ps.BeginInvoke() Start-Sleep 1 $null = $ps.Stop() - $ps.InvocationStateInfo.State | should be "Stopped" + $ps.InvocationStateInfo.State | should -be "Stopped" $ps.Dispose() } @@ -74,7 +74,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $ps.AddParameter("Path", $testfile) $ps.BeginInvoke() $ps.Stop() - $ps.InvocationStateInfo.State | Should Be "Stopped" + $ps.InvocationStateInfo.State | Should -Be "Stopped" } It "Export-Clixml using -Depth should work" { @@ -98,34 +98,34 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $one = [One]::New() $one | Export-Clixml -Depth 2 -Path $testfile $deserialized_one = Import-Clixml -Path $testfile - $deserialized_one.Value | Should Be 1 - $deserialized_one.two.Value | Should Be 2 - $deserialized_one.two.Three | Should Not BeNullOrEmpty - $deserialized_one.two.three.num | Should BeNullOrEmpty + $deserialized_one.Value | Should -Be 1 + $deserialized_one.two.Value | Should -Be 2 + $deserialized_one.two.Three | Should -Not -BeNullOrEmpty + $deserialized_one.two.three.num | Should -BeNullOrEmpty } It "Import-Clixml should work with XML serialization from pwsh.exe" { # need to create separate process so that current powershell doesn't interpret clixml output Start-Process -FilePath $pshome\pwsh -RedirectStandardOutput $testfile -Args "-noprofile -nologo -outputformat xml -command get-command import-clixml" -Wait $out = Import-Clixml -Path $testfile - $out.Name | Should Be "Import-CliXml" - $out.CommandType.ToString() | Should Be "Cmdlet" - $out.Source | Should Be "Microsoft.PowerShell.Utility" + $out.Name | Should -Be "Import-CliXml" + $out.CommandType.ToString() | Should -Be "Cmdlet" + $out.Source | Should -Be "Microsoft.PowerShell.Utility" } It "Import-Clixml -IncludeTotalCount always returns unknown total count" { # this cmdlets supports paging, but not this switch [PSCustomObject]@{foo=1;bar=@{hello="world"}} | Export-Clixml -Path $testfile $out = Import-Clixml -Path $testfile -IncludeTotalCount - $out[0].ToString() | Should BeExactly "Unknown total count" + $out[0].ToString() | Should -BeExactly "Unknown total count" } It "Import-Clixml -First and -Skip work together for simple types" { "one","two","three","four" | Export-Clixml -Path $testfile $out = Import-Clixml -Path $testfile -First 2 -Skip 1 - $out.Count | Should Be 2 - $out[0] | Should BeExactly "two" - $out[1] | Should BeExactly "three" + $out.Count | Should -Be 2 + $out[0] | Should -BeExactly "two" + $out[1] | Should -BeExactly "three" } It "Import-Clixml -First and -Skip work together for collections" { @@ -133,9 +133,9 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { # order not guaranteed, even with [ordered] so we have to be smart here and compare against the full result $out1 = Import-Clixml -Path $testfile # this results in a hashtable $out2 = Import-Clixml -Path $testfile -First 2 -Skip 1 # this results in a dictionary entry - $out2.Count | Should Be 2 - ($out2.Name) -join ":" | should be (@($out1.Keys)[1, 2] -join ":") - ($out2.Value) -join ":" | should be (@($out1.Values)[1, 2] -join ":") + $out2.Count | Should -Be 2 + ($out2.Name) -join ":" | should -be (@($out1.Keys)[1, 2] -join ":") + ($out2.Value) -join ":" | should -be (@($out1.Values)[1, 2] -join ":") } # these tests just cover aspects that aren't normally exercised being used as a cmdlet @@ -144,19 +144,19 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $cmd = [Microsoft.PowerShell.Commands.ExportClixmlCommand]::new() $cmd.LiteralPath = "foo" - $cmd.LiteralPath | Should BeExactly "foo" + $cmd.LiteralPath | Should -BeExactly "foo" $cmd.NoClobber = $true - $cmd.NoClobber | Should Be $true + $cmd.NoClobber | Should -Be $true $cmd = [Microsoft.PowerShell.Commands.ImportClixmlCommand]::new() $cmd.LiteralPath = "bar" - $cmd.LiteralPath | Should BeExactly "bar" + $cmd.LiteralPath | Should -BeExactly "bar" $cmd = [Microsoft.PowerShell.Commands.SelectXmlCommand]::new() $cmd.LiteralPath = "foo" - $cmd.LiteralPath | Should BeExactly "foo" + $cmd.LiteralPath | Should -BeExactly "foo" $xml = [xml]"" $cmd.Xml = $xml - $cmd.Xml | Should Be $xml + $cmd.Xml | Should -Be $xml } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 index ff4b864857a..4b7082a0113 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 @@ -50,11 +50,11 @@ Describe "Alias tests" -Tags "CI" { if($null -eq $test.expectedError) { - Test-Path -LiteralPath $test.testFile | Should Be $true + Test-Path -LiteralPath $test.testFile | Should -Be $true } else { - $exportAliasError.FullyqualifiedErrorId | Should Be $test.expectedError + $exportAliasError.FullyqualifiedErrorId | Should -Be $test.expectedError } } @@ -75,7 +75,7 @@ Describe "Alias tests" -Tags "CI" { $exportAliasError = $_ } - $exportAliasError.FullyQualifiedErrorId | Should Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" + $exportAliasError.FullyQualifiedErrorId | Should -Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" } } @@ -86,7 +86,7 @@ Describe "Alias tests" -Tags "CI" { It "with a CSV file" { Export-Alias "alias.csv" - Test-Path -LiteralPath (Join-Path $testPath "alias.csv") | Should Be $true + Test-Path -LiteralPath (Join-Path $testPath "alias.csv") | Should -Be $true } It "with NoClobber" { @@ -101,7 +101,7 @@ Describe "Alias tests" -Tags "CI" { $exportAliasError = $_ } - $exportAliasError.FullyQualifiedErrorId | Should Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" + $exportAliasError.FullyQualifiedErrorId | Should -Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" } AfterEach { @@ -135,7 +135,7 @@ Describe "Alias tests" -Tags "CI" { $exportAliasError = $_ } - $exportAliasError.FullyqualifiedErrorId | Should Be $test.expectedError + $exportAliasError.FullyqualifiedErrorId | Should -Be $test.expectedError } } @@ -154,9 +154,9 @@ Describe "Alias tests" -Tags "CI" { # Verify that the alias was imported $definedAlias = Get-Alias myuh - $definedAlias | Should Not Be $null - $definedAlias.Name | Should Be "myuh" - $definedAlias.Definition | Should Be "update-help" + $definedAlias | Should -Not -Be $null + $definedAlias.Name | Should -Be "myuh" + $definedAlias.Definition | Should -Be "update-help" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 index 9eef6350390..20b6cc072fb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 @@ -67,7 +67,7 @@ Describe "CliXml test" -Tags "CI" { $exportCliXmlError = $_ } - $exportCliXmlError.FullyQualifiedErrorId | Should Be $test.expectedError + $exportCliXmlError.FullyQualifiedErrorId | Should -Be $test.expectedError } } @@ -76,7 +76,7 @@ Describe "CliXml test" -Tags "CI" { $filePath = Join-Path $subFilePath 'gps.xml' Export-Clixml -Depth 1 -LiteralPath $filePath -InputObject ($gpsList | Select-Object -First 1) - $filePath | Should Exist + $filePath | Should -Exist $fileContent = Get-Content $filePath $isExisted = $false @@ -94,7 +94,7 @@ Describe "CliXml test" -Tags "CI" { } } - $isExisted | Should Be $true + $isExisted | Should -Be $true } It "can be created with literal path using pipeline" { @@ -102,7 +102,7 @@ Describe "CliXml test" -Tags "CI" { $filePath = Join-Path $subFilePath 'gps.xml' ($gpsList | Select-Object -First 1) | Export-Clixml -Depth 1 -LiteralPath $filePath - $filePath | Should Exist + $filePath | Should -Exist $fileContent = Get-Content $filePath $isExisted = $false @@ -120,7 +120,7 @@ Describe "CliXml test" -Tags "CI" { } } - $isExisted | Should Be $true + $isExisted | Should -Be $true } } @@ -150,43 +150,43 @@ Describe "CliXml test" -Tags "CI" { $importCliXmlError = $_ } - $importCliXmlError.FullyQualifiedErrorId | Should Be $test.expectedError + $importCliXmlError.FullyQualifiedErrorId | Should -Be $test.expectedError } } It "can import from a literal path" { Export-Clixml -Depth 1 -LiteralPath $filePath -InputObject $gps - $filePath | Should Exist + $filePath | Should -Exist $fileContent = Get-Content $filePath - $fileContent | Should Not Be $null + $fileContent | Should -Not -Be $null $importedProcess = Import-Clixml $filePath - $importedProcess.ProcessName | Should Not BeNullOrEmpty - $gps.ProcessName | Should Be $importedProcess.ProcessName - $importedProcess.Id | Should Not BeNullOrEmpty - $gps.Id | Should Be $importedProcess.Id + $importedProcess.ProcessName | Should -Not -BeNullOrEmpty + $gps.ProcessName | Should -Be $importedProcess.ProcessName + $importedProcess.Id | Should -Not -BeNullOrEmpty + $gps.Id | Should -Be $importedProcess.Id } It "can import from a literal path using pipeline" { $gps | Export-Clixml -Depth 1 -LiteralPath $filePath - $filePath | Should Exist + $filePath | Should -Exist $fileContent = Get-Content $filePath - $fileContent | Should Not Be $null + $fileContent | Should -Not -Be $null $importedProcess = Import-Clixml $filePath - $importedProcess.ProcessName | Should Not BeNullOrEmpty - $gps.ProcessName | Should Be $importedProcess.ProcessName - $importedProcess.Id | Should Not BeNullOrEmpty - $gps.Id | Should Be $importedProcess.Id + $importedProcess.ProcessName | Should -Not -BeNullOrEmpty + $gps.ProcessName | Should -Be $importedProcess.ProcessName + $importedProcess.Id | Should -Not -BeNullOrEmpty + $gps.Id | Should -Be $importedProcess.Id } It "test follow-up for WinBlue: 161470 - Export-CliXml errors in WhatIf scenarios" { $testPath = "testdrive:\Bug161470NonExistPath.txt" Export-Clixml -Path $testPath -InputObject "string" -WhatIf - $testPath | Should Not Exist + $testPath | Should -Not -Exist } } } @@ -228,6 +228,6 @@ Describe "Deserializing corrupted Cim classes should not instantiate non-Cim typ Start-Sleep -Milliseconds 500 } - $calcProc | Should BeNullOrEmpty + $calcProc | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/command.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/command.tests.ps1 index 76e091fe8ac..fee1c049fe8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/command.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/command.tests.ps1 @@ -21,13 +21,13 @@ Describe "Trace-Command" -tags "Feature" { Trace-Command -Name * -Expression {write-output Foo} -ListenerOption LogicalOperationStack -FilePath $logfile $log = Get-Content $logfile | Where-Object {$_ -like "*LogicalOperationStack=$keyword*"} - $log.Count | Should BeGreaterThan 0 + $log.Count | Should -BeGreaterThan 0 } It "Callstack works" -pending:($IsCoreCLR) { Trace-Command -Name * -Expression {write-output Foo} -ListenerOption Callstack -FilePath $logfile $log = Get-Content $logfile | Where-Object {$_ -like "*Callstack= * System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)*"} - $log.Count | Should BeGreaterThan 0 + $log.Count | Should -BeGreaterThan 0 } It "Datetime works" { @@ -44,7 +44,7 @@ Describe "Trace-Command" -tags "Feature" { $actualGap = $expectedDate - $_; } - $allowedGap | Should BeGreaterThan $actualGap + $allowedGap | Should -BeGreaterThan $actualGap } } @@ -52,7 +52,7 @@ Describe "Trace-Command" -tags "Feature" { Trace-Command -Name * -Expression {write-output Foo} -ListenerOption None -FilePath $actualLogfile Trace-Command -name * -Expression {write-output Foo} -FilePath $logfile - Compare-Object (Get-Content $actualLogfile) (Get-Content $logfile) | Should BeNullOrEmpty + Compare-Object (Get-Content $actualLogfile) (Get-Content $logfile) | Should -BeNullOrEmpty } It "ThreadID works" { @@ -60,7 +60,7 @@ Describe "Trace-Command" -tags "Feature" { $log = Get-Content $logfile | Where-Object {$_ -like "*ThreadID=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} - $results | ForEach-Object { $_ | Should Be ([threading.thread]::CurrentThread.ManagedThreadId) } + $results | ForEach-Object { $_ | Should -Be ([threading.thread]::CurrentThread.ManagedThreadId) } } It "Timestamp creates logs in ascending order" { @@ -68,7 +68,7 @@ Describe "Trace-Command" -tags "Feature" { $log = Get-Content $logfile | Where-Object {$_ -like "*Timestamp=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} $sortedResults = $results | Sort-Object - $sortedResults | Should Be $results + $sortedResults | Should -Be $results } It "ProcessId logs current process Id" { @@ -76,7 +76,7 @@ Describe "Trace-Command" -tags "Feature" { $log = Get-Content $logfile | Where-Object {$_ -like "*ProcessID=*"} $results = $log | ForEach-Object {$_.Split("=")[1]} - $results | ForEach-Object { $_ | Should Be $pid } + $results | ForEach-Object { $_ | Should -Be $pid } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 index b4f8d958485..2bf8a4b87bf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 @@ -19,8 +19,8 @@ Describe "FormatData" -tags "Feature" { $runspace.CreatePipeline("Update-FormatData -AppendPath $TESTDRIVE\allformat.ps1xml").Invoke() $actualAllFormat = $runspace.CreatePipeline("Get-FormatData -TypeName *").Invoke() - $expectAllFormat.Count | Should Be $actualAllFormat.Count - Compare-Object $expectAllFormat $actualAllFormat | Should Be $null + $expectAllFormat.Count | Should -Be $actualAllFormat.Count + Compare-Object $expectAllFormat $actualAllFormat | Should -Be $null $runspace.Close() } finally @@ -32,7 +32,7 @@ Describe "FormatData" -tags "Feature" { It "works with literal path" { $filename = 'TestDrive:\[formats.ps1xml' Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename - (Test-Path -LiteralPath $filename) | Should Be $true + (Test-Path -LiteralPath $filename) | Should -Be $true } It "should overwrite the destination file" { @@ -44,7 +44,7 @@ Describe "FormatData" -tags "Feature" { Get-FormatData -TypeName * | Export-FormatData -Path $filename -Force $actual = @(Get-Content $filename)[0] - $actual | Should Not Be $unexpected + $actual | Should -Not -Be $unexpected } It "should not overwrite the destination file with NoClobber" { @@ -60,7 +60,7 @@ Describe "FormatData" -tags "Feature" { $exportFormatError = $_ } - $exportFormatError.FullyQualifiedErrorId | Should Be 'NoClobber,Microsoft.PowerShell.Commands.ExportFormatDataCommand' + $exportFormatError.FullyQualifiedErrorId | Should -Be 'NoClobber,Microsoft.PowerShell.Commands.ExportFormatDataCommand' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/object.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/object.tests.ps1 index 14381b2f41b..c4f24590b30 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/object.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/object.tests.ps1 @@ -4,13 +4,13 @@ Describe "Object cmdlets" -Tags "CI" { Context "Group-Object" { It "AsHashtable returns a hashtable" { $result = Get-Process | Group-Object -Property ProcessName -AsHashTable - $result["pwsh"].Count | Should BeGreaterThan 0 + $result["pwsh"].Count | Should -BeGreaterThan 0 } It "AsString returns a string" { $processes = Get-Process | Group-Object -Property ProcessName -AsHashTable -AsString $result = $processes.Keys | ForEach-Object {$_.GetType()} - $result[0].Name | Should Be "String" + $result[0].Name | Should -Be "String" } } @@ -18,7 +18,7 @@ Describe "Object cmdlets" -Tags "CI" { It "with literal path" { $path = "TestDrive:\[TeeObjectLiteralPathShouldWorkForSpecialFilename].txt" Write-Output "Test" | Tee-Object -LiteralPath $path | Tee-Object -Variable TeeObjectLiteralPathShouldWorkForSpecialFilename - $TeeObjectLiteralPathShouldWorkForSpecialFilename | Should Be (Get-Content -LiteralPath $path) + $TeeObjectLiteralPathShouldWorkForSpecialFilename | Should -Be (Get-Content -LiteralPath $path) } } } @@ -62,41 +62,41 @@ Describe "Object cmdlets" -Tags "CI" { It "can compare string representation for minimum" { $minResult = $firstObject, $secondObject | Measure-Object Header -Minimum - $minResult.Minimum.ToString() | Should Be $expectedFirstValue.ToString() + $minResult.Minimum.ToString() | Should -Be $expectedFirstValue.ToString() } It "can compare string representation for maximum" { $maxResult = $firstObject, $secondObject | Measure-Object Header -Maximum - $maxResult.Maximum.ToString() | Should Be $expectedSecondValue.ToString() + $maxResult.Maximum.ToString() | Should -Be $expectedSecondValue.ToString() } It 'correctly find minimum of ()' -TestCases $testCases { param($data, $min, $max) $output = $data | Measure-Object -Minimum - $output.Minimum.ToString() | Should Be $min + $output.Minimum.ToString() | Should -Be $min } It 'correctly find maximum of ()' -TestCases $testCases { param($data, $min, $max) $output = $data | Measure-Object -Maximum - $output.Maximum.ToString() | Should Be $max + $output.Maximum.ToString() | Should -Be $max } It 'returns a GenericMeasureInfoObject' { $gmi = 1,2,3 | measure-object -max -min - $gmi | Should BeOfType Microsoft.PowerShell.Commands.GenericMeasureInfo + $gmi | Should -BeOfType Microsoft.PowerShell.Commands.GenericMeasureInfo } It 'should return correct error for non-numeric input' { $gmi = "abc",[Datetime]::Now | measure -sum -max -ev err -ea silentlycontinue - $err | ForEach-Object { $_.FullyQualifiedErrorId | Should Be 'NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand' } + $err | ForEach-Object { $_.FullyQualifiedErrorId | Should -Be 'NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand' } } It 'should have the correct count' { $gmi = "abc",[Datetime]::Now | measure -sum -max -ev err -ea silentlycontinue - $gmi.Count | Should Be 2 + $gmi.Count | Should -Be 2 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/string.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/string.tests.ps1 index 3a4713bb425..d0a253fcc5c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/string.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/string.tests.ps1 @@ -33,37 +33,37 @@ Describe "String cmdlets" -Tags "CI" { } It "Select-String does not throw on subdirectory (path without wildcard)" { - { select-string -Path $pathWithoutWildcard "noExists" -ErrorAction Stop } | Should Not Throw + { select-string -Path $pathWithoutWildcard "noExists" -ErrorAction Stop } | Should -Not -Throw } It "Select-String does not throw on subdirectory (path with wildcard)" { - { select-string -Path $pathWithWildcard "noExists" -ErrorAction Stop } | Should Not Throw + { select-string -Path $pathWithWildcard "noExists" -ErrorAction Stop } | Should -Not -Throw } It "LiteralPath with relative path" { - (select-string -LiteralPath (Get-Item -LiteralPath $fileName).Name "b").count | Should Be 2 + (select-string -LiteralPath (Get-Item -LiteralPath $fileName).Name "b").count | Should -Be 2 } It "LiteralPath with absolute path" { - (select-string -LiteralPath $fileName "b").count | Should Be 2 + (select-string -LiteralPath $fileName "b").count | Should -Be 2 } It "LiteralPath with dots in path" { - (select-string -LiteralPath $fileNameWithDots "b").count | Should Be 2 + (select-string -LiteralPath $fileNameWithDots "b").count | Should -Be 2 } It "Network path" -skip:(!$IsWindows) { - (select-string -LiteralPath $fileNameAsNetworkPath "b").count | Should Be 2 + (select-string -LiteralPath $fileNameAsNetworkPath "b").count | Should -Be 2 } It "throws error for non filesystem providers" { $aaa = "aaaaaaaaaa" select-string -literalPath variable:\aaa "a" -ErrorAction SilentlyContinue -ErrorVariable selectStringError - $selectStringError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand' + $selectStringError.FullyQualifiedErrorId | Should -Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand' } It "throws parameter binding exception for invalid context" { - { select-string It $PSScriptRoot -Context -1,-1 } | Should Throw Context + { select-string It $PSScriptRoot -Context -1,-1 } | Should -Throw Context } It "match object supports RelativePath method" { @@ -71,9 +71,9 @@ Describe "String cmdlets" -Tags "CI" { $match = Select-String CmdletsToExport $pshome/$file - $match.RelativePath($pshome) | Should Be $file - $match.RelativePath($pshome.ToLower()) | Should Be $file - $match.RelativePath($pshome.ToUpper()) | Should Be $file + $match.RelativePath($pshome) | Should -Be $file + $match.RelativePath($pshome.ToLower()) | Should -Be $file + $match.RelativePath($pshome.ToUpper()) | Should -Be $file } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 index eaa83972694..da0903a92ab 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 @@ -3,27 +3,27 @@ Describe "TestData cmdlets" -Tags "CI" { Context "Get-TypeData" { It "System.DateTime" { - (Get-TypeData System.DateTime).TypeName | Should Be System.DateTime + (Get-TypeData System.DateTime).TypeName | Should -Be System.DateTime # Supports pipelining? - ("System.DateTime" | Get-TypeData).TypeName | Should Be System.DateTime + ("System.DateTime" | Get-TypeData).TypeName | Should -Be System.DateTime } It "Type accelerators" { - (Get-TypeData DateTime).TypeName | Should Be System.DateTime - (Get-TypeData psCredential).TypeName | Should Be System.Management.Automation.PSCredential + (Get-TypeData DateTime).TypeName | Should -Be System.DateTime + (Get-TypeData psCredential).TypeName | Should -Be System.Management.Automation.PSCredential } It "Accept multiple types" { $types = Get-TypeData System.DateTime, System.Management.Automation* | Sort-Object -Property TypeName - $types[0].TypeName | Should Be System.DateTime + $types[0].TypeName | Should -Be System.DateTime for($i = 1; $i -lt $types.Count; $i++) { - $types[$i].TypeName.StartsWith("System.Management.Automation") | Should Be $true + $types[$i].TypeName.StartsWith("System.Management.Automation") | Should -Be $true } } It "System.Object" { - Get-TypeData System.Object | Should Be $null + Get-TypeData System.Object | Should -Be $null } } @@ -48,8 +48,8 @@ Describe "TestData cmdlets" -Tags "CI" { Update-TypeData -TypeName Void -TypeAdapter Microsoft.PowerShell.Cim.CimInstanceAdapter Get-TypeData System.Void "@).Invoke() - $type[0].TypeName | Should Be System.Void - $type[0].TypeAdapter.FullName | Should Be Microsoft.PowerShell.Cim.CimInstanceAdapter + $type[0].TypeName | Should -Be System.Void + $type[0].TypeAdapter.FullName | Should -Be Microsoft.PowerShell.Cim.CimInstanceAdapter } } @@ -73,57 +73,57 @@ Get-TypeData System.Void It "Remove type that doesn't exist" { $typeName = "TypeThatDoesNotExistsAnywhere" + (Get-Random) $ps.AddScript("Remove-TypeData -TypeName $typeName").Invoke() - $ps.Streams.Error[0].FullyQualifiedErrorId | Should Be "TypesDynamicRemoveException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypesDynamicRemoveException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" } ##{ All of the following It blocks are intended to run in sequence, so don't reorder them. It "Add type file," { $ps.AddScript("Update-TypeData -AppendPath $TestDrive\dummy1.types.ps1xml").Invoke() - $ps.Streams.Error.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 } It "Get type data from file just added," { $type = $ps.AddScript("Get-TypeData -TypeName yyyDummy").Invoke() - $ps.Streams.Error.Count | Should Be 0 - $type[0].TypeName | Should Be yyyDummy + $ps.Streams.Error.Count | Should -Be 0 + $type[0].TypeName | Should -Be yyyDummy } It "Remove type file just added," { $ps.AddScript("Remove-TypeData -Path $TestDrive\dummy1.types.ps1xml").Invoke() - $ps.Streams.Error.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 } It "Make sure type was removed" { $type = $ps.AddScript("Get-TypeData -TypeName yyyDummy").Invoke() - $type.Count | Should Be 0 + $type.Count | Should -Be 0 } It "Add another type file," { $ps.AddScript("Update-TypeData -AppendPath $TestDrive\dummy2.types.ps1xml").Invoke() - $ps.Streams.Error.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 } It "Now add some type data to one of those newly added types" { $ps.AddScript("Update-TypeData -TypeName zzzDummy -MemberType NoteProperty -MemberName DynamicDummyProperty -Value 10").Invoke() - $ps.Streams.Error.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 } It "Remove the newly type file," { $ps.AddScript("Remove-TypeData -Path $TestDrive\dummy2.types.ps1xml").Invoke() - $ps.Streams.Error.Count | Should Be 0 + $ps.Streams.Error.Count | Should -Be 0 } It "Remove the newly type file a second time, should error," { $ps.AddScript("Remove-TypeData -Path $TestDrive\dummy2.types.ps1xml").Invoke() - $ps.Streams.Error.Count | Should Be 1 - $ps.Streams.Error[0].FullyQualifiedErrorId | Should Be "TypeFileNotExistsInCurrentSession,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" + $ps.Streams.Error.Count | Should -Be 1 + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypeFileNotExistsInCurrentSession,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" } It "Dynamic property added should still be there" { $res = $ps.AddScript("Get-TypeData -TypeName zzzDummy").Invoke() - $res.Count | Should Be 1 - $res[0].Members.Keys[0] | Should Be DynamicDummyProperty + $res.Count | Should -Be 1 + $res[0].Members.Keys[0] | Should -Be DynamicDummyProperty } ##} All of the preceding It blocks are intended to run in sequence, so don't reorder them. diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 index a4c4eaecb22..30088623d1c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 @@ -51,8 +51,8 @@ Describe "XML cmdlets" -Tags "Feature" { $params = $_.parameters It $_.testName { - @(Select-XML @params).Count | Should Be 1 - (Select-XML @params).Path | Should Be $fileName.FullName + @(Select-XML @params).Count | Should -Be 1 + (Select-XML @params).Path | Should -Be $fileName.FullName } } @@ -68,7 +68,7 @@ Describe "XML cmdlets" -Tags "Feature" { $params = @{$parameter=$file} $err = $null Select-XML @params "Root" -ErrorVariable err -ErrorAction SilentlyContinue - $err.FullyQualifiedErrorId | Should Be $expectedError + $err.FullyQualifiedErrorId | Should -Be $expectedError } finally { @@ -81,40 +81,40 @@ Describe "XML cmdlets" -Tags "Feature" { Set-Content -Path $testfile -Value "" $err = $null Select-Xml -Path $testfile -XPath foo -ErrorVariable err -ErrorAction SilentlyContinue - $err.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' + $err.FullyQualifiedErrorId | Should -Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "-xml works with inputstream" { [xml]$xml = "helloworld" $node = Select-Xml -Xml $xml -XPath "//c:b" -Namespace @{c='bar'} - $node.Path | Should BeExactly "InputStream" + $node.Path | Should -BeExactly "InputStream" $node.Pattern = "//c:b" - $node.ToString() | Should BeExactly "hello" + $node.ToString() | Should -BeExactly "hello" } It "Returns error for invalid xmlnamespace" { $err = $null [xml]$xml = "helloworld" Select-Xml -Xml $xml -XPath foo -Namespace @{c=$null} -ErrorVariable err -ErrorAction SilentlyContinue - $err.FullyQualifiedErrorId | Should Be 'PrefixError,Microsoft.PowerShell.Commands.SelectXmlCommand' + $err.FullyQualifiedErrorId | Should -Be 'PrefixError,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "Returns error for invalid content" { $err = $null Select-Xml -Content "hello" -XPath foo -ErrorVariable err -ErrorAction SilentlyContinue - $err.FullyQualifiedErrorId | Should Be 'InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand' + $err.FullyQualifiedErrorId | Should -Be 'InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "ToString() works correctly on nested node" { $node = Select-Xml -Content "onehello" -XPath "//b" - $node.ToString() | Should BeExactly "onehello" + $node.ToString() | Should -BeExactly "onehello" } It "ToString() works correctly with file" { $testfile = Join-Path "$testdrive" "test.xml" Set-Content -Path $testfile -Value "hello" $node = Select-Xml -Path $testfile -XPath "//b" - $node.ToString() | Should BeExactly "hello:$testfile" + $node.ToString() | Should -BeExactly "hello:$testfile" } } } From b5ce7017cc40636a58590501d29274c5fd782909 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 08:49:30 -0700 Subject: [PATCH 02/21] [Feature] Capital letter and -BeNullOrEmpty, -BeTrue, -BeFalse in pester tests parameters in Utility module. --- .../Add-Type.Tests.ps1 | 4 +- .../Clear-Variable.Tests.ps1 | 12 ++-- .../Compare-Object.Tests.ps1 | 8 +-- .../ConvertFrom-StringData.Tests.ps1 | 2 +- .../ConvertTo-Xml.Tests.ps1 | 12 ++-- .../Debug-Runspace.Tests.ps1 | 8 +-- .../EnableDisablePSBreakpoint.Tests.ps1 | 8 +-- .../Eventing.Tests.ps1 | 14 ++-- .../Export-Alias.Tests.ps1 | 10 +-- .../Export-Csv.Tests.ps1 | 8 +-- .../Export-FormatData.Tests.ps1 | 4 +- .../Format-Table.Tests.ps1 | 2 +- .../Format-Wide.Tests.ps1 | 2 +- .../Get-Alias.Tests.ps1 | 6 +- .../Get-Culture.Tests.ps1 | 2 +- .../Get-Date.Tests.ps1 | 54 +++++++-------- .../Get-Event.Tests.ps1 | 2 +- .../Get-Member.Tests.ps1 | 2 +- .../Get-PSBreakpoint.Tests.ps1 | 4 +- .../Get-PSCallStack.Tests.ps1 | 40 +++++------ .../Get-Random.Tests.ps1 | 2 +- .../Get-TraceSource.Tests.ps1 | 2 +- .../Get-Uptime.Tests.ps1 | 2 +- .../Get-Variable.Tests.ps1 | 26 +++---- .../Get-Verb.Tests.ps1 | 14 ++-- .../Implicit.Remoting.Tests.ps1 | 68 +++++++++---------- .../Import-Alias.Tests.ps1 | 8 +-- .../Import-LocalizedData.Tests.ps1 | 8 +-- .../ImportExportCSV.Delimiter.Tests.ps1 | 8 +-- .../Invoke-Expression.Tests.ps1 | 2 +- .../Invoke-Item.Tests.ps1 | 2 +- .../JsonObject.Tests.ps1 | 4 +- .../MiscCmdletUpdates.Tests.ps1 | 10 +-- .../New-Alias.Tests.ps1 | 2 +- .../New-Event.Tests.ps1 | 2 +- .../New-Object.Tests.ps1 | 24 +++---- .../New-Variable.Tests.ps1 | 12 ++-- .../NewTemporaryFile.Tests.ps1 | 2 +- .../Out-File.Tests.ps1 | 2 +- .../Out-String.Tests.ps1 | 4 +- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 18 ++--- .../Read-Host.Tests.ps1 | 6 +- .../Remove-TypeData.Tests.ps1 | 6 +- .../Remove-Variable.Tests.ps1 | 2 +- .../RunspaceCmdlets.Tests.ps1 | 12 ++-- .../Select-Object.Tests.ps1 | 20 +++--- .../Select-String.Tests.ps1 | 2 +- .../Send-MailMessage.Tests.ps1 | 2 +- .../Set-Alias.Tests.ps1 | 4 +- .../Set-Variable.Tests.ps1 | 8 +-- .../Sort-Object.Tests.ps1 | 6 +- .../Tee-Object.Tests.ps1 | 8 +-- .../Unblock-File.Tests.ps1 | 6 +- .../Update-FormatData.Tests.ps1 | 4 +- .../Update-TypeData.Tests.ps1 | 28 ++++---- .../WebCmdlets.Tests.ps1 | 18 ++--- .../Write-Output.Tests.ps1 | 6 +- .../Write-Stream.Tests.ps1 | 8 +-- .../XMLCommand.Tests.ps1 | 8 +-- 59 files changed, 290 insertions(+), 290 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 index 6b85cc0a0ea..853a1227a13 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 @@ -48,11 +48,11 @@ Describe "Add-Type" -Tags "CI" { [System.Management.Automation.Cmdlet("Get", "Thing", ConfirmImpact = System.Management.Automation.ConfirmImpact.High, SupportsPaging = true)] public class AttributeTest$guid {} "@ - Add-Type -TypeDefinition $code -PassThru | Should -Not -Be $null + Add-Type -TypeDefinition $code -PassThru | Should -Not -BeNullOrEmpty } It "Can load TPA assembly System.Runtime.Serialization.Primitives.dll" { - Add-Type -AssemblyName 'System.Runtime.Serialization.Primitives' -PassThru | Should -Not -Be $null + Add-Type -AssemblyName 'System.Runtime.Serialization.Primitives' -PassThru | Should -Not -BeNullOrEmpty } It "Can compile C# files" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index b14ee03133d..26b5a5af7c2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" - $var1.Value|Should -Be $null + $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" $var1.Description|Should -Be "" } @@ -26,7 +26,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo -Force $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" - $var1.Value|Should -Be $null + $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "ReadOnly" $var1.Description|Should -Be "" } @@ -35,12 +35,12 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Set-Variable foo bar &{ Set-Variable foo baz - $foo | should -be baz + $foo | Should -Be baz Clear-Variable -Name foo -Scope "local" $var1=Get-Variable -Name foo -Scope "local" $var1.Name|Should -Be "foo" - $var1.Value|Should -Be $null + $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" $var1.Description|Should -Be "" } @@ -80,7 +80,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1=Get-Variable -Name foo -Scope "local" $var1.Name|Should -Be "foo" - $var1.Value|Should -Be $null + $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" $var1.Description|Should -Be "" } @@ -193,7 +193,7 @@ Describe "Clear-Variable" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should -be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" } $var2 | Should -Not -BeNullOrEmpty diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index 77ea4b12396..40e13634cf5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -115,10 +115,10 @@ Describe "Compare-Object" -Tags "CI" { $actualOutput[2].InputObject | Should -Be 1 $actualOutput[3].InputObject | Should -Be 15 - $actualOutput[0].SideIndicator | Should -be "=>" - $actualOutput[1].SideIndicator | Should -be "<=" - $actualOutput[2].SideIndicator | Should -be "=>" - $actualOutput[3].SideIndicator | Should -be "<=" + $actualOutput[0].SideIndicator | Should -Be "=>" + $actualOutput[1].SideIndicator | Should -Be "<=" + $actualOutput[2].SideIndicator | Should -Be "=>" + $actualOutput[3].SideIndicator | Should -Be "<=" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index c3bc8ff1b35..ad2e65e49fa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -15,7 +15,7 @@ def=content of def } catch { - $_.FullyQualifiedErrorId | Should -be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 index c2f21af6d81..73052388f7a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -11,7 +11,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $newLine = [System.Environment]::NewLine It "Test convertto-xml with a depth parameter" { $returnObject = $customPSObject | ConvertTo-Xml -Depth 1 - $returnObject -is [System.Xml.XmlDocument] | Should -Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue #$xml = [System.Xml.XmlDocument]$returnObject $expectedValue = '' + 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue @@ -19,7 +19,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { It "Test convertto-xml with notypeinfo parameter" { $returnObject = $customPSObject | ConvertTo-Xml -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should -Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue $expectedValue = '' + 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue } @@ -29,14 +29,14 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $expectedValue = @" $newLine$newLine $newLine val1$newLine val2$newLine $newLine "@ - $returnObject -is [System.String] | Should -Be $true + $returnObject -is [System.String] | Should -BeTrue $returnObject | Should -Be $expectedValue #$returnObject.Trim($newLine) | Should Be $expectedValue.Trim($newLine) } It "Test convertto-xml as Stream" { $returnObject = $customPSObject | ConvertTo-Xml -As Stream - $returnObject -is [System.Array] | Should -Be $true + $returnObject -is [System.Array] | Should -BeTrue $stream1 = '' $stream2 = '' $stream3 = @" @@ -53,7 +53,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { It "Test convertto-xml as Document" { $returnObject = $customPSObject | ConvertTo-Xml -As Document -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should -Be $true + $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue $expectedValue = 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue } @@ -74,7 +74,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $cmd = [Microsoft.PowerShell.Commands.ConvertToXmlCommand]::new() $cmd.NoTypeInformation = $true - $cmd.NoTypeInformation | Should -Be $true + $cmd.NoTypeInformation | Should -BeTrue } It "Serialize primitive type" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 index 710a9b660b0..9aaa1fd389e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should -be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | Should -Be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -30,7 +30,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should -be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | Should -Be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -41,7 +41,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should -be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -52,7 +52,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | should -be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 index 838f33a4842..155dc1b9005 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/EnableDisablePSBreakpoint.Tests.ps1 @@ -10,14 +10,14 @@ Describe "Enable and Disable PSBreakpoints" -Tag "CI" { $bp | remove-psbreakpoint } It "Enable-PSBreakpoint should enable the breakpoint" { - $bp.Enabled | should -be $false + $bp.Enabled | Should -BeFalse Enable-PSBreakpoint $bp - $bp.Enabled | Should -be $true + $bp.Enabled | Should -BeTrue } It "Disable-PSBreakpoint should disable the breakpoint" { Enable-PSBreakpoint $bp - $bp.Enabled | Should -be $true + $bp.Enabled | Should -BeTrue Disable-PSBreakpoint $bp - $bp.Enabled | Should -be $false + $bp.Enabled | Should -BeFalse } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 index f8a6b0f0947..6509b226c83 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Eventing.Tests.ps1 @@ -10,7 +10,7 @@ Describe "Event Subscriber Tests" -tags "CI" { # can't let this case to work It "Register an event with no action, trigger it and wait for it to be raised." -Pending:$true{ - Get-EventSubscriber | should -BeNullOrEmpty + Get-EventSubscriber | Should -BeNullOrEmpty $messageData = new-object psobject $job = Start-Job { Start-Sleep -Seconds 5; 1..5 } $eventtest = Register-ObjectEvent $job -EventName StateChanged -SourceIdentifier EventSIDTest -Action {} -MessageData $messageData @@ -18,21 +18,21 @@ Describe "Event Subscriber Tests" -tags "CI" { wait-event EventSIDTest $eventdata = get-event EventSIDTest - $eventdata.MessageData | should -Be $messageData + $eventdata.MessageData | Should -Be $messageData remove-event EventSIDTest Unregister-Event EventSIDTest - Get-EventSubscriber | should -BeNullOrEmpty + Get-EventSubscriber | Should -BeNullOrEmpty } It "Access a global variable from an event action." { - Get-EventSubscriber | should -BeNullOrEmpty + Get-EventSubscriber | Should -BeNullOrEmpty set-variable incomingGlobal -scope global -value globVarValue $eventtest = register-engineevent -SourceIdentifier foo -Action {set-variable -scope global -name aglobalvariable -value $incomingGlobal} new-event foo $getvar = get-variable aglobalvariable -scope global - $getvar.Name | should -Be aglobalvariable - $getvar.Value | should -Be globVarValue + $getvar.Name | Should -Be aglobalvariable + $getvar.Value | Should -Be globVarValue Unregister-Event foo - Get-EventSubscriber | should -BeNullOrEmpty + Get-EventSubscriber | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index 149ffe90f4f..b734a631095 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -45,7 +45,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" } finally{ Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue @@ -59,7 +59,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" } } @@ -123,7 +123,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { throw "No Exception!" } catch{ - $_.FullyQualifiedErrorId | Should -be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" } Export-Alias $fulltestpath abcd03 -force $fulltestpath| Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' @@ -160,12 +160,12 @@ Describe "Export-Alias" -Tags "CI" { It "Should be able to create a file in the specified location"{ Export-Alias $fulltestpath - Test-Path $fulltestpath | Should -be $true + Test-Path $fulltestpath | Should -BeTrue } It "Should create a file with the list of aliases that match the expected list" { Export-Alias $fulltestpath - Test-Path $fulltestpath | Should -Be $true + Test-Path $fulltestpath | Should -BeTrue $actual = Get-Content $fulltestpath | Sort-Object $expected = Get-Command -CommandType Alias diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 index 2cc97edf64b..bae559440bf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 @@ -106,9 +106,9 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input | Export-Csv -Path $filePath -Force $results = Import-Csv $filePath - $results.P2 | Should -be "second" + $results.P2 | Should -Be "second" $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } - $property | should -not -be P1 + $property | Should -Not -Be P1 } It "Test export-csv with a useculture flag" { @@ -119,7 +119,7 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { Get-Item -Path $outputFilesDir| Export-Csv -Path $fileToGenerate -UseCulture -NoTypeInformation $contents = Get-Content -Path $fileToGenerate $contents.Count | Should -Be 2 - $contents[0].Contains($delimiter) | Should -Be $true - $contents[1].Contains($delimiter) | Should -Be $true + $contents[0].Contains($delimiter) | Should -BeTrue + $contents[1].Contains($delimiter) | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index cc2d6067e88..eb5d0be2f9e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -8,10 +8,10 @@ Describe "Export-FormatData DRT Unit Tests" -Tags "CI" { $content = Get-Content $tempFile $formatViewDefinition = $fd[0].FormatViewDefinition $typeName = $fd[0].TypeName - $content.Contains($typeName) | Should -Be $true + $content.Contains($typeName) | Should -BeTrue for ($i = 0; $i -lt $formatViewDefinition.Count;$i++) { - $content.Contains($formatViewDefinition[$i].Name) | Should -Be $true + $content.Contains($formatViewDefinition[$i].Name) | Should -BeTrue } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index e2d2e5fef6b..00287248e60 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "PipelineStoppedException" - $_.FullyQualifiedErrorId | Should -be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $_.FullyQualifiedErrorId | Should -Be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 index 1011125acf6..9d3bbb9565a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Format-Wide" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" + $_.FullyQualifiedErrorId | Should -Be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 2fc6ad93a6e..98133a38cc9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias OutOfRange Scope"{ @@ -17,7 +17,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Named Single Valid"{ @@ -146,7 +146,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Zero Scope Valid"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 index ecc1d2b2aaf..5226f5ac4ab 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 @@ -3,7 +3,7 @@ Describe "Get-Culture DRT Unit Tests" -Tags "CI" { It "Should works proper with get-culture" { $results = get-Culture - $results -is "System.Globalization.CultureInfo" | Should -be $true + $results -is "System.Globalization.CultureInfo" | Should -BeTrue $results[0].Name | Should -Be $PSCulture } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index 8a2c4ce8220..4875a93e69c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -5,38 +5,38 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $date = [datetime]::Now + ([timespan]::new(0,0,30)) $result = Get-Date -Date $date -Year 1973 -Month 2 -Day 22 -Hour 15 -Minute 40 -Second 10 -Millisecond 200 $result | Should -BeOfType Datetime - $result.Year | Should -be 1973 - $result.Month| Should -be 2 - $result.Day | Should -be 22 - $result.Hour | Should -be 15 - $result.Minute | Should -be 40 - $result.Second | Should -be 10 - $result.Millisecond | Should -be 200 + $result.Year | Should -Be 1973 + $result.Month| Should -Be 2 + $result.Day | Should -Be 22 + $result.Hour | Should -Be 15 + $result.Minute | Should -Be 40 + $result.Second | Should -Be 10 + $result.Millisecond | Should -Be 200 } It "using -displayhint produces the correct output" { $d = Get-date -Date:"Jan 1, 2020" -DisplayHint Date | Out-String - $d.Trim() | Should -be "Wednesday, January 1, 2020" + $d.Trim() | Should -Be "Wednesday, January 1, 2020" } It "using -format produces the correct output" { - Get-date -Date:"Jan 1, 2020" -Format:"MMM-dd-yy" | Should -be "Jan-01-20" + Get-date -Date:"Jan 1, 2020" -Format:"MMM-dd-yy" | Should -Be "Jan-01-20" } It "using -uformat produces the correct output" { - Get-date -Date:"Jan 1, 2020" -UFormat:"%s" | Should -be "1577836800" + Get-date -Date:"Jan 1, 2020" -UFormat:"%s" | Should -Be "1577836800" } It "using -uformat 'ymdH' produces the correct output" { - Get-date -Date 0030-01-01T00:00:00 -uformat %y/%m/%d-%H | Should -be "30/01/01-00" + Get-date -Date 0030-01-01T00:00:00 -uformat %y/%m/%d-%H | Should -Be "30/01/01-00" } It "using -uformat 'aAbBcCdDehHIjmMpr' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should -be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" + Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should -Be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should -be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should -Be "0000:00:002012001/01/3000:00:00300030%" } It "Passing '' to -uformat produces a descriptive error" -TestCases @( @@ -51,7 +51,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $x = new-object System.Management.Automation.PSObject $x | add-member NoteProperty Date ([DateTime]::Now) $y = @($x,$x) - ($y | Get-date).Length | Should -be 2 + ($y | Get-date).Length | Should -Be 2 } It "the LastWriteTime alias works with pipeline input" { @@ -74,12 +74,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $result1 = get-childitem -path $pathString | get-date $result2 = get-childitem -path $pathString | get-date - $result1.Length | Should -be 10 - $result1.Length -eq $result2.Length | Should -be $true + $result1.Length | Should -Be 10 + $result1.Length -eq $result2.Length | Should -BeTrue for($i = 0; $i -lt $result1.Length; $i++) { - $result1[$i] -eq $result2[$i] | Should -be $true + $result1[$i] -eq $result2[$i] | Should -BeTrue } Get-ChildItem -Path $pathString | Remove-Item @@ -106,23 +106,23 @@ Describe "Get-Date" -Tags "CI" { } It "Should have colons when ToString method is used" { - (Get-Date).ToString().Contains(":") | Should -be $true - (Get-Date -DisplayHint Time).ToString().Contains(":") | Should -be $true - (Get-Date -DisplayHint Date).ToString().Contains(":") | Should -be $true + (Get-Date).ToString().Contains(":") | Should -BeTrue + (Get-Date -DisplayHint Time).ToString().Contains(":") | Should -BeTrue + (Get-Date -DisplayHint Date).ToString().Contains(":") | Should -BeTrue } It "Should be able to use the format flag" { # You would think that one could use simple loops here, but apparently powershell in Windows returns different values in loops - (Get-Date -Format d).Contains("/") | Should -be $true - (Get-Date -Format D).Contains(",") | Should -be $true - (Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should -be $true - (Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should -be $true - (Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should -be $true - (Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should -be $true + (Get-Date -Format d).Contains("/") | Should -BeTrue + (Get-Date -Format D).Contains(",") | Should -BeTrue + (Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should -BeTrue + (Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should -BeTrue + (Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should -BeTrue + (Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should -BeTrue (Get-Date -Format m).Contains(",") -or ` (Get-Date -Format m).Contains(":") -or ` - (Get-Date -Format m).Contains("/") | Should -be $false + (Get-Date -Format m).Contains("/") | Should -BeFalse } It "Should check that Get-Date can return the correct datetime from the system time" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 index b860edb6e44..16e819800b0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Get-Event" -Tags "CI" { } It "Should return Sender as Windows.timer" { - { (Get-Event -SourceIdentifier PesterTimer).Sender | Should -be Windows.timer } + { (Get-Event -SourceIdentifier PesterTimer).Sender | Should -Be Windows.timer } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 index 086d156460c..2dba372027f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 @@ -189,7 +189,7 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { for ($i = 0;$i -lt $methodList.Length;$i++) { - $methodFound[$i] | Should -Be $true + $methodFound[$i] | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 index 90de2f4debc..68b2c55e618 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSBreakpoint.Tests.ps1 @@ -19,7 +19,7 @@ Describe "Get-PSBreakpoint" -Tags "CI" { # so we can't check against a specific number # however, we can be sure that we're getting an int and that the int is # greater or equal to 0 - ([int]$Id) -ge 0 | should -be $true + ([int]$Id) -ge 0 | Should -BeTrue } It "should be able to get PSBreakpoint with using Variable switch" { @@ -28,7 +28,7 @@ Describe "Get-PSBreakpoint" -Tags "CI" { { Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath } | Should -Not -Throw $Id = (Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath).Variable - $Id | Should -be $scriptName + $Id | Should -Be $scriptName } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 index e956498669c..3a88280463d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 @@ -45,21 +45,21 @@ Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" { $results = & "$scriptFilePath" $results.Count | Should -BeGreaterThan 3 - $results[0].Command | Should -be "bar" - $results[0].ScriptName | Should -be $scriptFilePath - $results[0].ScriptLineNumber | Should -be 27 - $results[0].InvocationInfo.ScriptLineNumber | Should -be 9 + $results[0].Command | Should -Be "bar" + $results[0].ScriptName | Should -Be $scriptFilePath + $results[0].ScriptLineNumber | Should -Be 27 + $results[0].InvocationInfo.ScriptLineNumber | Should -Be 9 - $results[1].Command | Should -be "foo" - $results[1].ScriptName | Should -be $scriptFilePath - $results[1].ScriptLineNumber | Should -be 9 - $results[1].InvocationInfo.ScriptLineNumber | Should -be 32 + $results[1].Command | Should -Be "foo" + $results[1].ScriptName | Should -Be $scriptFilePath + $results[1].ScriptLineNumber | Should -Be 9 + $results[1].InvocationInfo.ScriptLineNumber | Should -Be 32 #InvocationInfo.ScriptLineNumber: Gets the line number of the script that contains the command - $results[2].Command | Should -be $scriptFileName - $results[2].ScriptName | Should -be $scriptFilePath - $results[2].ScriptLineNumber | Should -be 32 - $results[2].InvocationInfo.ScriptLineNumber | Should -be 46 + $results[2].Command | Should -Be $scriptFileName + $results[2].ScriptName | Should -Be $scriptFilePath + $results[2].ScriptLineNumber | Should -Be 32 + $results[2].InvocationInfo.ScriptLineNumber | Should -Be 46 } It "Verify that the script block of a trap statement shows up on the call stack" { @@ -76,14 +76,14 @@ Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" { $fileStream > $scriptFilePath $results = & "$scriptFilePath" $results.Count | Should -BeGreaterThan 2 - $results[0].Command | Should -be $scriptFileName - $results[0].ScriptName | Should -be $scriptFilePath - $results[0].ScriptLineNumber | Should -be 3 - $results[0].InvocationInfo.ScriptLineNumber | Should -be 77 + $results[0].Command | Should -Be $scriptFileName + $results[0].ScriptName | Should -Be $scriptFilePath + $results[0].ScriptLineNumber | Should -Be 3 + $results[0].InvocationInfo.ScriptLineNumber | Should -Be 77 - $results[1].Command | Should -be $scriptFileName - $results[1].ScriptName | Should -be $scriptFilePath - $results[1].ScriptLineNumber | Should -be 7 - $results[1].InvocationInfo.ScriptLineNumber | Should -be 77 + $results[1].Command | Should -Be $scriptFileName + $results[1].ScriptName | Should -Be $scriptFilePath + $results[1].ScriptLineNumber | Should -Be 7 + $results[1].InvocationInfo.ScriptLineNumber | Should -Be 77 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 index 0ab9f1e0444..6ce8e40430f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 @@ -115,7 +115,7 @@ Describe "Get-Random" -Tags "CI" { It "Should return same number for both Get-Random when switch SetSeed is used " { $firstRandomNumber = Get-Random -Maximum 100 -SetSeed 23 $secondRandomNumber = Get-Random -Maximum 100 -SetSeed 23 - $firstRandomNumber | Should -be $secondRandomNumber + $firstRandomNumber | Should -Be $secondRandomNumber } It "Should return a number from 1,2,3,5,8,13 " { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 index b282b9bc702..e558ba5d1fb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-TraceSource.Tests.ps1 @@ -3,6 +3,6 @@ Describe "Get-TraceSource" -Tags "Feature" { It "Should output data sorted by name" { $expected = (Get-TraceSource | Sort-Object Name) - Get-TraceSource | Should -be $expected + Get-TraceSource | Should -Be $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index 77e9f8e58dd..c09d6101d97 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Get-Uptime" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + $_.FullyQualifiedErrorId | Should -Be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" } finally { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 index 9bdfaf1761d..170f219df52 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -33,7 +33,7 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Set-Variable bcdaVar "another test" Set-Variable aVarfoo wow $var1=get-variable -Name *aVar* -Scope local - $var1.Count | Should -be 3 + $var1.Count | Should -Be 3 $var1[0].Name|Should -Be "abcaVar" $var1[0].Value|Should -Be "testing" $var1[1].Name|Should -Be "aVarfoo" @@ -49,7 +49,7 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } } @@ -60,12 +60,12 @@ Describe "Get-Variable" -Tags "CI" { } It "Should return environment variables when called with no parameters" { - (Get-Variable).Name -contains "$" | Should -Be $true - (Get-Variable).Name -contains "?" | Should -Be $true - (Get-Variable).Name -contains "HOST" | Should -Be $true - (Get-Variable).Name -contains "PWD" | Should -Be $true - (Get-Variable).Name -contains "PID" | Should -Be $true - (Get-Variable).Name -contains "^" | Should -Be $true + (Get-Variable).Name -contains "$" | Should -BeTrue + (Get-Variable).Name -contains "?" | Should -BeTrue + (Get-Variable).Name -contains "HOST" | Should -BeTrue + (Get-Variable).Name -contains "PWD" | Should -BeTrue + (Get-Variable).Name -contains "PID" | Should -BeTrue + (Get-Variable).Name -contains "^" | Should -BeTrue } It "Should return the value of an object" { @@ -87,8 +87,8 @@ Describe "Get-Variable" -Tags "CI" { New-Variable -Name var1 -Value 4 New-Variable -Name var2 -Value "test" - (Get-Variable -Name var*).Value[0] | Should -be 4 - (Get-Variable -Name var*).Value[1] | Should -be "test" + (Get-Variable -Name var*).Value[0] | Should -Be 4 + (Get-Variable -Name var*).Value[1] | Should -Be "test" Remove-Variable var1 Remove-Variable var2 @@ -97,7 +97,7 @@ Describe "Get-Variable" -Tags "CI" { It "Should return only the value if the value switch is used" { New-Variable -Name var1 -Value 4 - Get-Variable -Name var1 -ValueOnly | Should -be 4 + Get-Variable -Name var1 -ValueOnly | Should -Be 4 Remove-Variable var1 } @@ -133,7 +133,7 @@ Describe "Get-Variable" -Tags "CI" { $actual = Get-Variable -Exclude var1, var2 - $actual.Name -contains "var3" | Should -Be $true + $actual.Name -contains "var3" | Should -BeTrue } Context "Scope Tests" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 index 7c13a51859b..aef91e3d389 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 @@ -3,30 +3,30 @@ Describe "Get-Verb" -Tags "CI" { It "Should get a list of Verbs" { - Get-Verb | Should -not -be $null + Get-Verb | Should -Not -BeNullOrEmpty } It "Should get a specific verb" { - @(Get-Verb -Verb Add).Count | Should -be 1 - @(Get-Verb -Verb Add -Group Common).Count | Should -be 1 + @(Get-Verb -Verb Add).Count | Should -Be 1 + @(Get-Verb -Verb Add -Group Common).Count | Should -Be 1 } It "Should get a specific group" { - (Get-Verb -Group Common).Group | Sort-Object -Unique | Should -be Common + (Get-Verb -Group Common).Group | Sort-Object -Unique | Should -Be Common } It "Should not return duplicate Verbs with Verb paramater" { $dups = Get-Verb -Verb Add,ad*,a* $unique = $dups | Select-Object -Property * -Unique - $dups.Count | Should -be $unique.Count + $dups.Count | Should -Be $unique.Count } It "Should not return duplicate Verbs with Group paramater" { $dupVerbs = Get-Verb -Group Data,Data $uniqueVerbs = $dupVerbs | Select-Object -Property * -Unique - $dupVerbs.Count | Should -be $uniqueVerbs.Count + $dupVerbs.Count | Should -Be $uniqueVerbs.Count } It "Should filter using the Verb parameter" { @@ -39,7 +39,7 @@ Describe "Get-Verb" -Tags "CI" { throw "Expected error did not occur" } Catch{ - $PSItem.FullyQualifiedErrorId | Should -be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' + $PSItem.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index 66acd8b5592..f18dd0035f6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -100,7 +100,7 @@ try It "Verifies that Import-PSSession works in AllSigned if Certificate is used" -Skip:($skipTest -or $skipThisTest) { try { $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -Certificate $cert -AllowClobber - $importedModule | Should -Not -Be $null + $importedModule | Should -Not -BeNullOrEmpty } finally { $importedModule | Remove-Module -Force -ErrorAction SilentlyContinue } @@ -206,7 +206,7 @@ try $module = Import-PSSession $session -CommandName:BrokenAlias -CommandType:All -ErrorAction SilentlyContinue -ErrorVariable expectedError -AllowClobber $expectedError | Should -Not -Be NullOrEmpty - $expectedError[0].ToString().Contains("BrokenAlias") | Should -Be $true + $expectedError[0].ToString().Contains("BrokenAlias") | Should -BeTrue } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { Remove-Item alias:BrokenAlias } @@ -231,7 +231,7 @@ try ($results[1]).Value | Should -Not -Be $PID # Verifies that returned PID is not for this session $errorString = $results[0] | Out-String # Verifies error message for variable blah - ($errorString -like "*VariableNotFound*") | Should -Be $true + ($errorString -like "*VariableNotFound*") | Should -BeTrue } It "Test terminating error" { @@ -240,7 +240,7 @@ try $results.Count | Should -Be 1 # Verifies that remote session pid is not returned $errorString = $results[0] | Out-String # Verifes error message for incorrect Scope parameter argument - ($errorString -like "*Argument*") | Should -Be $true + ($errorString -like "*Argument*") | Should -BeTrue } } @@ -333,15 +333,15 @@ try } It "Verifies Export-PSSession creates a psd1 file" { - ($results | Where-Object { $_.Name -like "*$(Split-Path -Leaf $file).psd1" }) | Should -Be $true + ($results | Where-Object { $_.Name -like "*$(Split-Path -Leaf $file).psd1" }) | Should -BeTrue } It "Verifies Export-PSSession creates a psm1 file" { - ($results | Where-Object { $_.Name -like "*.psm1" }) | Should -Be $true + ($results | Where-Object { $_.Name -like "*.psm1" }) | Should -BeTrue } It "Verifies Export-PSSession creates a ps1xml file" { - ($results | Where-Object { $_.Name -like "*.ps1xml" }) | Should -Be $true + ($results | Where-Object { $_.Name -like "*.ps1xml" }) | Should -BeTrue } It "Verifies that Export-PSSession fails when a module directory already exists" { @@ -351,7 +351,7 @@ try $expectedError | Should -Not -Be NullOrEmpty # Error contains reference to the directory that already exists - ([string]($expectedError[0]) -like "*$file*") | Should -Be $true + ([string]($expectedError[0]) -like "*$file*") | Should -BeTrue } It "Verifies that overwriting an existing directory succeeds with -Force" { @@ -431,7 +431,7 @@ try It "Verifies Remove-Module removed the runspace that was automatically created" -Pending { Remove-Module $module -Force - (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -Be $null + (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { @@ -466,7 +466,7 @@ try # removing the module should remove the implicitly/magically created runspace It "Verifies Remove-Module removes automatically created runspace" -Pending { Remove-Module $module -Force - (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -Be $null + (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Closed" @@ -681,7 +681,7 @@ try # Should get 2 deserialized S.M.A.H.Coordinates objects $results.Count | Should -Be 2 # First object shouldn't have the additional ETS note property - $results[0].MyTestLabel | Should -Be $null + $results[0].MyTestLabel | Should -BeNullOrEmpty # Second object should have the additional ETS note property $results[1].MyTestLabel | Should -Be 123 } @@ -777,7 +777,7 @@ try } It "Helper functions should not be imported" { - (Get-Item function:*PSImplicitRemoting* -ErrorAction SilentlyContinue) | Should -Be $null + (Get-Item function:*PSImplicitRemoting* -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } It "Calls implicit remoting proxies 'MyFunction'" { @@ -818,11 +818,11 @@ try } It "Temporary module should be automatically removed after runspace is closed" { - (Get-Module | Where-Object { $_.Path -eq $module.Path }) | Should -Be $null + (Get-Module | Where-Object { $_.Path -eq $module.Path }) | Should -BeNullOrEmpty } It "Temporary psm1 file should be automatically removed after runspace is closed" { - (Get-Item $module.Path -ErrorAction SilentlyContinue) | Should -Be $null + (Get-Item $module.Path -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } It "Event should be unregistered when the runspace is closed" { @@ -1339,8 +1339,8 @@ try $job = Get-Variable -Name PID -AsJob $job | Should -Not -Be NullOrEmpty - ($job -is [System.Management.Automation.Job]) | Should -Be $true - ($job.Finished.WaitOne([TimeSpan]::FromSeconds(10), $false)) | Should -Be $true + ($job -is [System.Management.Automation.Job]) | Should -BeTrue + ($job.Finished.WaitOne([TimeSpan]::FromSeconds(10), $false)) | Should -BeTrue $job.JobStateInfo.State | Should -Be 'Completed' $childJob = $job.ChildJobs[0] @@ -1502,7 +1502,7 @@ try -Force $session = New-RemoteSession -ConfigurationName $myConfiguration.Name - $session | Should -Not -Be $null + $session | Should -Not -BeNullOrEmpty } AfterAll { @@ -1578,15 +1578,15 @@ try } It "PSModuleInfo.Name shouldn't contain a psd1 extension" { - ($module.Name -notlike '*.psd1') | Should -Be $true + ($module.Name -notlike '*.psd1') | Should -BeTrue } It "PSModuleInfo.Name shouldn't contain a psm1 extension" { - ($module.Name -notlike '*.psm1') | Should -Be $true + ($module.Name -notlike '*.psm1') | Should -BeTrue } It "PSModuleInfo.Name shouldn't contain a path" { - ($module.Name -notlike "${env:TMP}*") | Should -Be $true + ($module.Name -notlike "${env:TMP}*") | Should -BeTrue } It "Get-Command returns only 1 public command from implicit remoting module (1)" { @@ -1667,7 +1667,7 @@ try $expectedError | Should -Not -Be NullOrEmpty $msg = [string]($expectedError[0]) - $msg.Contains("blah") | Should -Be $true + $msg.Contains("blah") | Should -BeTrue } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1683,7 +1683,7 @@ try $expectedError | Should -Not -Be NullOrEmpty $msg = [string]($expectedError[0]) - $msg.Contains("notRequested") | Should -Be $true + $msg.Contains("notRequested") | Should -BeTrue } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1699,7 +1699,7 @@ try throw "Import-PSSession should throw" } catch { $msg = [string]($_) - $msg.Contains("Get-Command") | Should -Be $true + $msg.Contains("Get-Command") | Should -BeTrue } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } Invoke-Command $session { ${function:Get-Command} = $oldGetCommand } @@ -1740,7 +1740,7 @@ try if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } - (Get-Item function:Get-MyVariable -ErrorAction SilentlyContinue) | Should -Be $null + (Get-Item function:Get-MyVariable -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } Context "BadVerbs of functions should trigger a warning" { @@ -1779,13 +1779,13 @@ try $getVariablePid | Should -Be $remotePid ## Get-Variable function should not be exported when importing a BadVerb-Variable function - Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -Be $null + Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -BeNullOrEmpty ## BadVerb-Variable should be a function, not an alias (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty ## BadVerb-Variable should be a function, not an alias (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -BeNullOrEmpty (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { @@ -1819,13 +1819,13 @@ try $getVariablePid | Should -Be $remotePid ## Get-Variable function should not be exported when importing a BadVerb-Variable function - Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -Be $null + Get-Item Function:\Get-Variable -ErrorAction SilentlyContinue | Should -BeNullOrEmpty ## BadVerb-Variable should be a function, not an alias (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty ## BadVerb-Variable should be a function, not an alias (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -BeNullOrEmpty (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { @@ -1870,10 +1870,10 @@ try $getVariablePid | Should -Be $remotePid ## BadVerb-Variable should be an alias, not a function (1) - Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Be $null + Get-Item Function:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -BeNullOrEmpty ## BadVerb-Variable should be an alias, not a function (2) - Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -Be $null + Get-Item Alias:\BadVerb-Variable -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty (BadVerb-Variable -Name pid).Value | Should -Be $remotePid } finally { @@ -1929,11 +1929,11 @@ try $result = $ps.AddScript(" & $tempdir\TestBug450687.ps1").Invoke() ## The module created by Export-PSSession is imported successfully - ($null -ne $result -and $result.Count -eq 1 -and $result[0].Name -eq "Diag") | Should -Be $true + ($null -ne $result -and $result.Count -eq 1 -and $result[0].Name -eq "Diag") | Should -BeTrue ## The command Add-BitsFile is imported successfully $c = $result[0].ExportedCommands["New-Guid"] - ($null -ne $c -and $c.CommandType -eq "Function") | Should -Be $true + ($null -ne $c -and $c.CommandType -eq "Function") | Should -BeTrue } finally { $ps.Dispose() } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 index 50225ddca0f..7a774c96cec 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" } } @@ -42,7 +42,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" } } @@ -53,7 +53,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" } } @@ -98,6 +98,6 @@ Describe "Import-Alias" -Tags "CI" { It "Should be able to use ipal alias to import an alias file and perform cmd" { (ipal $pesteraliasfile) - (pesterecho pestertesting) | Should -be "pestertesting" + (pesterecho pestertesting) | Should -Be "pestertesting" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 index 72fa60aa335..e5bbb401b28 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 @@ -16,22 +16,22 @@ $culture = Get-Culture $culture.Name | Should -Be "en-US" $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -$d.d0 | Should -be $sunday +$d.d0 | Should -Be $sunday } It "Should be able to import string using en-US culture" { $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US - $d.d0 | Should -be $sunday + $d.d0 | Should -Be $sunday } It "Should be able to import string using de-DE culture" { $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE - $d.d0 | Should -be $sundayInGerman + $d.d0 | Should -Be $sundayInGerman } It "Should be able to import string and store in binding variable" { Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d - $d.d0 | Should -be $sundayInGerman + $d.d0 | Should -Be $sundayInGerman } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 index 271ab6f9e58..9400c97ed9e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ImportExportCSV.Delimiter.Tests.ps1 @@ -54,10 +54,10 @@ Describe "Using delimiters with Export-CSV and Import-CSV behave correctly" -tag $a = [pscustomobject]@{ a = 1; b = 2; c = 3 } $a | export-Csv TESTDRIVE:/file.csv $b = import-csv TESTDRIVE:/file.csv - @($b.psobject.properties).count | should -be 3 - $b.a | Should -be $a.a - $b.b | Should -be $a.b - $b.c | Should -be $a.c + @($b.psobject.properties).count | Should -Be 3 + $b.a | Should -Be $a.a + $b.b | Should -Be $a.b + $b.c | Should -Be $a.c } # parameter generated tests diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 index 0d7b76743b1..9700a514b92 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 @@ -5,7 +5,7 @@ Describe "Invoke-Expression" -Tags "CI" { Context "Should execute the invoked command validly" { It "Should return the echoed text" { - (Invoke-Expression -command "echo pestertest1") | Should -be "pestertest1" + (Invoke-Expression -command "echo pestertest1") | Should -Be "pestertest1" } It "Should return the echoed text from a script" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 index 6c820847860..b45132e9a3e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 @@ -217,6 +217,6 @@ Describe "Invoke-Item tests on Windows" -Tags "CI","RequireAdminOnWindows" { It "Should start a file without error on Windows full SKUs" -Skip:(-not $isFullWin) { Start-Process $testfilepath -Wait - Test-Path $renamedtestfilepath | Should -Be $true + Test-Path $renamedtestfilepath | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 index 2c3d2d6c412..9991a35d793 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 @@ -44,7 +44,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Not throw when json contains empty key name when ReturnHashTable is true' { $errorRecord = $null $result = [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, $true, [ref]$errorRecord) - $result | Should -Not -Be $null + $result | Should -Not -BeNullOrEmpty $result.Count | Should -Be 1 $result.'' | Should -Be 'Value' } @@ -61,7 +61,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Not throw when json contains key (same casing) when ReturnHashTable is true' { $errorRecord = $null $result = [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, $true, [ref]$errorRecord) - $result | Should -Not -Be $null + $result | Should -Not -BeNullOrEmpty $result.Count | Should -Be 2 $result.key1 | Should -Be 'Value1' $result.Key1 | Should -Be 'Value2' diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 index 6075ff4fa86..3ca0cfd884c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 @@ -7,7 +7,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMdd}" -f $date $actualFormat = Get-Date -Date $date -Format FileDate - $actualFormat | Should -be $expectedFormat + $actualFormat | Should -Be $expectedFormat } It "Verifies that FileDateUniversal format works" { @@ -15,7 +15,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddZ}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateUniversal - $actualFormat | Should -be $expectedFormat + $actualFormat | Should -Be $expectedFormat } It "Verifies that FileDateTime format works" { @@ -23,7 +23,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddTHHmmssffff}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateTime - $actualFormat | Should -be $expectedFormat + $actualFormat | Should -Be $expectedFormat } It "Verifies that FileDateTimeUniversal format works" { @@ -31,7 +31,7 @@ Describe "GetDateFormatUpdates" -Tags "Feature" { $expectedFormat = "{0:yyyyMMddTHHmmssffffZ}" -f $date $actualFormat = Get-Date -Date $date -Format FileDateTimeUniversal - $actualFormat | Should -be $expectedFormat + $actualFormat | Should -Be $expectedFormat } } @@ -51,6 +51,6 @@ Describe "GetRandomMiscTests" -Tags "Feature" { $hadError = $true } - $hadError | Should -be $false + $hadError | Should -BeFalse } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 7dab11be0da..9d749dafe7c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -9,7 +9,7 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 index bb5d2538cd3..aed16882ae4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 @@ -18,7 +18,7 @@ Describe "New-Event" -Tags "CI" { It "Should return Sender as Windows.timer" { (New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage") - (Get-Event -SourceIdentifier PesterTimer).Sender | Should -be Windows.timer + (Get-Event -SourceIdentifier PesterTimer).Sender | Should -Be Windows.timer Remove-Event -sourceIdentifier PesterTimer } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index 2508a616e35..f6e85c2fc30 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -6,7 +6,7 @@ Describe "New-Object" -Tags "CI" { { New-Object -ComObject "Shell.Application" } | ShouldBeErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } else { # It works on NanoServer and IoT too - (Get-Command "New-Object").Parameters.ContainsKey("ComObject") | Should -Be $true + (Get-Command "New-Object").Parameters.ContainsKey("ComObject") | Should -BeTrue } } @@ -19,8 +19,8 @@ Describe "New-Object" -Tags "CI" { $val.IsSerializable | Should -Not -BeNullOrEmpty $val.BaseType | Should -Not -BeNullOrEmpty - $val.IsPublic | Should -Be $true - $val.IsSerializable | Should -Be $false + $val.IsPublic | Should -BeTrue + $val.IsSerializable | Should -BeFalse $val.Name | Should -Be 'PSCustomObject' $val.BaseType | Should -Be 'System.Object' } @@ -92,7 +92,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -105,7 +105,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodException" - $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -119,7 +119,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodInvocationException" - $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -136,7 +136,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodException" - $_.FullyQualifiedErrorId | Should -be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -153,7 +153,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -167,7 +167,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -199,12 +199,12 @@ try It "Should be able to create with property of Type " -TestCases $testCases { param($Name, $Property, $Type) $comObject = New-Object -ComObject $name - $comObject.$Property | should -not -be $null - $comObject.$Property | should -beoftype $Type + $comObject.$Property | Should -Not -BeNullOrEmpty + $comObject.$Property | Should -Beoftype $Type } It "Should fail with correct error when creating a COM object that dose not exist" { - {New-Object -ComObject 'doesnotexist'} | shouldBeErrorId 'NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand' + {New-Object -ComObject 'doesnotexist'} | ShouldBeErrorId 'NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 73fc0011002..912191fe7a3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -131,7 +131,7 @@ Describe "New-Variable" -Tags "CI" { } It "Should default to none as the value for options" { - (new-variable -name var2 -value 4 -passthru).Options | should -be "None" + (new-variable -name var2 -value 4 -passthru).Options | Should -Be "None" } It "Should be able to set ReadOnly option" { @@ -155,7 +155,7 @@ Describe "New-Variable" -Tags "CI" { Set-Variable -Name var1 -Option Constant -ErrorAction SilentlyContinue - (Get-Variable var1).Options | should -be "None" + (Get-Variable var1).Options | Should -Be "None" } It "Should not be able to delete a constant variable" { @@ -228,16 +228,16 @@ Describe "New-Variable" -Tags "CI" { } It "Should be able to create a global scope variable using the global switch" { new-variable -Scope global -name globalvar1 -value 1 - get-variable -Scope global -name globalVar1 -ValueOnly | Should -be 1 + get-variable -Scope global -name globalVar1 -ValueOnly | Should -Be 1 } It "Should be able to create a local scope variable using the local switch" { - Get-Variable -scope local -name localvar -ValueOnly -ea silentlycontinue | should -BeNullOrEmpty + Get-Variable -scope local -name localvar -ValueOnly -ea silentlycontinue | Should -BeNullOrEmpty New-Variable -Scope local -Name localVar -value 10 - get-variable -scope local -name localvar -ValueOnly | Should -be 10 + get-variable -scope local -name localvar -ValueOnly | Should -Be 10 } It "Should be able to create a script scope variable using the script switch" { new-variable -scope script -name scriptvar -value 100 - get-variable -scope script -name scriptvar -ValueOnly | should -be 100 + get-variable -scope script -name scriptvar -ValueOnly | Should -Be 100 } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 index 7e3bc97c36d..46c7bc65602 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 @@ -29,7 +29,7 @@ Describe "New-TemporaryFile" -Tags "CI" { } It "with WhatIf does not create a file" { - New-TemporaryFile -WhatIf | Should -Be $null + New-TemporaryFile -WhatIf | Should -BeNullOrEmpty } It "has an OutputType of System.IO.FileInfo" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index 9b8f2f7b060..b120014e2d5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -5,7 +5,7 @@ Describe "Out-File DRT Unit Tests" -Tags "CI" { $tempFile = Join-Path -Path $TestDrive -ChildPath "ExposeBug928965" { 1 | Out-File -PSPath $tempFile } | Should -Not -Throw $fileContents = Get-Content $tempFile - $fileContents | Should -be 1 + $fileContents | Should -Be 1 Remove-Item $tempFile -Force } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 index e4f7f03f706..c888714a35f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 @@ -6,8 +6,8 @@ Describe "Out-String DRT Unit Tests" -Tags "CI" { $results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string $results.Length | Should -BeGreaterThan 1 $results | Should -BeOfType "System.String" - $results.Contains("myvalue") | Should -Be $true - $results.Contains("name with square brackets: [0]") | Should -Be $true + $results.Contains("myvalue") | Should -BeTrue + $results.Contains("name with square brackets: [0]") | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index bcb1769ddf9..414743f2b85 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -20,9 +20,9 @@ Describe "Json Tests" -Tags "Feature" { $result.SampleInt | Should -Be 98765 $result.SampleString | Should -Match "stringVal" $result.SampleArray.Count | Should -Be 2 - $result.SampleTrue | Should -Be $true - $result.SampleFalse | Should -Be $false - $result.SampleNull | Should -Be $null + $result.SampleTrue | Should -BeTrue + $result.SampleFalse | Should -BeFalse + $result.SampleNull | Should -BeNullOrEmpty $result.SampleFloat | Should -Be 9.8765E+43 if ($hasEmbeddedSampleObject) @@ -50,7 +50,7 @@ Describe "Json Tests" -Tags "Feature" { } catch { - $_.FullyQualifiedErrorId | should -be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId } } @@ -209,7 +209,7 @@ Describe "Json Tests" -Tags "Feature" { It "Convert from Json allows an empty string" { $emptyStringResult = ConvertFrom-Json "" - $emptyStringResult | Should -Be $null + $emptyStringResult | Should -BeNullOrEmpty } It "Convert enumerated values to Json" { @@ -261,7 +261,7 @@ Describe "Json Tests" -Tags "Feature" { $json.Rev | Should -Be $json.Revision # Check the ScriptProperty - $json.IsOld | Should -Be $true + $json.IsOld | Should -BeTrue } It "ConvertFrom-Json with a key value pair" { @@ -1436,7 +1436,7 @@ Describe "Json Bug fixes" -Tags "Feature" { { $theError = $_ } - $theError | Should -Be $null + $theError | Should -BeNullOrEmpty } } } @@ -1480,12 +1480,12 @@ Describe "Json Bug fixes" -Tags "Feature" { # Read the object as an array of PSObjects and deserialize it. $result = Get-Content $filePath | ConvertFrom-Json - $result.Count | Should -be 2 + $result.Count | Should -Be 2 } It "ConvertFrom-Json deserializes an array of strings (in multiple lines) as a single string." { $result = "[1,","2,","3]" | ConvertFrom-Json - $result.Count | Should -be 3 + $result.Count | Should -Be 3 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 index 0516bea67e5..e5af81b01e9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Read-Host Test" -tag "CI" { It "Read-Host sets the prompt correctly" { $result = $ps.AddScript("Read-Host -prompt myprompt").Invoke() $prompt = $th.ui.streams.prompt[0] - $prompt | should -Not -BeNullOrEmpty - $prompt.split(":")[-1] | should -be myprompt + $prompt | Should -Not -BeNullOrEmpty + $prompt.split(":")[-1] | Should -Be myprompt } It "Read-Host returns a secure string when using -AsSecureString parameter" { $result = $ps.AddScript("Read-Host -AsSecureString").Invoke() | select-object -first 1 $result | Should -BeOfType SecureString - [pscredential]::New("foo",$result).GetNEtworkCredential().Password | should -BeExactly TEST + [pscredential]::New("foo",$result).GetNEtworkCredential().Password | Should -BeExactly TEST } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 index 6e06636d04c..f2cda04e3ae 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 @@ -53,7 +53,7 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { $ps.AddScript("(Get-TypeData System.Int32).TypeName").Invoke() | Should -Be System.Int32 $ps.Commands.Clear() $null = $ps.AddScript("'int' | Remove-TypeData").Invoke() - $ps.HadErrors | Should -be $false + $ps.HadErrors | Should -BeFalse } It "Remove Type File In Initial Session State" { @@ -65,7 +65,7 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { $null = $ps.AddScript('$a = 1..3').Invoke() $ps.Commands.Clear() # test - $ps.AddScript('$a.Yada').Invoke() | Should -be 3 + $ps.AddScript('$a.Yada').Invoke() | Should -Be 3 $ps.Commands.Clear() $ps.AddScript('$a.Yoda').Invoke() | Should -Be 3 $ps.Commands.Clear() @@ -79,7 +79,7 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { It "Remove Type File In Initial Session State File Not In Cache" { $null = $ps.AddScript("Remove-TypeData -Path fakefile").Invoke() - $ps.HadErrors | Should -be $true + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorID | Should -Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index fe02af7059f..20e9dadcefe 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -80,7 +80,7 @@ Describe "Remove-Variable" -Tags "CI" { $tmpvar1 | Should -Be "tempvalue" $tmpvar2 | Should -Be 2 $tmpmyvar1 | Should -Be #nothing. it should be Nothing at all. - $thevar | should -Be 1 + $thevar | Should -Be 1 Remove-Variable tmpvar1 Remove-Variable tmpvar2 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 index 3807d49196c..27a60351dd8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/RunspaceCmdlets.Tests.ps1 @@ -8,19 +8,19 @@ Describe "Get-Runspace cmdlet tests" -Tag "CI" { } It "Get-Runspace should return the current runspace" { $runspace = get-runspace |Sort-Object -property id | Select-Object -first 1 - $runspace.InstanceId | Should -be $ExpectedInstanceId + $runspace.InstanceId | Should -Be $ExpectedInstanceId } It "Get-Runspace with runspace InstanceId should return the correct runspace" { $runspace = get-runspace -instanceid $CurrentRunspace.InstanceId - $runspace.InstanceId | Should -be $ExpectedInstanceId + $runspace.InstanceId | Should -Be $ExpectedInstanceId } It "Get-Runspace with runspace name should return the correct runspace" { $runspace = get-runspace -name $currentRunspace.Name - $runspace.InstanceId | Should -be $ExpectedInstanceId + $runspace.InstanceId | Should -Be $ExpectedInstanceId } It "Get-Runspace with runspace Id should return the correct runspace" { $runspace = get-runspace -id $CurrentRunspace.Id - $runspace.InstanceId | Should -be $ExpectedInstanceId + $runspace.InstanceId | Should -Be $ExpectedInstanceId } Context "Multiple Runspaces" { BeforeAll { @@ -36,8 +36,8 @@ Describe "Get-Runspace cmdlet tests" -Tag "CI" { It "Get-Runspace should return the new runspaces" { $result = get-runspace # if the ids don't match, we'll get null passed to should - $result.id | Where-Object {$_ -eq $r1.id } | should -be $r1.id - $result.id | Where-Object {$_ -eq $r2.id } | should -be $r2.id + $result.id | Where-Object {$_ -eq $r1.id } | Should -Be $r1.id + $result.id | Where-Object {$_ -eq $r2.id } | Should -Be $r2.id } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index 6f9883b721e..b29c6ac382a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -132,7 +132,7 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -be "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $_.FullyQualifiedErrorId | Should -Be "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" } } @@ -256,45 +256,45 @@ Describe "Select-Object with Property = '*'" -Tags "CI" { # Issue #2420 It "Select-Object with implicit Property = '*' don't return property named '*'"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -ExcludeProperty thing - $results.psobject.Properties.Item("*") | Should -Be $null + $results.psobject.Properties.Item("*") | Should -BeNullOrEmpty } # Issue #2420 It "Select-Object with explicit Property = '*' don't return property named '*'"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -Property * -ExcludeProperty thing - $results.psobject.Properties.Item("*") | Should -Be $null + $results.psobject.Properties.Item("*") | Should -BeNullOrEmpty } # Issue #2351 It "Select-Object with implicit Property = '*' exclude single property"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -ExcludeProperty thing - $results.psobject.Properties.Item("Thing") | Should -Be $null - $results.psobject.Properties.Item("*") | Should -Be $null + $results.psobject.Properties.Item("Thing") | Should -BeNullOrEmpty + $results.psobject.Properties.Item("*") | Should -BeNullOrEmpty } # Issue #2351 It "Select-Object with explicit Property = '*' exclude single property"{ $results = [pscustomobject]@{Thing="thing1"} | Select-Object -Property * -ExcludeProperty thing - $results.psobject.Properties.Item("Thing") | Should -Be $null - $results.psobject.Properties.Item("*") | Should -Be $null + $results.psobject.Properties.Item("Thing") | Should -BeNullOrEmpty + $results.psobject.Properties.Item("*") | Should -BeNullOrEmpty } # Issue #2351 It "Select-Object with implicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -ExcludeProperty Param2 - $results.Param2 | Should -Be $null + $results.Param2 | Should -BeNullOrEmpty $results.Thing | Should -Be "thing1" } # Issue #2351 It "Select-Object with explicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -Property * -ExcludeProperty Param2 - $results.Param2 | Should -Be $null + $results.Param2 | Should -BeNullOrEmpty $results.Thing | Should -Be "thing1" } It "Select-Object with ExpandProperty and Property don't skip processing ExcludeProperty" { $p = Get-Process -Id $pid | Select-Object -Property Process* -ExcludeProperty ProcessorAffinity -ExpandProperty Modules - $p[0].psobject.Properties.Item("ProcessorAffinity") | Should -Be $null + $p[0].psobject.Properties.Item("ProcessorAffinity") | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 index 8156c127cdf..431a2ac1e6d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-String.Tests.ps1 @@ -60,7 +60,7 @@ Describe "Select-String" -Tags "CI" { } it "Should be true when select string returns a positive result when the quiet switch is used" { - ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should -Be $True + ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should -BeTrue } it "Should be empty when select string does not return a result when the quiet switch is used" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index a00d9bbaf1f..680bb205a3c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -137,7 +137,7 @@ Describe "Basic Send-MailMessage tests" -Tags CI { $body = "Greetings from me." $subject = "Test message" Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1 - Test-Path -Path $mailBox | Should -Be $true + Test-Path -Path $mailBox | Should -BeTrue $mail = read-mail $mailBox $mail.From | Should -BeExactly $address $mail.To.Count | Should -BeExactly 1 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index 5347ed4de0a..a38eb882417 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" } } @@ -80,7 +80,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 823796dbe5e..8a23f6bfc4a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -74,7 +74,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable -Name foo $null -Description "new description" -PassThru:$true -Scope "local" $var1=Get-Variable -Name foo -Scope "local" $var1.Name|Should -Be "foo" - $var1.Value|Should -Be $null + $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" $var1.Description|Should -Be "new description" } @@ -96,7 +96,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } @@ -123,7 +123,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -139,7 +139,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 index 0a5e19a020a..1c2ce5ed842 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Sort-Object" -Tags "CI" { $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -First 1).Length $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -Last 1).Length - $firstLen -lt $lastLen | Should -be $true + $firstLen -lt $lastLen | Should -BeTrue } @@ -18,7 +18,7 @@ Describe "Sort-Object" -Tags "CI" { $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -First 1).Length $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -Last 1).Length - $firstLen -gt $lastLen | Should -be $true + $firstLen -gt $lastLen | Should -BeTrue } } @@ -234,7 +234,7 @@ Describe 'Sort-Object Top and Bottom Unit Tests' -Tags 'CI' { if ($nSortEntry -is [System.Array]) { # Arrays are compared using reference equality to ensure that the original array was # moved to the correct position in both sorts; value equality doesn't verify this - [object]::ReferenceEquals($nSortEntry, $fullSortEntry) | Should -Be $true + [object]::ReferenceEquals($nSortEntry, $fullSortEntry) | Should -BeTrue } else { $nSortEntry | Should -Be $fullSortEntry } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 index 2aad275703f..cdb36fd9a0f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Tee-Object DRT Unit Tests" -Tags "CI" { It "Positive File Test" { $expected = "1", "2", "3" $results = $expected | Tee-Object -FilePath $tempFile - $results.Length | Should -be 3 + $results.Length | Should -Be 3 $results | Should -Be $expected $content = Get-Content $tempFile $content | Should -Be $expected @@ -38,7 +38,7 @@ Describe "Tee-Object DRT Unit Tests" -Tags "CI" { It "Positive File Test with Path parameter alias" { $expected = "1", "2", "3" $results = $expected | Tee-Object -Path $tempFile - $results.Length | Should -be 3 + $results.Length | Should -Be 3 $results | Should -Be $expected $content = Get-Content $tempFile $content | Should -Be $expected @@ -48,11 +48,11 @@ Describe "Tee-Object DRT Unit Tests" -Tags "CI" { $expected = "1", "2", "3" $varName = "teeObjectTestVar" $results = $expected | Tee-Object -Variable $varName - $results.Length | Should -be 3 + $results.Length | Should -Be 3 $results | Should -Be $expected $results = Get-Variable -Name $varName -ValueOnly - $results.Length | Should -be 3 + $results.Length | Should -Be 3 $results | Should -Be $expected } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 index 6b4eb220dae..8242d13ec70 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Unblock-File.Tests.ps1 @@ -48,7 +48,7 @@ Describe "Unblock-File" -Tags "CI" { It "With '-Path': file exist" { Unblock-File -Path $testfilepath - Test-UnblockFile | Should -Be $true + Test-UnblockFile | Should -BeTrue # If a file is not blocked we silently return without an error. { Unblock-File -Path $testfilepath -ErrorAction Stop } | Should -Not -Throw @@ -56,7 +56,7 @@ Describe "Unblock-File" -Tags "CI" { It "With '-LiteralPath': file exist" { Unblock-File -LiteralPath $testfilepath - Test-UnblockFile | Should -Be $true + Test-UnblockFile | Should -BeTrue } It "Write an error if a file is read only" { @@ -70,7 +70,7 @@ Describe "Unblock-File" -Tags "CI" { Set-ItemProperty -Path $TestFile -Name IsReadOnly -Value $True $TestFileCreated = Get-ChildItem $TestFile - $TestFileCreated.IsReadOnly | Should -Be $true + $TestFileCreated.IsReadOnly | Should -BeTrue { Unblock-File -LiteralPath $TestFile -ErrorAction Stop } | ShouldBeErrorId "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.UnblockFileCommand" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 index caf82ac0ef3..43df9b2d24b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Update-FormatData" -Tags "CI" { Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path $path $null = $ps.AddScript("Update-FormatData -prependPath $path") $ps.Invoke() - $ps.HadErrors | Should -be $false + $ps.HadErrors | Should -BeFalse } } } @@ -115,7 +115,7 @@ Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { $ps.Invoke() $sma = [appdomain]::CurrentDomain.GetAssemblies() | ? { if ($_.Location) {$_.Location.EndsWith("System.Management.Automation.dll")}} $smaLocation = $sma.Location - $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should -be $true } + $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should -BeTrue } $ps.Streams.Error | %{ $_.FullyQualifiedErrorId | Should -Match 'FormatXmlUpdateException' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index 22be7858026..74c951708ba 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -51,8 +51,8 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid TypesXml should throw Exception" { $null = $ps.AddScript("Update-TypeData -PrependPath $testfile") $ps.Invoke() - $ps.HadErrors | Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorID | Should -be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors | Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorID | Should -Be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid File Extension should throw Exception"{ @@ -60,8 +60,8 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $xmlContent>$invalidFileExtensionFile $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") $ps.Invoke() - $ps.HadErrors | Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors | Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Dynamic Type NoteProperty with Force should work"{ @@ -69,7 +69,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke() | should -be 2 + $ps.Invoke() | Should -Be 2 $ps.Commands.Clear() $null = $ps.AddScript("Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value 'test' -TypeName System.String -Force") $ps.Invoke() @@ -151,29 +151,29 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid DynamicType Null Value For AliasProperty should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType AliasProperty -MemberName TestAlias -Value $null -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No MemberName should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -Value "Error" -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No Value should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with Empty TypeData should throw Exception"{ $null = $ps.AddScript("Update-TypeData -TypeName System.String") $ps.Invoke() - $ps.HadErrors |Should -be $true - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -be "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.HadErrors |Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Standard Members Serialization Method String should work"{ @@ -314,7 +314,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $ps.AddScript('$a.Yada').Invoke() | Should -Be 3 $ps.AddScript("Remove-TypeData -Path $testfile").Invoke() - $ps.HadErrors|Should -be $false + $ps.HadErrors|Should -BeFalse } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 7ebc639e813..409ed22238b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -383,18 +383,18 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { function ValidateResponse { param ($response) - $response.Error | Should -Be $null + $response.Error | Should -BeNullOrEmpty # A successful call returns: Status = 200, and StatusDescription = "OK" $response.Output.StatusDescription | Should -Match "OK" $response.Output.StatusCode | Should -Be 200 # Make sure the response contains the following properties: - $response.Output.RawContent | Should -Not -Be $null - $response.Output.Headers | Should -Not -Be $null - $response.Output.RawContent | Should -Not -Be $null - $response.Output.RawContentLength | Should -Not -Be $null - $response.Output.Content | Should -Not -Be $null + $response.Output.RawContent | Should -Not -BeNullOrEmpty + $response.Output.Headers | Should -Not -BeNullOrEmpty + $response.Output.RawContent | Should -Not -BeNullOrEmpty + $response.Output.RawContentLength | Should -Not -BeNullOrEmpty + $response.Output.Content | Should -Not -BeNullOrEmpty } #User-Agent changes on different platforms, so tests should only be run if on the correct platform @@ -2763,7 +2763,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { body = 'null' } $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -Be $null + Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty } It "Invoke-RestMethod Supports a Single Value JSON null and ignores whitespace" { @@ -2772,10 +2772,10 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { body = " null " } $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -Be $null + Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty $query['body'] = " null `n" $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -Be $null + Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 index 9fed5063426..648913ecd72 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.Tests.ps1 @@ -10,16 +10,16 @@ Describe "Write-Output DRT Unit Tests" -Tags "CI" { $results[1] | Should -Be $objectWritten[1] $results[2] | Should -Be $objectWritten[2] - $results[2] -is [System.Array] | Should -Be $true + $results[2] -is [System.Array] | Should -BeTrue $results[3] | Should -Be $objectWritten[3] - $results[3] -is [System.String] | Should -Be $true + $results[3] -is [System.String] | Should -BeTrue } It "Works with NoEnumerate switch" { $objectWritten = 1, 2.2, @("John", "Smith", 10), "abc" [string]$s = Write-Output $objectWritten -NoEnumerate 6>&1 - $s | Should -be '1 2.2 System.Object[] abc' + $s | Should -Be '1 2.2 System.Object[] abc' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 index 534fd4da9bb..3cc92e0151d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 @@ -94,15 +94,15 @@ Describe "Stream writer tests" -Tags "CI" { $result.User | Should -Be $(whoami) } - "$result" | Should -be "Test Message" + "$result" | Should -Be "Test Message" } It "Write-Information accept objects from pipe" { $ps.AddScript("'teststring',12345 | Write-Information -InformationAction Continue").Invoke() $result = $ps.Streams.Information - $result.Count | Should -be 2 - $result[0].MessageData | Should -be "teststring" - $result[1].MessageData | Should -be "12345" + $result.Count | Should -Be 2 + $result[0].MessageData | Should -Be "teststring" + $result[1].MessageData | Should -Be "12345" } It "Write-Information works with " -TestCases:$testInfoData { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 index 3971e0e8efa..2882d88f888 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 @@ -62,7 +62,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $null = $ps.BeginInvoke() Start-Sleep 1 $null = $ps.Stop() - $ps.InvocationStateInfo.State | should -be "Stopped" + $ps.InvocationStateInfo.State | Should -Be "Stopped" $ps.Dispose() } @@ -134,8 +134,8 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $out1 = Import-Clixml -Path $testfile # this results in a hashtable $out2 = Import-Clixml -Path $testfile -First 2 -Skip 1 # this results in a dictionary entry $out2.Count | Should -Be 2 - ($out2.Name) -join ":" | should -be (@($out1.Keys)[1, 2] -join ":") - ($out2.Value) -join ":" | should -be (@($out1.Values)[1, 2] -join ":") + ($out2.Name) -join ":" | Should -Be (@($out1.Keys)[1, 2] -join ":") + ($out2.Value) -join ":" | Should -Be (@($out1.Values)[1, 2] -join ":") } # these tests just cover aspects that aren't normally exercised being used as a cmdlet @@ -146,7 +146,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags "CI" { $cmd.LiteralPath = "foo" $cmd.LiteralPath | Should -BeExactly "foo" $cmd.NoClobber = $true - $cmd.NoClobber | Should -Be $true + $cmd.NoClobber | Should -BeTrue $cmd = [Microsoft.PowerShell.Commands.ImportClixmlCommand]::new() $cmd.LiteralPath = "bar" From 825809278fb03561e66633b639144a333a472ef8 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 08:51:44 -0700 Subject: [PATCH 03/21] [Feature] -BeNullOrEmpty instead of -Be in Utility module tests. --- .../Clear-Variable.Tests.ps1 | 16 ++++---- .../Export-FormatData.Tests.ps1 | 2 +- .../Get-Alias.Tests.ps1 | 38 +++++++++---------- .../New-Alias.Tests.ps1 | 4 +- .../New-Variable.Tests.ps1 | 6 +-- .../Out-File.Tests.ps1 | 28 +++++++------- .../Remove-Variable.Tests.ps1 | 2 +- .../Set-Alias.Tests.ps1 | 14 +++---- .../Set-Variable.Tests.ps1 | 18 ++++----- 9 files changed, 64 insertions(+), 64 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index 26b5a5af7c2..c5235bebe11 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Clear-Variable ReadOnly variable Name should throw exception and force Clear-Variable should works"{ @@ -28,7 +28,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "ReadOnly" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Clear-Variable normal variable Name with local scope should works"{ @@ -42,14 +42,14 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Clear-Variable Private variable Name should works and Get-Variable with local scope should throw exception"{ @@ -69,7 +69,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "Private" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Clear-Variable normal variable Name with local scope should works in different scope"{ @@ -82,20 +82,20 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty $var1=Get-Variable -Name foo -Scope "local" $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index eb5d0be2f9e..394b65972c9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Export-FormatData" -Tags "CI" { It "Should not return an empty xml file" { Get-FormatData | Export-FormatData -Path $testOutput $piped = Get-Content $testOutput - $piped | Should -Not -Be "" + $piped | Should -Not -BeNullOrEmpty } It "Should have a valid xml tag at the start of the file" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 98133a38cc9..53e4a537f14 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Get-Alias Positional Single Valid"{ @@ -33,7 +33,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Get-Alias Named Multiple Valid"{ @@ -42,11 +42,11 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD,AEFG $result[0].Name| Should -Be "ABCD" $result[0].Definition| Should -Be "foo" - $result[0].Description| Should -Be "" + $result[0].Description| Should -BeNullOrEmpty $result[0].Options| Should -Be "None" $result[1].Name| Should -Be "AEFG" $result[1].Definition| Should -Be "bar" - $result[1].Description| Should -Be "" + $result[1].Description| Should -BeNullOrEmpty $result[1].Options| Should -Be "None" } It "Get-Alias Named Wildcard Valid"{ @@ -55,11 +55,11 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABC* $result[0].Name| Should -Be "ABCD" $result[0].Definition| Should -Be "foo" - $result[0].Description| Should -Be "" + $result[0].Description| Should -BeNullOrEmpty $result[0].Options| Should -Be "None" $result[1].Name| Should -Be "ABCG" $result[1].Definition| Should -Be "bar" - $result[1].Description| Should -Be "" + $result[1].Description| Should -BeNullOrEmpty $result[1].Options| Should -Be "None" } It "Get-Alias Positional Wildcard Valid"{ @@ -68,11 +68,11 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias ABC* $result[0].Name| Should -Be "ABCD" $result[0].Definition| Should -Be "foo" - $result[0].Description| Should -Be "" + $result[0].Description| Should -BeNullOrEmpty $result[0].Options| Should -Be "None" $result[1].Name| Should -Be "ABCG" $result[1].Definition| Should -Be "bar" - $result[1].Description| Should -Be "" + $result[1].Description| Should -BeNullOrEmpty $result[1].Options| Should -Be "None" } It "Get-Alias Named Wildcard And Exclude Valid"{ @@ -81,7 +81,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABC* -Exclude "*BCG" $result[0].Name| Should -Be "ABCD" $result[0].Definition| Should -Be "foo" - $result[0].Description| Should -Be "" + $result[0].Description| Should -BeNullOrEmpty $result[0].Options| Should -Be "None" } It "Get-Alias Scope Valid"{ @@ -89,14 +89,14 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" Set-Alias -Name ABCD -Value "localfoo" -scope local $result=Get-Alias -Name ABCD -scope local $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "localfoo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" Set-Alias -Name ABCD -Value "globalfoo" -scope global @@ -107,37 +107,37 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo0" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope local $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo0" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope global $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "globalfoo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "script" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "scriptfoo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "0" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo0" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "1" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo1" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Get-Alias Expose Bug 1065828, BugId:905235"{ @@ -154,13 +154,13 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "0" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 9d749dafe7c..bd6191ba2f3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -18,7 +18,7 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD -Scope "0" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "MyCommand" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } @@ -27,7 +27,7 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD -Scope "0" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "MyCommand" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 912191fe7a3..630c7b115ea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -17,7 +17,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "Constant" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "New-Variable variable twice should throw Exception"{ @@ -36,7 +36,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "New-Variable ReadOnly variable twice should throw Exception"{ @@ -55,7 +55,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index b120014e2d5..7438bbaf55b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -65,7 +65,7 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile - $actual[0] | Should -Be "" + $actual[0] | Should -BeNullOrEmpty $actual[1] | Should -Match "text" $actual[2] | Should -Match "----" $actual[3] | Should -Match "some test text" @@ -77,18 +77,18 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile - $actual[0] | Should -Be "" + $actual[0] | Should -BeNullOrEmpty $actual[1] | Should -Match "text" $actual[2] | Should -Match "----" $actual[3] | Should -Match "some test text" - $actual[4] | Should -Be "" - $actual[5] | Should -Be "" - $actual[6] | Should -Be "" + $actual[4] | Should -BeNullOrEmpty + $actual[5] | Should -BeNullOrEmpty + $actual[6] | Should -BeNullOrEmpty $actual[7] | Should -Match "text" $actual[8] | Should -Match "----" $actual[9] | Should -Match "some test text" - $actual[10] | Should -Be "" - $actual[11] | Should -Be "" + $actual[10] | Should -BeNullOrEmpty + $actual[11] | Should -BeNullOrEmpty } It "Should limit each line to the specified number of characters when the width switch is used on objects" { @@ -97,7 +97,7 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile - $actual[0] | Should -Be "" + $actual[0] | Should -BeNullOrEmpty $actual[1] | Should -Be "text" $actual[2] | Should -Be "----" $actual[3] | Should -Be "some te..." @@ -113,18 +113,18 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile - $actual[0] | Should -Be "" + $actual[0] | Should -BeNullOrEmpty $actual[1] | Should -Match "text" $actual[2] | Should -Match "----" $actual[3] | Should -Match "some test text" - $actual[4] | Should -Be "" - $actual[5] | Should -Be "" - $actual[6] | Should -Be "" + $actual[4] | Should -BeNullOrEmpty + $actual[5] | Should -BeNullOrEmpty + $actual[6] | Should -BeNullOrEmpty $actual[7] | Should -Match "text" $actual[8] | Should -Match "----" $actual[9] | Should -Match "some test text" - $actual[10] | Should -Be "" - $actual[11] | Should -Be "" + $actual[10] | Should -BeNullOrEmpty + $actual[11] | Should -BeNullOrEmpty # reset to not read only so it can be deleted Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 20e9dadcefe..5eb895e177b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -269,7 +269,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { $var1.Name | Should -Be "foo" $var1.Value | Should -Be "bar" $var1.Options | Should -Be "None" - $var1.Description | Should -Be "" + $var1.Description | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index a38eb882417..b7aa0b82785 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -17,14 +17,14 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "ReadOnly" Set-Alias -Name ABCD -Value "foo" -Force:$true $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } @@ -33,7 +33,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "MyCommand" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Set-Alias Name And Value Positional Valid"{ @@ -41,7 +41,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Set-Alias Description Valid"{ @@ -59,19 +59,19 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { $result=Get-Alias -Name ABCD $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "localfoo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope local $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "localfoo" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" $result=Get-Alias -Name ABCD -scope "1" $result.Name| Should -Be "ABCD" $result.Definition| Should -Be "foo1" - $result.Description| Should -Be "" + $result.Description| Should -BeNullOrEmpty $result.Options| Should -Be "None" } It "Set-Alias Expose Bug 1062958, BugId:905449"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 8a23f6bfc4a..9519f674221 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Set-Variable normal variable Name with position should works"{ @@ -17,7 +17,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Set-Variable normal variable Name with scope should works"{ @@ -28,21 +28,21 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "foo" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty Set-Variable -Name foo -Value newValue -Scope "local" $var1=Get-Variable -Name foo -scope "local" $var1.Name|Should -Be "foo" $var1.Value|Should -Be "newValue" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty Set-Variable -Name foo -Value newValue2 -Scope "script" $var1=Get-Variable -Name foo -scope "script" $var1.Name|Should -Be "foo" $var1.Value|Should -Be "newValue2" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } It "Set-Variable normal variable Name with position should works"{ @@ -56,17 +56,17 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1[0].Name|Should -Be "abcaVar" $var1[0].Value|Should -Be "overwrite" $var1[0].Options|Should -Be "None" - $var1[0].Description|Should -Be "" + $var1[0].Description|Should -BeNullOrEmpty $var1[1].Name|Should -Be "aVarfoo" $var1[1].Value|Should -Be "overwrite" $var1[1].Options|Should -Be "None" - $var1[1].Description|Should -Be "" + $var1[1].Description|Should -BeNullOrEmpty $var1[2].Name|Should -Be "bcdaVar" $var1[2].Value|Should -Be "anotherVal" $var1[2].Options|Should -Be "None" - $var1[2].Description|Should -Be "" + $var1[2].Description|Should -BeNullOrEmpty } It "Set-Variable normal variable Name with Description and Value should works"{ @@ -159,7 +159,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Name|Should -Be "footest1" $var1.Value|Should -Be "bar" $var1.Options|Should -Be "None" - $var1.Description|Should -Be "" + $var1.Description|Should -BeNullOrEmpty } } From 9fbf48b6ef4f2c4267b856116440d25f6c9286b2 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 09:13:49 -0700 Subject: [PATCH 04/21] [Feature] Tests in module Utility correction. --- .../Add-Member.Tests.ps1 | 157 +++--------------- .../Clear-Variable.Tests.ps1 | 6 +- .../ConvertFrom-StringData.Tests.ps1 | 2 +- .../Debug-Runspace.Tests.ps1 | 8 +- .../Export-Alias.Tests.ps1 | 6 +- .../Format-Table.Tests.ps1 | 2 +- .../Format-Wide.Tests.ps1 | 2 +- .../Get-Alias.Tests.ps1 | 10 +- .../Get-FileHash.Tests.ps1 | 6 +- .../Get-Member.Tests.ps1 | 2 +- .../Get-Random.Tests.ps1 | 2 +- .../Get-Uptime.Tests.ps1 | 2 +- .../Get-Variable.Tests.ps1 | 6 +- .../Get-Verb.Tests.ps1 | 2 +- .../Implicit.Remoting.Tests.ps1 | 2 +- .../Import-Alias.Tests.ps1 | 6 +- .../JsonObject.Tests.ps1 | 4 +- .../New-Alias.Tests.ps1 | 2 +- .../New-Object.Tests.ps1 | 12 +- .../New-Variable.Tests.ps1 | 6 +- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 4 +- .../PowerShellData.tests.ps1 | 51 +----- .../Remove-Variable.Tests.ps1 | 12 +- .../Select-Object.Tests.ps1 | 2 +- .../Set-Alias.Tests.ps1 | 4 +- .../Set-PSBreakpoint.Tests.ps1 | 4 +- .../Set-Variable.Tests.ps1 | 6 +- .../Update-TypeData.Tests.ps1 | 2 +- .../WebCmdlets.Tests.ps1 | 42 ++--- .../Write-Error.Tests.ps1 | 4 +- .../Write-Host.Tests.ps1 | 2 +- .../Write-Progress.Tests.ps1 | 6 +- .../alias.tests.ps1 | 42 +---- .../clixml.tests.ps1 | 4 +- .../formatdata.tests.ps1 | 2 +- .../typedata.tests.ps1 | 2 +- 36 files changed, 134 insertions(+), 300 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 index dd4be831478..3afa5197892 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 @@ -4,59 +4,19 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { It "Mandatory parameters should not be null nor empty" { # when Name is null - try - { - Add-Member -Name $null - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -Name $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" # when Name is empty - try - { - Add-Member -Name "" - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -Name "" } | Should -Throw -ErrorId "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" # when MemberType is null - try - { - Add-Member -MemberType $null - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -MemberType $null } | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" # when MemberType is empty - try - { - Add-Member -MemberType "" - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -MemberType "" } | Should -Throw -ErrorId "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" # when InputObject is null - try - { - Add-Member -InputObject $null - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" } # It only support on AliasProperty, ScriptProperty, CodeProperty and CodeMethod @@ -64,14 +24,8 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $memberTypesWhereV1CannotBeNull = "CodeMethod", "MemberSet", "PropertySet", "ScriptMethod", "NoteProperty" foreach ($memberType in $memberTypesWhereV1CannotBeNull) { - try - { - Add-Member -InputObject a -memberType $memberType -Name Name -Value something -SecondValue somethingElse - Throw "Execution OK" - } - catch{ - $_.FullyQualifiedErrorId | Should -Be "Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -memberType $memberType -Name Name -Value something -SecondValue somethingElse } | + Should -Throw -ErrorId "Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand" } } @@ -79,27 +33,10 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $membersYouCannotAdd = "Method", "Property", "ParameterizedProperty" foreach ($member in $membersYouCannotAdd) { - try - { - Add-Member -InputObject a -memberType $member -Name Name - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "CannotAddMemberType,Microsoft.PowerShell.Commands.AddMemberCommand" - - } + { Add-Member -InputObject a -memberType $member -Name Name } | Should -Throw -ErrorId "CannotAddMemberType,Microsoft.PowerShell.Commands.AddMemberCommand" } - try - { - Add-Member -InputObject a -memberType AnythingElse -Name Name - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -memberType AnythingElse -Name Name } | Should -Throw -ErrorId "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" } @@ -107,29 +44,15 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $memberTypes = "CodeProperty", "ScriptProperty" foreach ($memberType in $memberTypes) { - try - { - Add-Member -memberType $memberType -Name PropertyName -Value $null -SecondValue $null -InputObject a - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "Value1AndValue2AreNotBothNull,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -memberType $memberType -Name PropertyName -Value $null -SecondValue $null -InputObject a } | + Should -Throw -ErrorId "Value1AndValue2AreNotBothNull,Microsoft.PowerShell.Commands.AddMemberCommand" } } It "Fail to add unexisting type" { - try - { - Add-Member -InputObject a -MemberType AliasProperty -Name Name -Value something -SecondValue unexistingType - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "InvalidCastFromStringToType,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -MemberType AliasProperty -Name Name -Value something -SecondValue unexistingType } + Should -Throw -ErrorId "InvalidCastFromStringToType,Microsoft.PowerShell.Commands.AddMemberCommand" } It "Successful alias, no type" { @@ -145,15 +68,8 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } It "CodeProperty Reference Wrong Type" { - try - { - add-member -InputObject a -MemberType CodeProperty -Name Name -Value something - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -MemberType CodeProperty -Name Name -Value something } | + Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } It "Empty Member Set Null Value1" { @@ -166,58 +82,37 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $members = new-object System.Collections.ObjectModel.Collection[System.Management.Automation.PSMemberInfo] $n=new-object Management.Automation.PSNoteProperty a,1 $members.Add($n) - $r=add-member -InputObject a -MemberType MemberSet -Name Name -Value $members -passthru + $r=Add-Member -InputObject a -MemberType MemberSet -Name Name -Value $members -passthru $r.Name.a | Should -Be '1' } It "MemberSet With Wrong Type For Value1" { - try - { - add-member -InputObject a -MemberType MemberSet -Name Name -Value ImNotACollection - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -MemberType MemberSet -Name Name -Value ImNotACollection } | + Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } It "ScriptMethod Reference Wrong Type" { - try - { - add-member -InputObject a -MemberType ScriptMethod -Name Name -Value something - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -MemberType ScriptMethod -Name Name -Value something } + | Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } It "Add ScriptMethod Success" { - $results = add-member -InputObject 'abc' -MemberType ScriptMethod -Name Name -Value {$this.length} -passthru - $results | Should -Be abc + $results = Add-Member -InputObject 'abc' -MemberType ScriptMethod -Name Name -Value {$this.length} -PassThru + $results | Should -BeExactly 'abc' $results.Name() | Should -Be 3 } It "ScriptProperty Reference Wrong Type" { - try - { - add-member -InputObject a -MemberType ScriptProperty -Name Name -Value something - Throw "Execution OK" - } - catch - { - $_.FullyQualifiedErrorId | Should -Be "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" - } + { Add-Member -InputObject a -MemberType ScriptProperty -Name Name -Value something } | + Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } It "Add ScriptProperty Success" { set-alias ScriptPropertyTestAlias dir $al=(get-alias ScriptPropertyTestAlias) $al.Description="MyDescription" - $al | add-member -MemberType ScriptProperty -Name NewDescription -Value {$this.Description} -SecondValue {$this.Description=$args[0]} - $al.NewDescription | Should -Be 'MyDescription' + $al | Add-Member -MemberType ScriptProperty -Name NewDescription -Value {$this.Description} -SecondValue {$this.Description=$args[0]} + $al.NewDescription | Should -BeExactly 'MyDescription' $al.NewDescription = "some description" $al.NewDescription | Should -Be 'some description' } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index c5235bebe11..b00cc739bf2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" } Clear-Variable -Name foo -Force @@ -61,7 +61,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "ItemNotFoundException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -193,7 +193,7 @@ Describe "Clear-Variable" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" } $var2 | Should -Not -BeNullOrEmpty diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index ad2e65e49fa..35365c8608c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -15,7 +15,7 @@ def=content of def } catch { - $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 index 9aaa1fd389e..1cfee2362a6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | Should -Be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.| Should -Throw -ErrorId "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -30,7 +30,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | Should -Be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.| Should -Throw -ErrorId "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -41,7 +41,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } @@ -52,7 +52,7 @@ Describe "Debug-Runspace" -tag "CI" { throw "Command did not throw exception" } catch { - $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index b734a631095..41832d36ae5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -45,7 +45,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.| Should -Throw -ErrorId "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" } finally{ Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue @@ -59,7 +59,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" } } @@ -123,7 +123,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { throw "No Exception!" } catch{ - $_.FullyQualifiedErrorId | Should -Be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" + $_.| Should -Throw -ErrorId "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" } Export-Alias $fulltestpath abcd03 -force $fulltestpath| Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 00287248e60..5a628550bae 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Format-Table DRT Unit Tests" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "PipelineStoppedException" - $_.FullyQualifiedErrorId | Should -Be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $_.| Should -Throw -ErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 index 9d3bbb9565a..e18d453a43e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Format-Wide" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" + $_.| Should -Throw -ErrorId "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 53e4a537f14..dfd59dafd7d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias OutOfRange Scope"{ @@ -17,7 +17,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Named Single Valid"{ @@ -146,7 +146,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" + $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } } It "Get-Alias Zero Scope Valid"{ @@ -231,7 +231,7 @@ Describe "Get-Alias null tests" -Tags "CI" { Get-Alias -Name $data throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + catch { $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } } Context 'Check null or empty value to the -Name parameter via pipeline' { @@ -242,7 +242,7 @@ Describe "Get-Alias null tests" -Tags "CI" { $data | Get-Alias -ErrorAction Stop throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + catch { $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 index af02f685529..65abea35ad7 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 @@ -38,7 +38,7 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.| Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" } } } @@ -50,7 +50,7 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should -Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.| Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } } @@ -60,7 +60,7 @@ Describe "Get-FileHash" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should -Be "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" + $_.| Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 index 2dba372027f..51f0df96112 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 @@ -156,7 +156,7 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' + $_.| Should -Throw -ErrorId 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 index 6ce8e40430f..e783877b768 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 @@ -80,7 +80,7 @@ Describe "Get-Random DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" + $_.| Should -Throw -ErrorId "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index c09d6101d97..47e58474e03 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Get-Uptime" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + $_.| Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" } finally { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 index 170f219df52..25bcb9f39ea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -49,7 +49,7 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } } @@ -148,7 +148,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable globalVar -Value 1 -Scope global -Force Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue -ErrorVariable removeGlobalAsLocal - $removeGlobalAsLocal.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $removeGlobalAsLocal.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } It "Should be able to get a global variable when there's one in the script scope" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 index aef91e3d389..55c26de2d20 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 @@ -39,7 +39,7 @@ Describe "Get-Verb" -Tags "CI" { throw "Expected error did not occur" } Catch{ - $PSItem.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' + $PSItem.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index f18dd0035f6..833b68cf3c4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -111,7 +111,7 @@ try $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -AllowClobber throw "expect Import-PSSession to throw" } catch { - $_.FullyQualifiedErrorId | Should -Be "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" + $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 index 7a774c96cec..ac7de6b7d58 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.| Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" } } @@ -42,7 +42,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.| Should -Throw -ErrorId "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" } } @@ -53,7 +53,7 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" + $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 index 9991a35d793..e7934d5b138 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains empty key name' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should -Be 'EmptyKeyInJsonString' + $errorRecord.| Should -Throw -ErrorId 'EmptyKeyInJsonString' } It 'Not throw when json contains empty key name when ReturnHashTable is true' { @@ -55,7 +55,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains key with different casing' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should -Be 'KeysWithDifferentCasingInJsonString' + $errorRecord.| Should -Throw -ErrorId 'KeysWithDifferentCasingInJsonString' } It 'Not throw when json contains key (same casing) when ReturnHashTable is true' { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index bd6191ba2f3..a42e34b0d21 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -9,7 +9,7 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + $_.| Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index f6e85c2fc30..ea253550070 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -92,7 +92,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -Be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -105,7 +105,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodException" - $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -119,7 +119,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodInvocationException" - $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -136,7 +136,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "MethodException" - $_.FullyQualifiedErrorId | Should -Be "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -153,7 +153,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" } } @@ -167,7 +167,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -Be "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $_.| Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 630c7b115ea..96ca6188d39 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -29,7 +29,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "SessionStateException" - $_.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $_.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo @@ -48,7 +48,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { } catch { $_.CategoryInfo| Should -Match "SessionStateException" - $_.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $_.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo @@ -89,7 +89,7 @@ Describe "New-Variable" -Tags "CI" { It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" { New-Variable var1 New-Variable var1 -ErrorAction SilentlyContinue -ErrorVariable newWhenExists - $newWhenExists.FullyQualifiedErrorId | Should -Be "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $newWhenExists.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } It "Should change the value of an already existing variable using the Force switch" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index 414743f2b85..c9dfd537d05 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -50,7 +50,7 @@ Describe "Json Tests" -Tags "Feature" { } catch { - $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId + $_.| Should -Throw -ErrorId $expectedFullyQualifiedErrorId } } @@ -1422,7 +1422,7 @@ Describe "Json Bug fixes" -Tags "Feature" { } catch { - $_.FullyQualifiedErrorId | Should -Be $testCase.FullyQualifiedErrorId + $_.| Should -Throw -ErrorId $testCase.FullyQualifiedErrorId } } else diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 index 7a142da3e47..11ccaaaf555 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 @@ -3,66 +3,33 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { It "Validates error on a missing path" { - - try - { - Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop - Throw "Command did not throw exception" - } - catch - { - $_.FullyQualifiedErrorId | Should -be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" - } + { Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop } | + Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } It "Validates error on a directory" { - - try - { - Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop - Throw "Command did not throw exception" - } - catch - { - $_.FullyQualifiedErrorId | Should -be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" - } + { Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop } | + Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } It "Generates a good error on an insecure file" { $path = Setup -f insecure.psd1 -content '@{ Foo = Get-Process }' -pass - try - { - Import-PowerShellDataFile $path -ErrorAction Stop - Throw "Command did not throw exception" - } - catch - { - $_.FullyQualifiedErrorId | Should -be "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" - } + { Import-PowerShellDataFile $path -ErrorAction Stop } | + Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" { - $path = setup -f NotAPSDataFile -content '"Hello World"' -Pass - try - { - Import-PowerShellDataFile $path -ErrorAction Stop - Throw "Command did not throw exception" - } - catch - { - $_.FullyQualifiedErrorId | Should -be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" - } + { Import-PowerShellDataFile $path -ErrorAction Stop } | + Should -Throw -ErrorId "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand" } It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" { - $path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass - $result = Import-PowerShellDataFile $path -ErrorAction Stop - $result.Hello | Should -be "World" + $result.Hello | Should -Exactly "World" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 5eb895e177b..6016eccd614 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable -Name var1 -Value 4 Remove-Variable $var1 -ErrorAction SilentlyContinue -ErrorVariable err - $err.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $err.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" } It "Should not throw error when used without the Name field, and named variable is properly specified and exists" { @@ -203,7 +203,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } } @@ -217,7 +217,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { catch { $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue @@ -234,7 +234,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } try @@ -245,7 +245,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" } } @@ -261,7 +261,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "ItemNotFoundException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index b29c6ac382a..ccb871321ba 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -132,7 +132,7 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { catch { $_.CategoryInfo | Should -Match "PSArgumentException" - $_.FullyQualifiedErrorId | Should -Be "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $_.| Should -Throw -ErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index b7aa0b82785..1627fd97fcf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" } } @@ -80,7 +80,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" + $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 index 6e037f52ba2..8bb0e26c750 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 @@ -142,7 +142,7 @@ set-psbreakpoint -command foo Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + $_.| Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } } @@ -153,7 +153,7 @@ set-psbreakpoint -command foo Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + $_.| Should -Throw -ErrorId "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } $ErrorActionPreference = "SilentlyContinue" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 9519f674221..14e606ad211 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -96,7 +96,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } @@ -123,7 +123,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -139,7 +139,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should -Be "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index 74c951708ba..e5beb107728 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -61,7 +61,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") $ps.Invoke() $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].| Should -Throw -ErrorId "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Dynamic Type NoteProperty with Force should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 409ed22238b..bd2981fc519 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -474,7 +474,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri '$uri' -MaximumRedirection 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Invoke-WebRequest supports request that returns page containing UTF-8 data." { @@ -493,7 +493,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" { @@ -501,7 +501,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } $testCase = @( @@ -516,7 +516,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -Proxy '${proxy_address}' -SkipCertificateCheck" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with environment proxy set - ''" -TestCases $testCase { @@ -529,7 +529,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns User-Agent where -NoProxy with envirionment proxy set - ''" -TestCases $testCase { @@ -696,7 +696,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns empty RelationLink property if there is no Link Header" { @@ -845,7 +845,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -874,7 +874,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -1162,7 +1162,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $Uri = Get-WebListenerUrl -Https $command = "Invoke-WebRequest -Uri '$Uri'" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $Uri = Get-WebListenerUrl -Https @@ -1178,7 +1178,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" { @@ -1718,7 +1718,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri '$uri' -MaximumRedirection 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Invoke-RestMethod supports request that returns page containing UTF-8 data." { @@ -1734,7 +1734,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" { @@ -1742,7 +1742,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } $testCase = @( @@ -1758,7 +1758,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri '$uri' -Proxy '${proxy_address}'" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with environment proxy set - ''" -TestCases $testCase { @@ -1771,7 +1771,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod returns User-Agent with option -NoProxy when environment proxy set - ''" -TestCases $testCase { @@ -1929,7 +1929,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" { @@ -2050,7 +2050,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -2079,7 +2079,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -2162,7 +2162,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Https $command = "Invoke-RestMethod -Uri '$uri' -Method HEAD" $result = ExecuteWebCommand -command $command - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $command = "Invoke-RestMethod -Uri '$uri' -SkipCertificateCheck -Method HEAD" @@ -2177,7 +2177,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" { @@ -2860,7 +2860,7 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu & $scriptblock throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | Should -Be $ExpectedFullyQualifiedErrorId + $_.| Should -Throw -ErrorId $ExpectedFullyQualifiedErrorId } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 index d6e2740044b..973c52adb51 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Write-Error Tests" -Tags "CI" { $e.ErrorDetails | Should -BeNullOrEmpty #FullyQualifiedErrorId verification - $e.FullyQualifiedErrorId | Should -Be 'Microsoft.PowerShell.Commands.WriteErrorException' + $e.| Should -Throw -ErrorId 'Microsoft.PowerShell.Commands.WriteErrorException' #InvocationInfo verification $e.InvocationInfo | Should -Not -BeNullOrEmpty @@ -47,7 +47,7 @@ Describe "Write-Error Tests" -Tags "CI" { $e.TargetObject | Should -Be 'TargetObject' #FullyQualifiedErrorId verification - $e.FullyQualifiedErrorId | Should -Be 'myerrorid' + $e.| Should -Throw -ErrorId 'myerrorid' #ErrorCategoryInfo verification $e.CategoryInfo | Should -Not -BeNullOrEmpty diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 index c7742e9e593..38ed23424da 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Write-Host with wrong colors" -Tags "CI" { Write-Host "No output from Write-Host" -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor throw "No Exception!" } - catch { $_.FullyQualifiedErrorId | Should -Be 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } + catch { $_.| Should -Throw -ErrorId 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 index c309821f1a0..bc35548fb27 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.| Should -Throw -ErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' } } @@ -21,7 +21,7 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } } @@ -33,7 +33,7 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 index 4b7082a0113..6209170408d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 @@ -50,7 +50,7 @@ Describe "Alias tests" -Tags "CI" { if($null -eq $test.expectedError) { - Test-Path -LiteralPath $test.testFile | Should -Be $true + $test.testFile | Should -Exist } else { @@ -65,17 +65,7 @@ Describe "Alias tests" -Tags "CI" { It "when file exists with NoClobber" { Export-Alias -LiteralPath $csvFile - - try - { - Export-Alias -LiteralPath $csvFile -NoClobber - } - catch - { - $exportAliasError = $_ - } - - $exportAliasError.FullyQualifiedErrorId | Should -Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" + { Export-Alias -LiteralPath $csvFile -NoClobber } | Should -Throw -ErrorId "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" } } @@ -86,22 +76,13 @@ Describe "Alias tests" -Tags "CI" { It "with a CSV file" { Export-Alias "alias.csv" - Test-Path -LiteralPath (Join-Path $testPath "alias.csv") | Should -Be $true + Test-Path -LiteralPath (Join-Path $testPath "alias.csv") | Should -BeTrue } It "with NoClobber" { $path = Export-Alias alias.csv - try - { - Export-Alias alias.csv -NoClobber - } - catch - { - $exportAliasError = $_ - } - - $exportAliasError.FullyQualifiedErrorId | Should -Be "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" + { Export-Alias alias.csv -NoClobber } | Should -Throw -ErrorId "NoClobber,Microsoft.PowerShell.Commands.ExportAliasCommand" } AfterEach { @@ -126,16 +107,7 @@ Describe "Alias tests" -Tags "CI" { It "for $($_.testName)" { $test = $_ - try - { - Import-Alias -LiteralPath $test.testFile -ErrorAction SilentlyContinue - } - catch - { - $exportAliasError = $_ - } - - $exportAliasError.FullyqualifiedErrorId | Should -Be $test.expectedError + { Import-Alias -LiteralPath $test.testFile -ErrorAction SilentlyContinue } | Should -Throw -ErrorId $test.expectedError } } @@ -154,8 +126,8 @@ Describe "Alias tests" -Tags "CI" { # Verify that the alias was imported $definedAlias = Get-Alias myuh - $definedAlias | Should -Not -Be $null - $definedAlias.Name | Should -Be "myuh" + $definedAlias | Should -Not -BeNullOrEmpty + $definedAlias.Name | Should -BeExactly "myuh" $definedAlias.Definition | Should -Be "update-help" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 index 20b6cc072fb..16245b26f1d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 @@ -94,7 +94,7 @@ Describe "CliXml test" -Tags "CI" { } } - $isExisted | Should -Be $true + $isExisted | Should -BeTrue } It "can be created with literal path using pipeline" { @@ -120,7 +120,7 @@ Describe "CliXml test" -Tags "CI" { } } - $isExisted | Should -Be $true + $isExisted | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 index 2bf8a4b87bf..877141fb12f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 @@ -32,7 +32,7 @@ Describe "FormatData" -tags "Feature" { It "works with literal path" { $filename = 'TestDrive:\[formats.ps1xml' Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename - (Test-Path -LiteralPath $filename) | Should -Be $true + (Test-Path -LiteralPath $filename) | Should -BeTrue } It "should overwrite the destination file" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 index da0903a92ab..e396d57219a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/typedata.tests.ps1 @@ -18,7 +18,7 @@ Describe "TestData cmdlets" -Tags "CI" { $types[0].TypeName | Should -Be System.DateTime for($i = 1; $i -lt $types.Count; $i++) { - $types[$i].TypeName.StartsWith("System.Management.Automation") | Should -Be $true + $types[$i].TypeName.StartsWith("System.Management.Automation") | Should -BeTrue } } From 0c672a104835e1d3e32f5e03218d7a133a53cbc0 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 11:15:42 -0700 Subject: [PATCH 05/21] [Feature] Test correction for module Microsoft.PowerShell.Utility. --- .../Clear-Variable.Tests.ps1 | 234 ++++++++---------- .../ConvertFrom-StringData.Tests.ps1 | 10 +- .../Debug-Runspace.Tests.ps1 | 36 +-- .../Export-Alias.Tests.ps1 | 36 +-- .../Format-Table.Tests.ps1 | 12 +- .../Format-Wide.Tests.ps1 | 11 +- .../FormatHex.Tests.ps1 | 9 +- .../Get-Member.Tests.ps1 | 10 +- .../Get-Random.Tests.ps1 | 10 +- .../Get-Uptime.Tests.ps1 | 15 +- .../MiscCmdletUpdates.Tests.ps1 | 13 +- .../New-Object.Tests.ps1 | 71 +----- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 31 +-- .../Remove-Variable.Tests.ps1 | 60 +---- .../Select-Object.Tests.ps1 | 12 +- .../Write-Progress.Tests.ps1 | 32 +-- .../clixml.tests.ps1 | 23 +- .../formatdata.tests.ps1 | 11 +- 18 files changed, 173 insertions(+), 463 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index b00cc739bf2..b2cf2aecb5a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -14,21 +14,15 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { It "Clear-Variable ReadOnly variable Name should throw exception and force Clear-Variable should works"{ Set-Variable foo bar -Option ReadOnly - try { - Clear-Variable -Name foo -EA Stop - Throw "Execution OK" - } - catch { - $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" - } + { Clear-Variable -Name foo -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" Clear-Variable -Name foo -Force $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" $var1.Value|Should -BeNullOrEmpty $var1.Options|Should -Be "ReadOnly" - $var1.Description|Should -BeNullOrEmpty + $var1.Description| Should -BeNullOrEmpty } It "Clear-Variable normal variable Name with local scope should works"{ @@ -55,14 +49,9 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { It "Clear-Variable Private variable Name should works and Get-Variable with local scope should throw exception"{ Set-Variable foo bar -Option Private &{ - try { - Get-Variable -Name foo -Scope local -EA Stop - Throw "Execution OK" - } - catch { - $_.CategoryInfo| Should -Match "ItemNotFoundException" - $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + $e = { Get-Variable -Name foo -Scope local -EA Stop } | + Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $e.CategoryInfo | Should -Match "ItemNotFoundException" } $var1=Get-Variable -Name foo @@ -100,165 +89,158 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { } Describe "Clear-Variable" -Tags "CI" { - BeforeEach { - $var1 = 3 - } - - It "Should be able to clear a variable using the Name switch" { - Clear-Variable -Name var1 - $var1 | Should -BeNullOrEmpty - { Get-Variable var1 } | Should -Not -Throw - } + BeforeEach { + $var1 = 3 + } - It "Should be able to clear a variable without using the Name switch" { - Clear-Variable var1 - $var1 | Should -BeNullOrEmpty - { Get-Variable var1 } | Should -Not -Throw - } + It "Should be able to clear a variable using the Name switch" { + Clear-Variable -Name var1 + $var1 | Should -BeNullOrEmpty + { Get-Variable var1 } | Should -Not -Throw + } - It "Should be able to include a set of variables to clear" { - $var1 = 2 - $var2 = 3 - $var3 = 4 - $variable1 = 23 - $variable2 = 4 - $variable3 = 2 - $w = 3 + It "Should be able to clear a variable without using the Name switch" { + Clear-Variable var1 + $var1 | Should -BeNullOrEmpty + { Get-Variable var1 } | Should -Not -Throw + } - Clear-Variable -Name w, vari* -Include w, vari* + It "Should be able to include a set of variables to clear" { + $var1 = 2 + $var2 = 3 + $var3 = 4 + $variable1 = 23 + $variable2 = 4 + $variable3 = 2 + $w = 3 - $variable1 | Should -BeNullOrEmpty - $variable2 | Should -BeNullOrEmpty - $variable3 | Should -BeNullOrEmpty - $w | Should -BeNullOrEmpty + Clear-Variable -Name w, vari* -Include w, vari* - $var1 | Should -Not -BeNullOrEmpty - $var2 | Should -Not -BeNullOrEmpty - $var3 | Should -Not -BeNullOrEmpty + $variable1 | Should -BeNullOrEmpty + $variable2 | Should -BeNullOrEmpty + $variable3 | Should -BeNullOrEmpty + $w | Should -BeNullOrEmpty - } + $var1 | Should -Not -BeNullOrEmpty + $var2 | Should -Not -BeNullOrEmpty + $var3 | Should -Not -BeNullOrEmpty + } - It "Should be able to exclude a set of variables to clear" { - $var1 = 2 - $var2 = 3 - $var3 = 4 - $variable1 = 23 - $variable2 = 4 - $variable3 = 2 - $w = 3 - - Clear-Variable -Name w, vari* -Exclude var* - - $variable1 | Should -Not -BeNullOrEmpty - $variable2 | Should -Not -BeNullOrEmpty - $variable3 | Should -Not -BeNullOrEmpty - $var1 | Should -Not -BeNullOrEmpty - $var2 | Should -Not -BeNullOrEmpty - $var3 | Should -Not -BeNullOrEmpty - - $w | Should -BeNullOrEmpty - } + It "Should be able to exclude a set of variables to clear" { + $var1 = 2 + $var2 = 3 + $var3 = 4 + $variable1 = 23 + $variable2 = 4 + $variable3 = 2 + $w = 3 + + Clear-Variable -Name w, vari* -Exclude var* + + $variable1 | Should -Not -BeNullOrEmpty + $variable2 | Should -Not -BeNullOrEmpty + $variable3 | Should -Not -BeNullOrEmpty + $var1 | Should -Not -BeNullOrEmpty + $var2 | Should -Not -BeNullOrEmpty + $var3 | Should -Not -BeNullOrEmpty + + $w | Should -BeNullOrEmpty + } - It "Should be able to pass the cleared object through the pipeline using the passthru switch" { - { Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should -Not -Throw - } + It "Should be able to pass the cleared object through the pipeline using the passthru switch" { + { Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should -Not -Throw + } - It "Should not clear environment variables" { - $env:TEMPVARIABLE = "test data" + It "Should not clear environment variables" { + $env:TEMPVARIABLE = "test data" - {Clear-Variable -Name env:TEMPVARIABLE -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name env:TEMPVARIABLE -ErrorAction Stop } | Should -Throw + } - It "Should clear variable even if it is read-only using the Force parameter" { - try - { - New-Variable -Name var2 -Option ReadOnly -Value 100 + It "Should clear variable even if it is read-only using the Force parameter" { + try + { + New-Variable -Name var2 -Option ReadOnly -Value 100 - Clear-Variable -Name var1 - Clear-Variable -Name var2 -Force + Clear-Variable -Name var1 + Clear-Variable -Name var2 -Force - $var1 | Should -BeNullOrEmpty - $var2 | Should -BeNullOrEmpty - } - finally - { - Remove-Variable -Name var2 -Force - } + $var1 | Should -BeNullOrEmpty + $var2 | Should -BeNullOrEmpty + } + finally + { + Remove-Variable -Name var2 -Force } + } - It "Should throw error when trying to clear variable that is read-only without using the Force parameter" { + It "Should throw error when trying to clear variable that is read-only without using the Force parameter" { New-Variable -Name var2 -Option ReadOnly -Value 100 - try { - Clear-Variable -Name var2 -ea stop - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" - } + { Clear-Variable -Name var2 -ea stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $var2 | Should -Not -BeNullOrEmpty Remove-Variable -Name var2 -Force - } + } - Context "Scope Tests" { + Context "Scope Tests" { # This will violate the DRY principle. Tread softly. - It "Should be able to clear a global scope variable using the global switch" { + It "Should be able to clear a global scope variable using the global switch" { New-Variable globalVar -Value 1 -Scope global -Force Clear-Variable -Name globalVar -Scope global $globalVar | Should -BeNullOrEmpty - } + } - It "Should not be able to clear a global scope variable using the local switch" { + It "Should not be able to clear a global scope variable using the local switch" { New-Variable globalVar -Value 1 -Scope global -Force - {Clear-Variable -Name globalVar -Scope local -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name globalVar -Scope local -ErrorAction Stop } | + Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand" + } - It "Should not be able to clear a global variable using the script scope switch" { + It "Should not be able to clear a global variable using the script scope switch" { New-Variable globalVar -Value 1 -Scope global -Force - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name localVar -Scope script -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand" + } - It "Should be able to clear an item locally using the local switch" { + It "Should be able to clear an item locally using the local switch" { New-Variable localVar -Value 2 -Scope local -Force Clear-Variable -Name localVar -Scope local $localVar | Should -BeNullOrEmpty - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name localVar -Scope script -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand" + } - It "Should not be able to clear an item locally using the global switch" { + It "Should not be able to clear an item locally using the global switch" { New-Variable localVar -Value 2 -Scope local -Force - {Clear-Variable -Name localVar -Scope global -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name localVar -Scope global -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand" + } - It "Should not be able to clear a local variable using the script scope switch" { + It "Should not be able to clear a local variable using the script scope switch" { New-Variable localVar -Value 2 -Scope local -Force - {Clear-Variable -Name localVar -Scope script -ErrorAction Stop} | Should -Throw - } + { Clear-Variable -Name localVar -Scope script -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand" + } - It "Should be able to clear a script variable created using the script switch" { + It "Should be able to clear a script variable created using the script switch" { { - New-Variable -Name derp2 -Value 3 -Scope script -Force - - Clear-Variable -Name derp2 -Scope script - }| Should -Not -Throw - } + New-Variable -Name derp2 -Value 3 -Scope script -Force + Clear-Variable -Name derp2 -Scope script + } | Should -Not -Throw + } - It "Should be able to clear a global script variable that was created using the script scope switch" { + It "Should be able to clear a global script variable that was created using the script scope switch" { { - New-Variable -Name derpx -Value 4 -Scope script -Force - - Clear-Variable -Name derpx -Scope script + New-Variable -Name derpx -Value 4 -Scope script -Force + Clear-Variable -Name derpx -Scope script } | Should -Not -Throw - } } + } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index 35365c8608c..edf0ed371da 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -8,15 +8,7 @@ abc #comments here def=content of def "@ - try - { - ConvertFrom-StringData $str - Throw "we expect 'InvalidOperation' exception" - } - catch - { - $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" - } + { ConvertFrom-StringData $str } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 index 1cfee2362a6..abf6d286172 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 @@ -15,45 +15,21 @@ Describe "Debug-Runspace" -tag "CI" { } It "Debugging a runspace should fail if the name is ambiguous" { - try { - Debug-Runspace -Name "My*" -ea stop - throw "Command did not throw exception" - } - catch { - $_.| Should -Throw -ErrorId "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" - } + { Debug-Runspace -Name "My*" -ea stop } | Should -Throw -ErrorId "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } It "Debugging a runspace should fail if the name is not found" { - try { - Debug-Runspace -Name "dflkjsdkfjldkjssldfj" -ea stop - throw "Command did not throw exception" - } - catch { - $_.| Should -Throw -ErrorId "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" - } + { Debug-Runspace -Name "dflkjsdkfjldkjssldfj" -ea stop } | Should -Throw -ErrorId "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } It "Debugging a runspace should fail if the runspace is not open" { - try { - $rs2.Close() - Debug-Runspace -runspace $rs2 -ea stop - throw "Command did not throw exception" - } - catch { - $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" - } + $rs2.Close() + { Debug-Runspace -runspace $rs2 -ea stop } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } It "Debugging a runspace should fail if the runspace has no debugger" { - try { - $rs1.Debugger.SetDebugMode("None") - Debug-Runspace -runspace $rs1 -ea stop - throw "Command did not throw exception" - } - catch { - $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" - } + $rs1.Debugger.SetDebugMode("None") + { Debug-Runspace -runspace $rs1 -ea stop } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index 41832d36ae5..5122e8a5994 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -38,29 +38,19 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { } It "Export-Alias resolving to multiple files will throw ReadWriteMultipleFilesNotSupported" { - try { + { $null = New-Item -Path $TestDrive\foo -ItemType File $null = New-Item -Path $TestDrive\bar -ItemType File Export-Alias $TestDrive\* Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" - } - finally{ - Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue - Remove-Item $TestDrive\bar -Force -ErrorAction SilentlyContinue - } + } | Should -Throw -ErrorId "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" + + Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue + Remove-Item $TestDrive\bar -Force -ErrorAction SilentlyContinue } It "Export-Alias with Invalid Scope will throw PSArgumentException" { - try { - Export-Alias $fulltestpath -scope foobar - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" - } + { Export-Alias $fulltestpath -scope foobar } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand" } It "Export-Alias for Default"{ @@ -118,17 +108,11 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { chmod 444 $fulltestpath } - try{ - Export-Alias $fulltestpath abcd02 - throw "No Exception!" - } - catch{ - $_.| Should -Throw -ErrorId "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" - } + { Export-Alias $fulltestpath abcd02 } | Should -Throw -ErrorId "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand" Export-Alias $fulltestpath abcd03 -force - $fulltestpath| Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' - $fulltestpath| Should -Not -FileContentMatchExactly '"abcd02","efgh02","","None"' - $fulltestpath| Should -FileContentMatchExactly '"abcd03","efgh03","","None"' + $fulltestpath | Should -Not -FileContentMatchExactly '"abcd01","efgh01","","None"' + $fulltestpath | Should -Not -FileContentMatchExactly '"abcd02","efgh02","","None"' + $fulltestpath | Should -FileContentMatchExactly '"abcd03","efgh03","","None"' if ( $IsWindows ) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 5a628550bae..9189e322e48 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -32,16 +32,8 @@ Describe "Format-Table" -Tags "CI" { Describe "Format-Table DRT Unit Tests" -Tags "CI" { It "Format-Table with not existing table with force should throw PipelineStoppedException"{ $obj = New-Object -typename PSObject - try - { - $obj | Format-Table -view bar -force -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "PipelineStoppedException" - $_.| Should -Throw -ErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" - } + $e = { $obj | Format-Table -view bar -force -EA Stop } | Should -Throw -ErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $e.CategoryInfo | Should -Match "PipelineStoppedException" } It "Format-Table with array should work" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 index e18d453a43e..8b805c08870 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Wide.Tests.ps1 @@ -26,15 +26,8 @@ Describe "Format-Wide" -Tags "CI" { } It "Should throw an error when property switch and view switch are used together" { - try - { - Format-Wide -InputObject $(Get-ChildItem) -Property CreationTime -View aoeu - throw "No Exception!" - } - catch - { - $_.| Should -Throw -ErrorId "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" - } + { Format-Wide -InputObject $(Get-ChildItem) -Property CreationTime -View aoeu } | + Should -Throw -ErrorId "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" } It "Should throw and suggest proper input when view is used with invalid input without the property switch" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 index cdf9f7d3154..c50088cfa42 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/FormatHex.Tests.ps1 @@ -332,7 +332,6 @@ Describe "FormatHex" -tags "CI" { param ($Name, $PathParameterErrorCase, $Path, $InputObject, $InputObjectErrorCase, $ExpectedFullyQualifiedErrorId) - try { if ($PathParameterErrorCase) { @@ -342,13 +341,7 @@ Describe "FormatHex" -tags "CI" { { $result = Format-Hex -InputObject $InputObject -ErrorAction Stop } - } - catch - { - $thrownError = $_ - } - - $thrownError.FullyQualifiedErrorId | Should -MatchExactly $ExpectedFullyQualifiedErrorId + } | Should -Throw -ErrorId $ExpectedFullyQualifiedErrorId } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 index 51f0df96112..c95736e36bc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 @@ -149,15 +149,7 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { Update-TypeData -AppendPath $fileToDeleteName It "Fail to get member without any input" { - try - { - Get-Member -MemberType All -ErrorAction Stop - Throw "Execution OK" - } - catch - { - $_.| Should -Throw -ErrorId 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' - } + { Get-Member -MemberType All -ErrorAction Stop } | Should -Throw -ErrorId 'NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand' } It 'Get the expected Properties of "Employee" object' { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 index e783877b768..e18cbe1a8a9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Random.Tests.ps1 @@ -73,15 +73,7 @@ Describe "Get-Random DRT Unit Tests" -Tags "CI" { It "Should be able to throw error when ''" -TestCases $testDataForError { param($maximum, $minimum) - try - { - Get-Random -Minimum $minimum -Maximum $maximum - throw "OK" - } - catch - { - $_.| Should -Throw -ErrorId "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" - } + { Get-Random -Minimum $minimum -Maximum $maximum } | Should -Throw -ErrorId "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" } It "Tests for setting the seed" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index 47e58474e03..d33f8e905ab 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -26,22 +26,13 @@ Describe "Get-Uptime" -Tags "CI" { $upt | Should -BeOfType "DateTime" } It "Get-Uptime throw if IsHighResolution == false" { - try { # Enable the test hook [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true) Get-Uptime - throw "No Exception!" - } - catch - { - $_.| Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" - } - finally - { - # Disable the test hook - [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false) - } + } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + # Disable the test hook + [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false) } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 index 3ca0cfd884c..d04d4098498 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/MiscCmdletUpdates.Tests.ps1 @@ -41,16 +41,7 @@ Describe "GetRandomMiscTests" -Tags "Feature" { $hadError = $false - try - { - ## Don't actually need to validate - Get-Random -Minimum ([Int32]::MinValue) -Maximum ([Int32]::MaxValue) -ErrorAction Stop - } - catch - { - $hadError = $true - } - - $hadError | Should -BeFalse + ## Don't actually need to validate + { Get-Random -Minimum ([Int32]::MinValue) -Maximum ([Int32]::MaxValue) -ErrorAction Stop } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index ea253550070..3c40cee202b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -84,43 +84,20 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } It "New-Object with invalid type should throw Exception"{ - try - { - New-Object -TypeName LiarType -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "PSArgumentException" - $_.| Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" - } + $e = { New-Object -TypeName LiarType -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "PSArgumentException" } It "New-Object with invalid argument should throw Exception"{ - try - { - New-Object -TypeName System.Management.Automation.PSVariable -ArgumentList "A", 1, None, "asd" -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "MethodException" - $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" - } + $e = { New-Object -TypeName System.Management.Automation.PSVariable -ArgumentList "A", 1, None, "asd" -EA Stop } | + | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "MethodException" } It "New-Object with abstract class should throw Exception"{ Add-Type -TypeDefinition "public abstract class AbstractEmployee{public AbstractEmployee(){}}" - try - { - New-Object -TypeName AbstractEmployee -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "MethodInvocationException" - $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" - } + $e = { New-Object -TypeName AbstractEmployee -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "MethodInvocationException } It "New-Object with bad argument for class constructor should throw Exception"{ @@ -128,16 +105,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - try - { - New-Object -TypeName Employee -ArgumentList 11 -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "MethodException" - $_.| Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" - } + { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "MethodException" } #This case will throw "Execution OK" now, just mark as pending now @@ -146,29 +115,13 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - try - { - New-Object -TypeName Employee -EA Stop - Throw "Execution OK" - } - catch - { - $_.| Should -Throw -ErrorId "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" - } + { New-Object -TypeName Employee -EA Stop } | Should -Throw -ErrorId "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" } It "New-Object with Private Nested class should throw Exception"{ Add-Type -TypeDefinition "public class WeirdEmployee{public WeirdEmployee(){}private class PrivateNestedWeirdEmployee{public PrivateNestedWeirdEmployee(){}}}" - try - { - New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "PSArgumentException" - $_.| Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" - } + $e = {New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "PSArgumentException" } It "New-Object with TypeName and Property parameter should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index c9dfd537d05..229015cd6b2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -43,15 +43,7 @@ Describe "Json Tests" -Tags "Feature" { $hash = @{ $process = "def" } $expectedFullyQualifiedErrorId = "NonStringKeyInDictionary,Microsoft.PowerShell.Commands.ConvertToJsonCommand" - try - { - ConvertTo-Json -InputObject $hash - throw "CodeExecuted" - } - catch - { - $_.| Should -Throw -ErrorId $expectedFullyQualifiedErrorId - } + { ConvertTo-Json -InputObject $hash } | Should -Throw -ErrorId $expectedFullyQualifiedErrorId } It "ConvertTo-Json should handle terms with double quotes" { @@ -1415,28 +1407,11 @@ Describe "Json Bug fixes" -Tags "Feature" { if ($testCase.ShouldThrow) { - try - { - $previous | ConvertTo-Json -Depth $testCase.MaxDepth - throw "CodeExecuted" - } - catch - { - $_.| Should -Throw -ErrorId $testCase.FullyQualifiedErrorId - } + { $previous | ConvertTo-Json -Depth $testCase.MaxDepth } | Should -Throw -ErrorId $testCase.FullyQualifiedErrorId } else { - $theError = $null - try - { - $previous | ConvertTo-Json -Depth $testCase.MaxDepth | ConvertFrom-Json - } - catch - { - $theError = $_ - } - $theError | Should -BeNullOrEmpty + { $previous | ConvertTo-Json -Depth $testCase.MaxDepth | ConvertFrom-Json } | Should -Not -Throw } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 6016eccd614..8281008caa3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -195,30 +195,14 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException"{ New-Variable foo bar -Option Constant - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + $e = { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } It "Remove-Variable ReadOnly variable should throw SessionStateUnauthorizedAccessException and force remove should work"{ New-Variable foo bar -Option ReadOnly - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue $var1 | Should -BeNullOrEmpty @@ -226,27 +210,12 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException and force remove should also throw exception"{ New-Variable foo bar -Option Constant - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + $e = { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + + $e = { Remove-Variable foo -Force -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - try - { - Remove-Variable foo -Force -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } } It "Remove-Variable variable in new scope should works and Get-Variable with different scope should have different result"{ @@ -254,15 +223,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { &{ Clear-Variable foo Remove-Variable foo - try{ - Get-Variable -Name foo -Scope local -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "ItemNotFoundException" - $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + $e = { Get-Variable -Name foo -Scope local -EA Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $e.CategoryInfo | Should -Match "ItemNotFoundException" } $var1 = Get-Variable -Name foo diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index ccb871321ba..a820278f0b4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -124,16 +124,8 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { } It "Select-Object with empty script block property should throw"{ - try - { - "bar" | select-object -Prop {} -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "PSArgumentException" - $_.| Should -Throw -ErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" - } + $e = { "bar" | select-object -Prop {} -EA Stop } | Should -Throw -ErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $e.CategoryInfo | Should -Match "PSArgumentException" } It "Select-Object with string property should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 index bc35548fb27..12cd3ed05a6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 @@ -2,39 +2,17 @@ # Licensed under the MIT License. Describe "Write-Progress DRT Unit Tests" -Tags "CI" { It "Should be able to throw exception when missing mandatory parameters" { - try - { - Write-Progress $null - Throw "Execution OK" - } - catch - { - $_.| Should -Throw -ErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' - } + { Write-Progress $null } | Should -Throw -ErrorId 'ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteProgressCommand' } It "Should be able to throw exception when running Write-Progress with bad percentage" { - try - { - write-progress -activity 'myactivity' -status 'mystatus' -percent 101 - Throw "Execution OK" - } - catch - { - $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' - } + { write-progress -activity 'myactivity' -status 'mystatus' -percent 101 } + | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } It "Should be able to throw exception when running Write-Progress with bad parent id " { - try - { - write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentid -2 - Throw "Execution OK" - } - catch - { - $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' - } + { write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentid -2 } + | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } It "all mandatory params works" -Pending { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 index 16245b26f1d..1ba464b4533 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 @@ -57,17 +57,7 @@ Describe "CliXml test" -Tags "CI" { It "$($_.testName)" { $test = $_ - - try - { - Export-Clixml -Depth 1 -LiteralPath $test.testFile -InputObject $test.inputObject -Force - } - catch - { - $exportCliXmlError = $_ - } - - $exportCliXmlError.FullyQualifiedErrorId | Should -Be $test.expectedError + { Export-Clixml -Depth 1 -LiteralPath $test.testFile -InputObject $test.inputObject -Force } | Should -Throw - ErrorId $test.expectedError } } @@ -141,16 +131,7 @@ Describe "CliXml test" -Tags "CI" { It "$($_.testName)" { $test = $_ - try - { - Import-Clixml -LiteralPath $test.testFile - } - catch - { - $importCliXmlError = $_ - } - - $importCliXmlError.FullyQualifiedErrorId | Should -Be $test.expectedError + { Import-Clixml -LiteralPath $test.testFile } | Should -Throw -ErrorId $test.expectedError } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 index 877141fb12f..ea3a89bd96b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/formatdata.tests.ps1 @@ -51,16 +51,7 @@ Describe "FormatData" -tags "Feature" { $filename = "TestDrive:\ExportFormatDataWithNoClobber.ps1xml" Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename - try - { - Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename -NoClobber - } - catch - { - $exportFormatError = $_ - } - - $exportFormatError.FullyQualifiedErrorId | Should -Be 'NoClobber,Microsoft.PowerShell.Commands.ExportFormatDataCommand' + { Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename -NoClobber } | Should -Throw -ErrorId 'NoClobber,Microsoft.PowerShell.Commands.ExportFormatDataCommand' } } } From fae3746d6d698ca13e7d14f9d358600240676318 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Mon, 12 Mar 2018 11:55:24 -0700 Subject: [PATCH 06/21] [Feature] Tests correction --- .../Export-Alias.Tests.ps1 | 2 +- .../Implicit.Remoting.Tests.ps1 | 7 +-- .../Import-Alias.Tests.ps1 | 34 +++---------- .../JsonObject.Tests.ps1 | 4 +- .../New-Alias.Tests.ps1 | 10 ++-- .../New-Variable.Tests.ps1 | 24 +++------ .../Out-String.Tests.ps1 | 2 +- .../Set-Alias.Tests.ps1 | 16 +----- .../Set-PSBreakpoint.Tests.ps1 | 16 +----- .../Set-Variable.Tests.ps1 | 24 ++------- .../Update-TypeData.Tests.ps1 | 4 +- .../WebCmdlets.Tests.ps1 | 49 ++++++------------- 12 files changed, 47 insertions(+), 145 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index 5122e8a5994..b36f342ef6a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { It "Export-Alias for exist file should work"{ New-Item -Path $fulltestpath -ItemType File -Force - {Export-Alias $fulltestpath}| Should -Not -Throw + {Export-Alias $fulltestpath} | Should -Not -Throw } It "Export-Alias resolving to multiple files will throw ReadWriteMultipleFilesNotSupported" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index 833b68cf3c4..66434d56382 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -107,12 +107,7 @@ try } It "Verifies security error when Certificate parameter is not used" -Skip:($skipTest -or $skipThisTest) { - try { - $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -AllowClobber - throw "expect Import-PSSession to throw" - } catch { - $_.| Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" - } + { $importedModule = Import-PSSession $session Get-Variable -Prefix Remote -AllowClobber } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ImportPSSessionCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 index ac7de6b7d58..5163d39c43f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 @@ -24,42 +24,22 @@ Describe "Import-Alias DRT Unit Tests" -Tags "CI" { } It "Import-Alias Resolve To Multiple will throw PSInvalidOperationException" { - $ErrorActionPreference = "Stop" - try { - Import-Alias * - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" - } + { Import-Alias * -ErrorAction Stop } | Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" } It "Import-Alias From Exported Alias File Aliases Already Exist should throw SessionStateException" { - $ErrorActionPreference = "Stop" - {Export-Alias $fulltestpath abcd*}| Should -Not -Throw - try { - Import-Alias $fulltestpath - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" - } + { Export-Alias $fulltestpath abcd* } | Should -Not -Throw + { Import-Alias $fulltestpath -ErrorAction Stop } | Should -Throw -ErrorId "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" } It "Import-Alias Into Invalid Scope should throw PSArgumentException"{ - {Export-Alias $fulltestpath abcd*}| Should -Not -Throw - try { - Import-Alias $fulltestpath -scope bogus - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" - } + { Export-Alias $fulltestpath abcd* } | Should -Not -Throw + { Import-Alias $fulltestpath -scope bogus } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" } It "Import-Alias From Exported Alias File Aliases Already Exist using force should not throw"{ - {Export-Alias $fulltestpath abcd*}| Should -Not -Throw - {Import-Alias $fulltestpath -Force}| Should -Not -Throw + {Export-Alias $fulltestpath abcd*} | Should -Not -Throw + {Import-Alias $fulltestpath -Force} | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 index e7934d5b138..eba2a3108ca 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains empty key name' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, [ref]$errorRecord) - $errorRecord.| Should -Throw -ErrorId 'EmptyKeyInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -Throw -ErrorId 'EmptyKeyInJsonString' } It 'Not throw when json contains empty key name when ReturnHashTable is true' { @@ -55,7 +55,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains key with different casing' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, [ref]$errorRecord) - $errorRecord.| Should -Throw -ErrorId 'KeysWithDifferentCasingInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -Throw -ErrorId 'KeysWithDifferentCasingInJsonString' } It 'Not throw when json contains key (same casing) when ReturnHashTable is true' { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index a42e34b0d21..56563dc06f4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -2,15 +2,11 @@ # Licensed under the MIT License. Describe "New-Alias DRT Unit Tests" -Tags "CI" { It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{ - try { + $e = { New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true New-Alias -Name "ABCD" -Value "foo" -Force:$true -ErrorAction Stop - Throw "Execution OK" - } - catch { - $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.| Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" - } + } | Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } It "New-Alias NamePositional And Value Valid" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 96ca6188d39..03d76ef245e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -23,14 +23,9 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable variable twice should throw Exception"{ New-Variable foo bogus - try { - New-Variable foo bar -EA Stop - Throw "Execution OK" - } - catch { - $_.CategoryInfo| Should -Match "SessionStateException" - $_.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" - } + { New-Variable foo bar -EA Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateException" + New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" @@ -42,14 +37,9 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable ReadOnly variable twice should throw Exception"{ New-Variable foo bogus -option ReadOnly - try { - New-Variable foo bar -EA Stop - Throw "Execution OK" - } - catch { - $_.CategoryInfo| Should -Match "SessionStateException" - $_.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" - } + { New-Variable foo bar -EA Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateException" + New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" @@ -187,7 +177,7 @@ Describe "New-Variable" -Tags "CI" { } It "Should not be able to see the value of a private variable when out of scope" { - {New-Variable -Name var1 -Value 1 -Option Private}| Should -Not -Throw + {New-Variable -Name var1 -Value 1 -Option Private} | Should -Not -Throw $var1 | Should -BeNullOrEmpty } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 index c888714a35f..091d4c883fb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 @@ -60,6 +60,6 @@ Describe "Out-String" -Tags "CI" { It "Should throw error when NoNewLine and Stream are used together" { $testArray = "a", "b" - { $testArray | Out-String -NoNewLine -Stream }| ShouldBeErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand" + { $testArray | Out-String -NoNewLine -Stream } | ShouldBeErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index 1627fd97fcf..789862d81b7 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -3,13 +3,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { It "Set-Alias Invalid Scope Name should throw PSArgumentException"{ - try { - Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus" - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" - } + { Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus" } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand" } It "Set-Alias ReadOnly Force"{ @@ -75,13 +69,7 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { $result.Options| Should -Be "None" } It "Set-Alias Expose Bug 1062958, BugId:905449"{ - try { - Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" - } + { Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 index 8bb0e26c750..d05635977a8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 @@ -137,24 +137,12 @@ set-psbreakpoint -command foo } It "Should be throw Exception when Column number less than 1" { - try { - set-psbreakpoint -line 1 -column -1 -script $scriptFileName - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" - } + { set-psbreakpoint -line 1 -column -1 -script $scriptFileName } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" } It "Should be throw Exception when Line number less than 1" { $ErrorActionPreference = "Stop" - try { - set-psbreakpoint -line -1 -script $scriptFileName - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" - } + { set-psbreakpoint -line -1 -script $scriptFileName } | Should -Throw -ErrorId "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" $ErrorActionPreference = "SilentlyContinue" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 14e606ad211..544d377a260 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -91,13 +91,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable overwrite Constant Option should throw SessionStateUnauthorizedAccessException"{ Set-Variable -Name abcaVar bar -Option Constant -Scope "local" - try { - Set-Variable -Name abcaVar new -Scope "local" -EA Stop - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" - } + { Set-Variable -Name abcaVar new -Scope "local" -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } It "Set-Variable of existing Private variable without force should throw Exception"{ @@ -118,13 +112,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable with Exclude, then Get-Variable it should throw ItemNotFoundException"{ Set-Variable -Name foo1,foo2 hello -Exclude foo2 -EA Stop - try { - Get-Variable -Name foo2 -EA Stop - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + { Get-Variable -Name foo2 -EA Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } It "Set-Variable of existing ReadOnly variable without force should throw Exception"{ @@ -134,13 +122,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Value|Should -Be "bar" $var1.Options|Should -Be "ReadOnly" $var1.Description|Should -Be "new description" - try { - Set-Variable abcaVar -Option None -EA Stop - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" - } + { Set-Variable abcaVar -Option None -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } It "Set-Variable of ReadOnly variable with private scope should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index e5beb107728..a43d5c72989 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -52,7 +52,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript("Update-TypeData -PrependPath $testfile") $ps.Invoke() $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorID | Should -Be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid File Extension should throw Exception"{ @@ -61,7 +61,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") $ps.Invoke() $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].| Should -Throw -ErrorId "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Throw -ErrorId "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Dynamic Type NoteProperty with Force should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index bd2981fc519..8677b3393b1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -473,8 +473,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3' $command = "Invoke-WebRequest -Uri '$uri' -MaximumRedirection 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Invoke-WebRequest supports request that returns page containing UTF-8 data." { @@ -492,16 +491,14 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } $testCase = @( @@ -515,8 +512,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -Proxy '${proxy_address}' -SkipCertificateCheck" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with environment proxy set - ''" -TestCases $testCase { @@ -528,8 +524,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns User-Agent where -NoProxy with envirionment proxy set - ''" -TestCases $testCase { @@ -1161,8 +1156,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # validate that exception is thrown for URI with expired certificate $Uri = Get-WebListenerUrl -Https $command = "Invoke-WebRequest -Uri '$Uri'" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $Uri = Get-WebListenerUrl -Https @@ -1178,7 +1172,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" { @@ -1717,8 +1711,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3' $command = "Invoke-RestMethod -Uri '$uri' -MaximumRedirection 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Invoke-RestMethod supports request that returns page containing UTF-8 data." { @@ -1733,16 +1726,14 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } $testCase = @( @@ -1757,8 +1748,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = 'http://httpbin.org' $command = "Invoke-RestMethod -Uri '$uri' -Proxy '${proxy_address}'" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with environment proxy set - ''" -TestCases $testCase { @@ -1770,8 +1760,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod returns User-Agent with option -NoProxy when environment proxy set - ''" -TestCases $testCase { @@ -1929,7 +1918,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" { @@ -2161,8 +2150,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # validate that exception is thrown for URI with expired certificate $uri = Get-WebListenerUrl -Https $command = "Invoke-RestMethod -Uri '$uri' -Method HEAD" - $result = ExecuteWebCommand -command $command - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $command = "Invoke-RestMethod -Uri '$uri' -SkipCertificateCheck -Method HEAD" @@ -2177,7 +2165,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" { @@ -2856,12 +2844,7 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu It "" -TestCases $testCases { param ($scriptblock, $expectedFullyQualifiedErrorId) - try { - & $scriptblock - throw "No Exception!" - } catch { - $_.| Should -Throw -ErrorId $ExpectedFullyQualifiedErrorId - } + { & $scriptblock } | Should -Throw -ErrorId $ExpectedFullyQualifiedErrorId } } From aaf2133e1628b70a08faee62ad62fd05f27c5942 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 10:38:38 -0700 Subject: [PATCH 07/21] [Feature] New pester syntax for tests in module Microsoft.WSMan.Management. --- .../ConfigProvider.Tests.ps1 | 110 +++++++++--------- .../CredSSP.Tests.ps1 | 24 ++-- .../TestWSMan.Tests.ps1 | 12 +- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1 index c2d332b3bfa..9e144aa6e8c 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1 @@ -34,15 +34,15 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { } Function Test-Plugin($plugin, $expectedMissingProperties, $expectedMissingAttributes) { - $plugin.PSPath | Should Exist + $plugin.PSPath | Should -Exist $testPluginXml = [xml](winrm g winrm/config/plugin?name=$($plugin.Name) -format:xml) $pluginProperties = Get-ChildItem $plugin.PSPath $xmlElementCount = ($testPluginXml.PluginConfiguration | Get-Member -Type Properties).Count + $expectedMissingProperties.Count - $expectedMissingAttributes.Count - $pluginProperties.Count | Should BeExactly $xmlElementCount + $pluginProperties.Count | Should -BeExactly $xmlElementCount foreach ($pluginProperty in $pluginProperties) { if ($pluginProperty.Type -eq "System.String") { - $pluginProperty.Value | Should Be $testPluginXml.PluginConfiguration.$($pluginProperty.Name) - (Get-Item "$($plugin.PSPath)\$($pluginProperty.Name)").Value | Should Be $testPluginXml.PluginConfiguration.$($pluginProperty.Name) + $pluginProperty.Value | Should -Be $testPluginXml.PluginConfiguration.$($pluginProperty.Name) + (Get-Item "$($plugin.PSPath)\$($pluginProperty.Name)").Value | Should -Be $testPluginXml.PluginConfiguration.$($pluginProperty.Name) } } } @@ -60,16 +60,16 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { Remove-PSDrive -Name wsman { Get-PSDrive -Name wsman -ErrorAction Stop } | ShouldBeErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand" $wsmanDrive2 = $wsmanDrive | New-PSDrive -PSProvider WSMan - $wsmanDrive2 | Should BeOfType System.Management.Automation.PSDriveInfo - $wsmanDrive2.Name | Should BeExactly "WSMan" - $wsmanDrive2.Provider.Name | Should BeExactly "WSMan" + $wsmanDrive2 | Should -BeOfType System.Management.Automation.PSDriveInfo + $wsmanDrive2.Name | Should -BeExactly "WSMan" + $wsmanDrive2.Provider.Name | Should -BeExactly "WSMan" } It "WSMan Config Provider starts WinRM if it is stopped" { try { Stop-Service WinRM - Get-ChildItem wsman:\localhost -Force | Should Not BeNullOrEmpty - (Get-Service WinRM).Status | Should Be 'Running' + Get-ChildItem wsman:\localhost -Force | Should -Not -BeNullOrEmpty + (Get-Service WinRM).Status | Should -Be 'Running' } finally { if ((Get-Service WinRM).Status -eq 'stopped') { @@ -88,41 +88,41 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { It "Plugin InitializationParameters are correct" { $initializationParameters = Get-ChildItem $pluginPath\InitializationParameters - $initializationParameters.Count | Should Be (,$pluginXml.PluginConfiguration.InitializationParameters.Param).Count + $initializationParameters.Count | Should -Be (,$pluginXml.PluginConfiguration.InitializationParameters.Param).Count foreach ($initializationParameter in $initializationParameters) { - $initializationParameter.Value | Should Be ($pluginXml.PluginConfiguration.InitializationParameters | Where-Object { $_.Param.Name -eq $initializationParameter.Name }).Param.Value - (Get-Item $pluginPath\InitializationParameters\$($initializationParameter.Name)).Value | Should Be ($pluginXml.PluginConfiguration.InitializationParameters | Where-Object { $_.Param.Name -eq $initializationParameter.Name }).Param.Value + $initializationParameter.Value | Should -Be ($pluginXml.PluginConfiguration.InitializationParameters | Where-Object { $_.Param.Name -eq $initializationParameter.Name }).Param.Value + (Get-Item $pluginPath\InitializationParameters\$($initializationParameter.Name)).Value | Should -Be ($pluginXml.PluginConfiguration.InitializationParameters | Where-Object { $_.Param.Name -eq $initializationParameter.Name }).Param.Value } } It "Plugin Quotas are correct" { $quotas = Get-ChildItem $pluginPath\Quotas - $quotas.Count | Should Be ($pluginXml.PluginConfiguration.Quotas | Get-Member -Type Properties).Count + $quotas.Count | Should -Be ($pluginXml.PluginConfiguration.Quotas | Get-Member -Type Properties).Count foreach ($quota in $quotas) { - $quota.Value | Should Be $pluginXml.PluginConfiguration.Quotas.$($quota.Name) + $quota.Value | Should -Be $pluginXml.PluginConfiguration.Quotas.$($quota.Name) } } It "Plugin Resources are correct" { $resources = Get-ChildItem $pluginPath\Resources - $resources.Count | Should Be (,$pluginXml.PluginConfiguration.Resources.Resource).Count + $resources.Count | Should -Be (,$pluginXml.PluginConfiguration.Resources.Resource).Count } It "Plugin Security Resource is correct" { - (,$pluginXml.PluginConfiguration.Resources.Resource).Count | Should Be 1 # by default only Security resource should be there + (,$pluginXml.PluginConfiguration.Resources.Resource).Count | Should -Be 1 # by default only Security resource should be there $resource = Get-ChildItem "$pluginPath\Resources" | Select-Object -First 1 $resourceUri = Get-Item "$($resource.PSPath)\ResourceUri" - $resourceUri.Value | Should Be "http://schemas.microsoft.com/powershell/microsoft.powershell" + $resourceUri.Value | Should -Be "http://schemas.microsoft.com/powershell/microsoft.powershell" $securityContainer = Get-ChildItem "$pluginPath\Resources\$($resource.Name)\Security" | Select-Object -First 1 $securityProperties = Get-ChildItem $securityContainer.PSPath $skippedAttributes = @("ParentResourceUri","xmlns") # these are added by the WSMan Config Provider but not in the original xml # ParentResourceUri is added by the Config Provider, xmlns existing seems to be dependent on WinRM which is inconsistent - $securityProperties.Count | Should BeGreaterThan (($pluginXml.PluginConfiguration.Resources.Resource.Security | Get-Member -Type Properties).Count) + $securityProperties.Count | Should -BeGreaterThan (($pluginXml.PluginConfiguration.Resources.Resource.Security | Get-Member -Type Properties).Count) foreach ($securityProperty in $securityProperties) { if ($skippedAttributes -notcontains $securityProperty.Name) { - $securityProperty.Value | Should Be ($pluginXml.PluginConfiguration.Resources.Resource.Security.$($securityProperty.Name)) - (Get-Item "$($securityContainer.PSPath)\$($securityProperty.Name)").Value | Should Be ($pluginXml.PluginConfiguration.Resources.Resource.Security.$($securityProperty.Name)) + $securityProperty.Value | Should -Be ($pluginXml.PluginConfiguration.Resources.Resource.Security.$($securityProperty.Name)) + (Get-Item "$($securityContainer.PSPath)\$($securityProperty.Name)").Value | Should -Be ($pluginXml.PluginConfiguration.Resources.Resource.Security.$($securityProperty.Name)) } } } @@ -145,7 +145,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $trustedHostsPath = "WSMan:\localhost\Client\TrustedHosts" $trustedHosts = Get-Item $trustedHostsPath Set-Item $trustedHostsPath "hello" -WhatIf - (Get-Item $trustedHostsPath).Value | Should Be $trustedHosts.Value + (Get-Item $trustedHostsPath).Value | Should -Be $trustedHosts.Value } It "Set-Item on TrustedHosts should succeed" { @@ -153,7 +153,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $trustedHostsPath = "WSMan:\localhost\Client\TrustedHosts\" $trustedHosts = Get-Item $trustedHostsPath Set-Item -Path $trustedHostsPath -Value "hello" -Force - (Get-Item $trustedHostsPath).Value | Should Be "hello" + (Get-Item $trustedHostsPath).Value | Should -Be "hello" } finally { Set-Item $trustedHostsPath $trustedHosts.Value -Force @@ -165,18 +165,18 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $password = ConvertTo-SecureString "My voice is my passport, verify me" -AsPlainText -Force $creds = [pscredential]::new((Get-Random),$password) $exception = { Set-Item $testPluginPath\RunAsUser $creds } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand" - $exception.Exception.Message | Should Match ".*$badCredentialError.*" + $exception.Exception.Message | Should -Match ".*$badCredentialError.*" } It "Set-Item and Clear-Item on plugin RunAsUser should succeed for valid creds" { $password = ConvertTo-SecureString $testPass -AsPlainText -Force $creds = [pscredential]::new($testUser,$password) Set-Item $testPluginPath\RunAsUser $creds -WarningAction SilentlyContinue - (Get-Item $testPluginPath\RunAsUser).Value | Should Be $testUser - (Get-Item $testPluginPath\RunAsPassword).Value | Should Be "System.Security.SecureString" + (Get-Item $testPluginPath\RunAsUser).Value | Should -Be $testUser + (Get-Item $testPluginPath\RunAsPassword).Value | Should -Be "System.Security.SecureString" Clear-Item $testPluginPath\RunAsUser -WarningAction SilentlyContinue - (Get-Item $testPluginPath\RunAsUser).Value | Should BeNullOrEmpty - (Get-Item $testPluginPath\RunAsPassword).Value | Should BeNullOrEmpty + (Get-Item $testPluginPath\RunAsUser).Value | Should -BeNullOrEmpty + (Get-Item $testPluginPath\RunAsPassword).Value | Should -BeNullOrEmpty } It "Set-Item on plugin RunAsUser should fail for invalid password" { @@ -184,7 +184,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $password = ConvertTo-SecureString "My voice is my passport, verify me" -AsPlainText -Force $creds = [pscredential]::new($testUser,$password) $exception = { Set-Item $testPluginPath\RunAsUser $creds } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand" - $exception.Exception.Message | Should Match ".*$badCredentialError.*" + $exception.Exception.Message | Should -Match ".*$badCredentialError.*" } It "Set-Item on password without user on plugin should fail for " -TestCases @( @@ -206,7 +206,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { ) { param ($type) Set-Item $testPluginPath\XmlRenderingType $type -WarningAction SilentlyContinue - (Get-Item $testPluginPath\XmlRenderingType).Value | Should Be $type + (Get-Item $testPluginPath\XmlRenderingType).Value | Should -Be $type } It "Set-Item on non-existent property should fail" { @@ -220,7 +220,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { param($property, $value, $expected) $resource = Get-ChildItem "$testPluginPath\Resources" | Select-Object -First 1 Set-Item "$($resource.PSPath)\$property" $value -WarningAction SilentlyContinue - (Get-Item "$($resource.PSPath)\$property").Value | Should BeExactly $expected + (Get-Item "$($resource.PSPath)\$property").Value | Should -BeExactly $expected } It "Set-Item on plugin Security Resource '' property with '' should succeed" -TestCases @( @@ -233,7 +233,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $resource = Get-ChildItem "$testPluginPath\Resources" | Select-Object -First 1 $security = Get-ChildItem "$($resource.PSPath)\Security" | Select-Object -First 1 Set-Item "$($security.PSPath)\$property" $value -WarningAction SilentlyContinue -Force - (Get-Item "$($security.PSPath)\$property").Value | Should Be $value + (Get-Item "$($security.PSPath)\$property").Value | Should -Be $value } It "Set-Item on plugin Security Resource '' property with invalid '' should fail" -TestCases @( @@ -252,7 +252,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { ) { param($property, $value) Set-Item "$testPluginPath\InitializationParameters\$property" $value -WarningAction SilentlyContinue - (Get-Item "$testPluginPath\InitializationParameters\$property").Value | Should Be $value + (Get-Item "$testPluginPath\InitializationParameters\$property").Value | Should -Be $value } It "Set-Item on plugin Quotas '' property with '' should succeed" -TestCases @( @@ -263,7 +263,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { ) { param($property, $value) Set-Item "$testPluginPath\Quotas\$property" $value -WarningAction SilentlyContinue - (Get-Item "$testPluginPath\Quotas\$property").Value | Should Be $value + (Get-Item "$testPluginPath\Quotas\$property").Value | Should -Be $value } It "Set-Item on plugin Quotas out of range on '' property with '' should fail" -TestCases @( @@ -294,13 +294,13 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { try { $connections = Get-ChildItem wsman:\ $newItem = New-Item WSMan:\$name - "WSMan:\$name" | Should Exist - (Get-ChildItem wsman:\).Count | Should Be ($connections.Count + 1) + "WSMan:\$name" | Should -Exist + (Get-ChildItem wsman:\).Count | Should -Be ($connections.Count + 1) # not a .Net type so can't use BeOfType - $newItem.PSObject.TypeNames[0] | Should Be "Microsoft.WSMan.Management.WSManConfigContainerElement#ComputerLevel" - $newItem.Name | Should Be $expected + $newItem.PSObject.TypeNames[0] | Should -Be "Microsoft.WSMan.Management.WSManConfigContainerElement#ComputerLevel" + $newItem.Name | Should -Be $expected Remove-Item WSMan:\$name -Recurse -Force - "WSMan:\$name" | Should Not Exist + "WSMan:\$name" | Should -Not -Exist } finally { Remove-Item WSMan:\$name -Recurse -Force -ErrorAction SilentlyContinue @@ -311,18 +311,18 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { try { $newListener = New-Item -Path WSMan:\localhost\Listener\ -Address IP:127.0.0.1 -port 6666 -Transport HTTP -Enabled $false -HostName foo -URLPrefix bar -Force $listenerName = $newListener.Name - $listenerName | Should Not BeNullOrEmpty + $listenerName | Should -Not -BeNullOrEmpty $properties = Get-ChildItem "WSMan:\localhost\Listener\$listenerName" $listenerXml = [xml](winrm g winrm/config/listener?Address=IP:127.0.0.1+Transport=HTTP -format:xml) $expectedMissingAttributes = "cfg","xsi","lang" - $properties.Count | Should Be (($listenerXml.Listener | Get-Member -Type Properties).Count - $expectedMissingAttributes.Count) + $properties.Count | Should -Be (($listenerXml.Listener | Get-Member -Type Properties).Count - $expectedMissingAttributes.Count) foreach ($property in $properties) { if (-not $property.Name.StartsWith("ListeningOn")) { # this property is represented differently - $property.Value | Should Be $listenerXml.Listener.$($property.Name) + $property.Value | Should -Be $listenerXml.Listener.$($property.Name) } } Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Recurse -Force - $newListener.PSPath | Should Not Exist + $newListener.PSPath | Should -Not -Exist } finally { Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Recurse -Force -ErrorAction SilentlyContinue @@ -340,7 +340,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $expectedMissingProperties = @("InitializationParameters") Test-Plugin -Plugin $plugin -expectedMissingProperties $expectedMissingProperties Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force - "WSMan:\localhost\Plugin\TestPlugin2" | Should Not Exist + "WSMan:\localhost\Plugin\TestPlugin2" | Should -Not -Exist } finally { Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force -ErrorAction SilentlyContinue @@ -371,7 +371,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $plugin = New-Item -Path WSMan:\localhost\Plugin -File $testdrive\plugin.xml -Name TestPlugin2 Test-Plugin -Plugin $plugin Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force - "WSMan:\localhost\Plugin\TestPlugin2\" | Should Not Exist + "WSMan:\localhost\Plugin\TestPlugin2\" | Should -Not -Exist } finally { Remove-Item "WSMan:\localhost\Plugin\TestPlugin2\" -Recurse -Force -ErrorAction SilentlyContinue @@ -382,12 +382,12 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { try { $resource = New-Item -Path WSMan:\localhost\Plugin\TestPlugin\Resources\ ` -ResourceUri http://foo -Capability shell - $resource.PSPath | Should Exist + $resource.PSPath | Should -Exist $properties = Get-ChildItem $resource.PSPath - ($properties | Where-Object { $_.Name -eq "ResourceUri" }).Value | Should Be "http://foo/" - ($properties | Where-Object { $_.Name -eq "Capability" })[0].Value | Should Be "shell" + ($properties | Where-Object { $_.Name -eq "ResourceUri" }).Value | Should -Be "http://foo/" + ($properties | Where-Object { $_.Name -eq "Capability" })[0].Value | Should -Be "shell" Remove-Item $resource.PSPath -Recurse -Force - $resource.PSPath | Should Not Exist + $resource.PSPath | Should -Not -Exist } finally { Remove-Item $resource.PSPath -Recurse -Force -ErrorAction SilentlyContinue @@ -399,10 +399,10 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { $parameter = New-Item -Path WSMan:\localhost\Plugin\TestPlugin\InitializationParameters ` -ParamName foo -ParamValue bar $parameterObj = Get-Item $parameter.PSPath - $parameterObj.Name | Should Be "foo" - $parameterObj.Value | Should Be "bar" + $parameterObj.Name | Should -Be "foo" + $parameterObj.Value | Should -Be "bar" Remove-Item $parameter.PSPath -Force - $parameter.PSPath | Should Not Exist + $parameter.PSPath | Should -Not -Exist } finally { Remove-Item $parameter.PSPath -Force -ErrorAction SilentlyContinue @@ -416,11 +416,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { # remove existing security resource since the folder name is just a hash of the resource uri Get-ChildItem "$($resource.PSPath)\Security" | Remove-Item -Recurse -Force $security = New-Item "$($resource.PSPath)\Security" -SDDL $sddl -Force - $security.PSPath | Should Exist + $security.PSPath | Should -Exist $securityObj = Get-Item $security.PSPath - (Get-ChildItem $securityObj.PSPath | Where-Object { $_.Name -eq 'sddl' }).Value | Should Be $sddl + (Get-ChildItem $securityObj.PSPath | Where-Object { $_.Name -eq 'sddl' }).Value | Should -Be $sddl Remove-Item $security.PSPath -Recurse -Force - $security.PSPath | Should Not Exist + $security.PSPath | Should -Not -Exist } finally { Remove-Item $security.PSPath -Recurse -Force -ErrorAction SilentlyContinue @@ -432,7 +432,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows { It "Get-Help while in WSMan: drive works" { try { Push-Location WSMan:\localhost - Get-Help New-Item | Should Not BeNullOrEmpty + Get-Help New-Item | Should -Not -BeNullOrEmpty } finally { Pop-Location diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index 027373f6305..adf202d379e 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -49,16 +49,16 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { ) { param ($params) $c = Enable-WSManCredSSP @params -Force - $c.CredSSP | Should Be $true + $c.CredSSP | Should -Be $true $c = Get-WSManCredSSP if ($params.Role -eq "Client") { - $c[0] | Should Match "The machine is configured to allow delegating fresh credentials to the following target\(s\):wsman/\*" + $c[0] | Should -Match "The machine is configured to allow delegating fresh credentials to the following target\(s\):wsman/\*" } else { - $c[1] | Should Match "This computer is configured to receive credentials from a remote client computer" + $c[1] | Should -Match "This computer is configured to receive credentials from a remote client computer" } } @@ -67,31 +67,31 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { @{Role="Server"} ) { param ($role) - Disable-WSManCredSSP -Role $role | Should BeNullOrEmpty + Disable-WSManCredSSP -Role $role | Should -BeNullOrEmpty $c = Get-WSManCredSSP if ($role -eq "Client") { - $c[0] | Should Match "The machine is not configured to allow delegating fresh credentials." + $c[0] | Should -Match "The machine is not configured to allow delegating fresh credentials." } else { - $c[1] | Should Match "This computer is not configured to receive credentials from a remote client computer" + $c[1] | Should -Match "This computer is not configured to receive credentials from a remote client computer" } } It "Call cmdlet as API" { $credssp = [Microsoft.WSMan.Management.EnableWSManCredSSPCommand]::new() $credssp.Role = "Client" - $credssp.Role | Should BeExactly "Client" + $credssp.Role | Should -BeExactly "Client" $credssp.DelegateComputer = "foo", "bar" - $credssp.DelegateComputer -join ',' | Should Be "foo,bar" + $credssp.DelegateComputer -join ',' | Should -Be "foo,bar" $credssp.Force = $true - $credssp.Force | Should Be $true + $credssp.Force | Should -Be $true $credssp = [Microsoft.WSMan.Management.DisableWSManCredSSPCommand]::new() $credssp.Role = "Server" - $credssp.Role | Should BeExactly "Server" + $credssp.Role | Should -BeExactly "Server" } It "Error returned if runas non-admin: " -TestCases @( @@ -103,8 +103,8 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline } catch { `$_.FullyQualifiedErrorId | Out-File $errtxt }; New-Item -Type File -Path $donefile" Wait-FileToBePresent -File $donefile -TimeoutInSeconds 5 -IntervalInMilliseconds 100 - $errtxt | Should Exist + $errtxt | Should -Exist $err = Get-Content $errtxt - $err | Should Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" + $err | Should -Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" } } diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/TestWSMan.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/TestWSMan.Tests.ps1 index 2aabc48ad65..15c3d78c61e 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/TestWSMan.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/TestWSMan.Tests.ps1 @@ -39,7 +39,7 @@ Describe "TestWSMan tests" -Tags 'Feature' { if ($expected -eq $null) { $expected = $value } - $testWsman.$parameter | Should Be $expected + $testWsman.$parameter | Should -Be $expected } It "-Authentication for unsupported type should return error" { @@ -53,10 +53,10 @@ Describe "TestWSMan tests" -Tags 'Feature' { ) { param($computername) $response = Test-WSMan -ComputerName $computername - $response.PSObject.TypeNames[0] | Should Be "System.Xml.XmlElement#http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd#IdentifyResponse" - $response.wsmid | Should Be "http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd" - $response.ProtocolVersion | Should Be "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" - $response.ProductVendor | Should Be "Microsoft Corporation" - $response.ProductVersion | Should Be "OS: 0.0.0 SP: 0.0 Stack: 3.0" + $response.PSObject.TypeNames[0] | Should -Be "System.Xml.XmlElement#http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd#IdentifyResponse" + $response.wsmid | Should -Be "http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd" + $response.ProtocolVersion | Should -Be "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" + $response.ProductVendor | Should -Be "Microsoft Corporation" + $response.ProductVersion | Should -Be "OS: 0.0.0 SP: 0.0 Stack: 3.0" } } From ca3a716e52e8c6d0f883dcea9464d66d1e050809 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 11:15:23 -0700 Subject: [PATCH 08/21] [Feature] Tests correction --- .../Add-Member.Tests.ps1 | 8 ++-- .../Get-Alias.Tests.ps1 | 38 +++---------------- .../Get-FileHash.Tests.ps1 | 24 ++---------- .../Get-Variable.Tests.ps1 | 23 +++-------- .../Get-Verb.Tests.ps1 | 9 +---- .../JsonObject.Tests.ps1 | 4 +- 6 files changed, 22 insertions(+), 84 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 index 3afa5197892..3c81fa00cbf 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 @@ -10,7 +10,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { { Add-Member -Name "" } | Should -Throw -ErrorId "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" # when MemberType is null - { Add-Member -MemberType $null } | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" + { Add-Member -MemberType $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" # when MemberType is empty { Add-Member -MemberType "" } | Should -Throw -ErrorId "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.AddMemberCommand" @@ -51,7 +51,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } It "Fail to add unexisting type" { - { Add-Member -InputObject a -MemberType AliasProperty -Name Name -Value something -SecondValue unexistingType } + { Add-Member -InputObject a -MemberType AliasProperty -Name Name -Value something -SecondValue unexistingType } | Should -Throw -ErrorId "InvalidCastFromStringToType,Microsoft.PowerShell.Commands.AddMemberCommand" } @@ -92,8 +92,8 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { } It "ScriptMethod Reference Wrong Type" { - { Add-Member -InputObject a -MemberType ScriptMethod -Name Name -Value something } - | Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" + { Add-Member -InputObject a -MemberType ScriptMethod -Name Name -Value something } | + Should -Throw -ErrorId "ConvertToFinalInvalidCastException,Microsoft.PowerShell.Commands.AddMemberCommand" } It "Add ScriptMethod Success" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index dfd59dafd7d..5bc449cba9f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -3,22 +3,10 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { It "Get-Alias Bogus Scope Name should throw PSArgumentException"{ - try { - Get-Alias -Name "ABCD" -Scope "bogus" - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" - } + { Get-Alias -Name "ABCD" -Scope "bogus" } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.GetAliasCommand" } It "Get-Alias OutOfRange Scope"{ - try { - Get-Alias -Name "ABCD" -Scope "99999" - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" - } + { Get-Alias -Name "ABCD" -Scope "99999" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } It "Get-Alias Named Single Valid"{ Set-Alias -Name ABCD -Value "foo" @@ -141,13 +129,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $result.Options| Should -Be "None" } It "Get-Alias Expose Bug 1065828, BugId:905235"{ - try { - Get-Alias -Name "ABCD" -Scope "100" - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" - } + { Get-Alias -Name "ABCD" -Scope "100" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" } It "Get-Alias Zero Scope Valid"{ Set-Alias -Name ABCD -Value "foo" @@ -226,23 +208,13 @@ Describe "Get-Alias null tests" -Tags "CI" { Context 'Check null or empty value to the -Name parameter' { It 'Should throw if is passed to -Name parameter' -TestCases $testCases { param($data) - try - { - Get-Alias -Name $data - throw "No Exception!" - } - catch { $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + { Get-Alias -Name $data } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } Context 'Check null or empty value to the -Name parameter via pipeline' { It 'Should throw if is passed through pipeline to -Name parameter' -TestCases $testCases { param($data) - try - { - $data | Get-Alias -ErrorAction Stop - throw "No Exception!" - } - catch { $_.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } + { $data | Get-Alias -ErrorAction Stop } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAliasCommand' } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 index 65abea35ad7..de4d8646bde 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 @@ -33,35 +33,17 @@ Describe "Get-FileHash" -Tags "CI" { } It "Should be throw for wrong algorithm name" { - try { - Get-FileHash Get-FileHash $testDocument -Algorithm wrongAlgorithm - throw "No Exception!" - } - catch { - $_.| Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" - } + { Get-FileHash Get-FileHash $testDocument -Algorithm wrongAlgorithm } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetFileHashCommand" } } Context "Paths tests" { It "With '-Path': no file exist" { - try { - Get-FileHash -Path nofileexist.ttt -ErrorAction Stop - throw "No Exception!" - } - catch { - $_.| Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" - } + { Get-FileHash -Path nofileexist.ttt -ErrorAction Stop } | Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } It "With '-LiteralPath': no file exist" { - try { - Get-FileHash -LiteralPath nofileexist.ttt -ErrorAction Stop - throw "No Exception!" - } - catch { - $_.| Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" - } + { Get-FileHash -LiteralPath nofileexist.ttt -ErrorAction Stop } | Should -Throw -ErrorId "FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand" } It "With '-Path': file exist" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 index 25bcb9f39ea..2c8802209a0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 @@ -3,13 +3,8 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { It "Get-Variable of not existing variable Name should throw ItemNotFoundException"{ - try { - Get-Variable -EA Stop -Name nonexistingVariableName - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + { Get-Variable -EA Stop -Name nonexistingVariableName } | + Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } It "Get-Variable of existing variable Name with include and bogus exclude should work"{ @@ -43,14 +38,9 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { } It "Get-Variable of existing private variable Name should throw ItemNotFoundException"{ - try { - Set-Variable newVar testing -Option Private - &{Get-Variable -Name newVar -EA Stop} - Throw "Execution OK" - } - catch { - $_.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + Set-Variable newVar testing -Option Private + {Get-Variable -Name newVar -EA Stop} | + Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } } @@ -147,8 +137,7 @@ Describe "Get-Variable" -Tags "CI" { It "Should not be able to clear a global scope variable using the local switch" { New-Variable globalVar -Value 1 -Scope global -Force - Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue -ErrorVariable removeGlobalAsLocal - $removeGlobalAsLocal.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + { Get-Variable -Name globalVar -Scope local -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" } It "Should be able to get a global variable when there's one in the script scope" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 index 55c26de2d20..4236c420116 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Verb.Tests.ps1 @@ -34,13 +34,8 @@ Describe "Get-Verb" -Tags "CI" { } It "Should not accept Groups that are not in the validate set" { - try{ - Get-Verb -Group FakeGroupNeverExists -ErrorAction Stop - throw "Expected error did not occur" - } - Catch{ - $PSItem.| Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' - } + { Get-Verb -Group FakeGroupNeverExists -ErrorAction Stop } | + Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetVerbCommand' } It "Accept all valid verb groups" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 index eba2a3108ca..7c6e0a7d64f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/JsonObject.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains empty key name' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonWithEmptyKey, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should -Throw -ErrorId 'EmptyKeyInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -BeExactly 'EmptyKeyInJsonString' } It 'Not throw when json contains empty key name when ReturnHashTable is true' { @@ -55,7 +55,7 @@ Describe 'Unit tests for JsonObject' -tags "CI" { It 'Throw InvalidOperationException when json contains key with different casing' { $errorRecord = $null [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($jsonContainingKeysWithDifferentCasing, [ref]$errorRecord) - $errorRecord.FullyQualifiedErrorId | Should -Throw -ErrorId 'KeysWithDifferentCasingInJsonString' + $errorRecord.FullyQualifiedErrorId | Should -BeExactly 'KeysWithDifferentCasingInJsonString' } It 'Not throw when json contains key (same casing) when ReturnHashTable is true' { From 7691f6618e17af4dd8551b70c099e241260a8df9 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 11:37:28 -0700 Subject: [PATCH 09/21] [Feature] Tests correction --- .../Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 | 7 +++---- .../Microsoft.PowerShell.Utility/New-Object.Tests.ps1 | 6 +++--- .../Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 | 3 +-- .../Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 | 5 ++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 56563dc06f4..5ca10afca9d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -2,10 +2,9 @@ # Licensed under the MIT License. Describe "New-Alias DRT Unit Tests" -Tags "CI" { It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{ - $e = { - New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true - New-Alias -Name "ABCD" -Value "foo" -Force:$true -ErrorAction Stop - } | Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true + $e = { New-Alias -Name "ABCD" -Value "foo" -Force:$true -ErrorAction Stop } | + Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index 3c40cee202b..1a6e794e039 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -90,7 +90,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { It "New-Object with invalid argument should throw Exception"{ $e = { New-Object -TypeName System.Management.Automation.PSVariable -ArgumentList "A", 1, None, "asd" -EA Stop } | - | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "MethodException" } @@ -105,7 +105,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "MethodException" } @@ -120,7 +120,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { It "New-Object with Private Nested class should throw Exception"{ Add-Type -TypeDefinition "public class WeirdEmployee{public WeirdEmployee(){}private class PrivateNestedWeirdEmployee{public PrivateNestedWeirdEmployee(){}}}" - $e = {New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = {New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "PSArgumentException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 03d76ef245e..918da2fd13e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -78,8 +78,7 @@ Describe "New-Variable" -Tags "CI" { It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" { New-Variable var1 - New-Variable var1 -ErrorAction SilentlyContinue -ErrorVariable newWhenExists - $newWhenExists.| Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + { New-Variable var1 -ErrorAction Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } It "Should change the value of an already existing variable using the Force switch" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 8281008caa3..71c274313be 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -8,8 +8,7 @@ Describe "Remove-Variable" -Tags "CI" { It "Should throw an error when a dollar sign is used in the variable name place" { New-Variable -Name var1 -Value 4 - Remove-Variable $var1 -ErrorAction SilentlyContinue -ErrorVariable err - $err.| Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" + { Remove-Variable $var1 -ErrorAction Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand" } It "Should not throw error when used without the Name field, and named variable is properly specified and exists" { @@ -213,7 +212,7 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { $e = { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $e = { Remove-Variable foo -Force -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand + $e = { Remove-Variable foo -Force -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } From 8ce3d4de50776aea788edd05729bf5dd24dca141 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 12:37:03 -0700 Subject: [PATCH 10/21] Tests correction --- .../New-Object.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index 1a6e794e039..f212e913319 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -84,20 +84,20 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } It "New-Object with invalid type should throw Exception"{ - $e = { New-Object -TypeName LiarType -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName LiarType -EA Stop } | ShouldBeErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "PSArgumentException" } It "New-Object with invalid argument should throw Exception"{ $e = { New-Object -TypeName System.Management.Automation.PSVariable -ArgumentList "A", 1, None, "asd" -EA Stop } | - Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "MethodException" } It "New-Object with abstract class should throw Exception"{ Add-Type -TypeDefinition "public abstract class AbstractEmployee{public AbstractEmployee(){}}" - $e = { New-Object -TypeName AbstractEmployee -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" - $e.CategoryInfo | Should -Match "MethodInvocationException + $e = { New-Object -TypeName AbstractEmployee -EA Stop } | ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e.CategoryInfo | Should -Match "MethodInvocationException" } It "New-Object with bad argument for class constructor should throw Exception"{ @@ -105,7 +105,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - $e = { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "MethodException" } @@ -113,14 +113,14 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { It "New-Object with not init class constructor should throw Exception" -Pending{ if(-not ([System.Management.Automation.PSTypeName]'Employee').Type) { - Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" + Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - { New-Object -TypeName Employee -EA Stop } | Should -Throw -ErrorId "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" + { New-Object -TypeName Employee -EA Stop } | ShouldBeErrorId "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" } It "New-Object with Private Nested class should throw Exception"{ Add-Type -TypeDefinition "public class WeirdEmployee{public WeirdEmployee(){}private class PrivateNestedWeirdEmployee{public PrivateNestedWeirdEmployee(){}}}" - $e = {New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | ShouldBeErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" $e.CategoryInfo | Should -Match "PSArgumentException" } From 3b49b8ef580669436bb128454455e00d31817bbc Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 12:53:56 -0700 Subject: [PATCH 11/21] [Feature] Tests corrections. --- .../PowerShellData.tests.ps1 | 2 +- .../Select-Object.Tests.ps1 | 2 +- .../Update-TypeData.Tests.ps1 | 8 ++++---- .../WebCmdlets.Tests.ps1 | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 index 11ccaaaf555..7b6530f6b9f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 @@ -29,7 +29,7 @@ Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" { It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" { $path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass $result = Import-PowerShellDataFile $path -ErrorAction Stop - $result.Hello | Should -Exactly "World" + $result.Hello | Should -BeExactly "World" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index a820278f0b4..ad029f8ee08 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -124,7 +124,7 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { } It "Select-Object with empty script block property should throw"{ - $e = { "bar" | select-object -Prop {} -EA Stop } | Should -Throw -ErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $e = { "bar" | select-object -Prop {} -EA Stop } | ShouldBeErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" $e.CategoryInfo | Should -Match "PSArgumentException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index a43d5c72989..af417016d32 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -58,10 +58,10 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid File Extension should throw Exception"{ $xmlContent="not really an xml file, but we will not use it" $xmlContent>$invalidFileExtensionFile - $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") - $ps.Invoke() - $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Throw -ErrorId "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $null = $ps.AddScript("Update-TypeData -PrependPath $invalidFileExtensionFile") + $ps.Invoke() + $ps.HadErrors | Should -BeTrue + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "WrongExtension,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Dynamic Type NoteProperty with Force should work"{ diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 8677b3393b1..f8c579877f6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -691,7 +691,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.| Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns empty RelationLink property if there is no Link Header" { @@ -840,7 +840,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers $response.Error | Should -Not -BeNullOrEmpty - $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -869,7 +869,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -1172,7 +1172,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" { @@ -1918,7 +1918,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" { @@ -2039,7 +2039,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -2068,7 +2068,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.| Should -Throw -ErrorId "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -2165,7 +2165,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" { From c7ffd59f464e82459b0b2b708f300f4e79cfa4aa Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 12:56:48 -0700 Subject: [PATCH 12/21] [Feature] From ad3f199bc0590aba54ab5ed08d694a043d6333eb Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 16:36:35 -0700 Subject: [PATCH 13/21] [Feature} Tests correction. --- .../Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 | 2 +- .../Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 | 2 +- .../Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 | 4 ++-- .../Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 | 7 +------ .../Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 | 8 ++++---- .../Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 | 4 ++-- .../Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 | 2 +- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index b2cf2aecb5a..5a5d69abbde 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -50,7 +50,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Set-Variable foo bar -Option Private &{ $e = { Get-Variable -Name foo -Scope local -EA Stop } | - Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + ShouldBeErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" $e.CategoryInfo | Should -Match "ItemNotFoundException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 9189e322e48..be09d60be7b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Format-Table" -Tags "CI" { Describe "Format-Table DRT Unit Tests" -Tags "CI" { It "Format-Table with not existing table with force should throw PipelineStoppedException"{ $obj = New-Object -typename PSObject - $e = { $obj | Format-Table -view bar -force -EA Stop } | Should -Throw -ErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $e = { $obj | Format-Table -view bar -force -EA Stop } | ShouldBeErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" $e.CategoryInfo | Should -Match "PipelineStoppedException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 index 973c52adb51..54818d132e3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Error.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Write-Error Tests" -Tags "CI" { $e.ErrorDetails | Should -BeNullOrEmpty #FullyQualifiedErrorId verification - $e.| Should -Throw -ErrorId 'Microsoft.PowerShell.Commands.WriteErrorException' + $e.FullyQualifiedErrorId | Should -BeExactly 'Microsoft.PowerShell.Commands.WriteErrorException' #InvocationInfo verification $e.InvocationInfo | Should -Not -BeNullOrEmpty @@ -47,7 +47,7 @@ Describe "Write-Error Tests" -Tags "CI" { $e.TargetObject | Should -Be 'TargetObject' #FullyQualifiedErrorId verification - $e.| Should -Throw -ErrorId 'myerrorid' + $e.FullyQualifiedErrorId | Should -BeExactly 'myerrorid' #ErrorCategoryInfo verification $e.CategoryInfo | Should -Not -BeNullOrEmpty diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 index 38ed23424da..7f6ab4666f9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 @@ -38,12 +38,7 @@ Describe "Write-Host with wrong colors" -Tags "CI" { It 'Should throw if color is invalid: ForegroundColor = ; BackgroundColor = ' -TestCases:$testWrongColor { param($ForegroundColor, $BackgroundColor) - try - { - Write-Host "No output from Write-Host" -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor - throw "No Exception!" - } - catch { $_.| Should -Throw -ErrorId 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } + { Write-Host "No output from Write-Host" -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor } | Should -Throw -ErrorId 'CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WriteHostCommand' } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 index 12cd3ed05a6..e4a236e2458 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Progress.Tests.ps1 @@ -6,13 +6,13 @@ Describe "Write-Progress DRT Unit Tests" -Tags "CI" { } It "Should be able to throw exception when running Write-Progress with bad percentage" { - { write-progress -activity 'myactivity' -status 'mystatus' -percent 101 } - | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + { write-progress -activity 'myactivity' -status 'mystatus' -percent 101 } | + Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } It "Should be able to throw exception when running Write-Progress with bad parent id " { - { write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentid -2 } - | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' + { write-progress -activity 'myactivity' -status 'mystatus' -id 1 -parentid -2 } | + Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand' } It "all mandatory params works" -Pending { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 index 6209170408d..602be5a791e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/alias.tests.ps1 @@ -3,7 +3,7 @@ Describe "Alias tests" -Tags "CI" { BeforeAll { - $testPath = Join-Path testdrive:\ ("testAlias\[.test") + $testPath = Join-Path testdrive:\ ("testAlias\.test") New-Item -ItemType Directory -Path $testPath -Force | Out-Null class TestData @@ -50,7 +50,7 @@ Describe "Alias tests" -Tags "CI" { if($null -eq $test.expectedError) { - $test.testFile | Should -Exist + Test-Path -LiteralPath $test.testFile | Should -BeTrue } else { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 index 1ba464b4533..d6b12600a4e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/clixml.tests.ps1 @@ -57,7 +57,7 @@ Describe "CliXml test" -Tags "CI" { It "$($_.testName)" { $test = $_ - { Export-Clixml -Depth 1 -LiteralPath $test.testFile -InputObject $test.inputObject -Force } | Should -Throw - ErrorId $test.expectedError + { Export-Clixml -Depth 1 -LiteralPath $test.testFile -InputObject $test.inputObject -Force } | Should -Throw -ErrorId $test.expectedError } } From 27451163b93dd69fba9fee265a7a6f6e69c9e9a5 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 13 Mar 2018 17:04:54 -0700 Subject: [PATCH 14/21] [Feature] --- .../Remove-Variable.Tests.ps1 | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index 71c274313be..e58dbaee6b5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -194,14 +194,30 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException"{ New-Variable foo bar -Option Constant - $e = { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + try + { + Remove-Variable foo -EA Stop + Throw "Execution OK" + } + catch + { + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + } } It "Remove-Variable ReadOnly variable should throw SessionStateUnauthorizedAccessException and force remove should work"{ New-Variable foo bar -Option ReadOnly - { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + try + { + Remove-Variable foo -EA Stop + Throw "Execution OK" + } + catch + { + $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + } Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue $var1 | Should -BeNullOrEmpty @@ -209,12 +225,27 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException and force remove should also throw exception"{ New-Variable foo bar -Option Constant - $e = { Remove-Variable foo -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - - $e = { Remove-Variable foo -Force -EA Stop } | Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + try + { + Remove-Variable foo -EA Stop + Throw "Execution OK" + } + catch + { + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + } + try + { + Remove-Variable foo -Force -EA Stop + Throw "Execution OK" + } + catch + { + $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + } } It "Remove-Variable variable in new scope should works and Get-Variable with different scope should have different result"{ @@ -222,15 +253,22 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { &{ Clear-Variable foo Remove-Variable foo - $e = { Get-Variable -Name foo -Scope local -EA Stop } | Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - $e.CategoryInfo | Should -Match "ItemNotFoundException" + try{ + Get-Variable -Name foo -Scope local -EA Stop + Throw "Execution OK" + } + catch + { + $_.CategoryInfo | Should -Match "ItemNotFoundException" + $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + } } $var1 = Get-Variable -Name foo $var1.Name | Should -Be "foo" $var1.Value | Should -Be "bar" $var1.Options | Should -Be "None" - $var1.Description | Should -BeNullOrEmpty + $var1.Description | Should -Be "" } } From 7664a69e6a47d481e43f58d04aa9ed9b80ed4d47 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Fri, 16 Mar 2018 15:31:09 -0700 Subject: [PATCH 15/21] [Feature] Tests in Utility module fixes. --- .../Clear-Variable.Tests.ps1 | 4 +- .../New-Alias.Tests.ps1 | 26 ++++---- .../New-Variable.Tests.ps1 | 8 +-- .../Remove-Variable.Tests.ps1 | 59 ++++--------------- .../Set-Variable.Tests.ps1 | 4 +- 5 files changed, 31 insertions(+), 70 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index 5a5d69abbde..7d5dfab70aa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -14,7 +14,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { It "Clear-Variable ReadOnly variable Name should throw exception and force Clear-Variable should works"{ Set-Variable foo bar -Option ReadOnly - { Clear-Variable -Name foo -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + $e = { Clear-Variable -Name foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" Clear-Variable -Name foo -Force @@ -176,7 +176,7 @@ Describe "Clear-Variable" -Tags "CI" { It "Should throw error when trying to clear variable that is read-only without using the Force parameter" { New-Variable -Name var2 -Option ReadOnly -Value 100 - { Clear-Variable -Name var2 -ea stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" + { Clear-Variable -Name var2 -Scope 1 -ea stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.ClearVariableCommand" $var2 | Should -Not -BeNullOrEmpty diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 5ca10afca9d..39c5c260bc6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -3,8 +3,8 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{ New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true - $e = { New-Alias -Name "ABCD" -Value "foo" -Force:$true -ErrorAction Stop } | - Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + $e = { New-Alias -Name "ABCD" -Value "foo" -Force:$true -Scope 1 -ErrorAction Stop } | + ShouldBeErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } @@ -38,8 +38,8 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { Describe "New-Alias" -Tags "CI" { It "Should be able to be called using the name and value parameters without error" { - { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw - } + { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw + } It "Should have the same output between the alias and the original cmdlet" { New-Alias -Name testAlias -Value Get-Command @@ -53,20 +53,20 @@ Describe "New-Alias" -Tags "CI" { } It "Should be able to call the New-Alias cmdlet using the nal alias without error" { - { nal -Name testAlias -Value 100 } | Should -Not -Throw + { nal -Name testAlias -Value 100 } | Should -Not -Throw } It "Should have the same output between the nal alias and the New-Alias cmdlet" { - nal -Name testAlias -Value Get-Command + nal -Name testAlias -Value Get-Command - New-Alias -Name testalias2 -Value Get-Command + New-Alias -Name testalias2 -Value Get-Command - $aliasData = $(testAlias).Id - $cmdletData = $(testAlias2).Id + $aliasData = $(testAlias).Id + $cmdletData = $(testAlias2).Id - foreach ($IdNumber in $aliasData) - { - $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber] - } + foreach ($IdNumber in $aliasData) + { + $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber] + } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 918da2fd13e..9b4e5d8354e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -23,9 +23,9 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable variable twice should throw Exception"{ New-Variable foo bogus - { New-Variable foo bar -EA Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e = { New-Variable foo bar -Scope 1 -EA Stop } | ShouldBeErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" $e.CategoryInfo | Should -Match "SessionStateException" - + New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo $var1.Name|Should -Be "foo" @@ -37,7 +37,7 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable ReadOnly variable twice should throw Exception"{ New-Variable foo bogus -option ReadOnly - { New-Variable foo bar -EA Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e = { New-Variable foo bar -Scope 1 -EA Stop } | ShouldBeErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" $e.CategoryInfo | Should -Match "SessionStateException" New-Variable foo bar -Force -PassThru @@ -78,7 +78,7 @@ Describe "New-Variable" -Tags "CI" { It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" { New-Variable var1 - { New-Variable var1 -ErrorAction Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + { New-Variable var1 -Scope 1 -ErrorAction Stop } | Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" } It "Should change the value of an already existing variable using the Force switch" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index e58dbaee6b5..ab1a46b2807 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -194,30 +194,14 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException"{ New-Variable foo bar -Option Constant - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } It "Remove-Variable ReadOnly variable should throw SessionStateUnauthorizedAccessException and force remove should work"{ New-Variable foo bar -Option ReadOnly - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo| Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue $var1 | Should -BeNullOrEmpty @@ -225,27 +209,11 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException and force remove should also throw exception"{ New-Variable foo bar -Option Constant - try - { - Remove-Variable foo -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - try - { - Remove-Variable foo -Force -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" - } + { Remove-Variable foo -Force -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } It "Remove-Variable variable in new scope should works and Get-Variable with different scope should have different result"{ @@ -253,15 +221,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { &{ Clear-Variable foo Remove-Variable foo - try{ - Get-Variable -Name foo -Scope local -EA Stop - Throw "Execution OK" - } - catch - { - $_.CategoryInfo | Should -Match "ItemNotFoundException" - $_.FullyQualifiedErrorId | Should -Be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" - } + $e = { Get-Variable -Name foo -Scope local -EA Stop } | ShouldBeErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $e.CategoryInfo | Should -Match "ItemNotFoundException" } $var1 = Get-Variable -Name foo diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 544d377a260..6977081d0e3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -91,7 +91,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable overwrite Constant Option should throw SessionStateUnauthorizedAccessException"{ Set-Variable -Name abcaVar bar -Option Constant -Scope "local" - { Set-Variable -Name abcaVar new -Scope "local" -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + { Set-Variable -Name abcaVar new -Scope 1 -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } It "Set-Variable of existing Private variable without force should throw Exception"{ @@ -122,7 +122,7 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { $var1.Value|Should -Be "bar" $var1.Options|Should -Be "ReadOnly" $var1.Description|Should -Be "new description" - { Set-Variable abcaVar -Option None -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" + { Set-Variable abcaVar -Option None -Scope 1 -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } It "Set-Variable of ReadOnly variable with private scope should work"{ From 93107241724c2713e51dfd157ecae3a9fae27747 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Fri, 16 Mar 2018 16:09:19 -0700 Subject: [PATCH 16/21] [Feature] Tests fixes --- .../WebCmdlets.Tests.ps1 | 79 +++++++++++-------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index f8c579877f6..350cc1f07cd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # This is a Pester test suite which validate the Web cmdlets. @@ -383,18 +383,18 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { function ValidateResponse { param ($response) - $response.Error | Should -BeNullOrEmpty + $response.Error | Should -Be $null # A successful call returns: Status = 200, and StatusDescription = "OK" $response.Output.StatusDescription | Should -Match "OK" $response.Output.StatusCode | Should -Be 200 # Make sure the response contains the following properties: - $response.Output.RawContent | Should -Not -BeNullOrEmpty - $response.Output.Headers | Should -Not -BeNullOrEmpty - $response.Output.RawContent | Should -Not -BeNullOrEmpty - $response.Output.RawContentLength | Should -Not -BeNullOrEmpty - $response.Output.Content | Should -Not -BeNullOrEmpty + $response.Output.RawContent | Should -Not -Be $null + $response.Output.Headers | Should -Not -Be $null + $response.Output.RawContent | Should -Not -Be $null + $response.Output.RawContentLength | Should -Not -Be $null + $response.Output.Content | Should -Not -Be $null } #User-Agent changes on different platforms, so tests should only be run if on the correct platform @@ -473,7 +473,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3' $command = "Invoke-WebRequest -Uri '$uri' -MaximumRedirection 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Invoke-WebRequest supports request that returns page containing UTF-8 data." { @@ -491,14 +492,16 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } $testCase = @( @@ -512,7 +515,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -Proxy '${proxy_address}' -SkipCertificateCheck" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest error with environment proxy set - ''" -TestCases $testCase { @@ -524,7 +528,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns User-Agent where -NoProxy with envirionment proxy set - ''" -TestCases $testCase { @@ -691,7 +696,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Validate Invoke-WebRequest returns empty RelationLink property if there is no Link Header" { @@ -840,7 +845,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -869,7 +874,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -1156,7 +1161,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # validate that exception is thrown for URI with expired certificate $Uri = Get-WebListenerUrl -Https $command = "Invoke-WebRequest -Uri '$Uri'" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $Uri = Get-WebListenerUrl -Https @@ -1172,7 +1178,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" { @@ -1711,7 +1717,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3' $command = "Invoke-RestMethod -Uri '$uri' -MaximumRedirection 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Invoke-RestMethod supports request that returns page containing UTF-8 data." { @@ -1726,14 +1733,16 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } $testCase = @( @@ -1748,7 +1757,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = 'http://httpbin.org' $command = "Invoke-RestMethod -Uri '$uri' -Proxy '${proxy_address}'" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod error with environment proxy set - ''" -TestCases $testCase { @@ -1760,7 +1770,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https') $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2 -SkipCertificateCheck" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod returns User-Agent with option -NoProxy when environment proxy set - ''" -TestCases $testCase { @@ -1918,7 +1929,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Error.Exception.Response.StatusCode | Should -Be 418 $result.Error.Exception.Response.ReasonPhrase | Should -Be $query.responsephrase $result.Error.Exception.Message | Should -Match ": 418 \($($query.responsephrase)\)\." - $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" { @@ -2039,7 +2050,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value '12345' is invalid." } @@ -2068,7 +2079,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod" $response.Error | Should -Not -BeNullOrEmpty - $response.Error.FullyQualifiedErrorId | Should -BeExactly "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $response.Error.FullyQualifiedErrorId | Should -Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" $response.Error.Exception.Message | Should -Be "The format of value 'Invalid:Agent' is invalid." } @@ -2150,7 +2161,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # validate that exception is thrown for URI with expired certificate $uri = Get-WebListenerUrl -Https $command = "Invoke-RestMethod -Uri '$uri' -Method HEAD" - { ExecuteWebCommand -command $command } | Should -Throw -ErrorId "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result = ExecuteWebCommand -command $command + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" # validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option $command = "Invoke-RestMethod -Uri '$uri' -SkipCertificateCheck -Method HEAD" @@ -2165,7 +2177,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { # need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same $result.Error.ErrorDetails.Message | Should -Match $result.Error.Exception.InnerException.Message - $result.Error.FullyQualifiedErrorId | Should -BeExactly "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + $result.Error.FullyQualifiedErrorId | Should -Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" { @@ -2751,7 +2763,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { body = 'null' } $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty + Invoke-RestMethod -Uri $uri | Should -Be $null } It "Invoke-RestMethod Supports a Single Value JSON null and ignores whitespace" { @@ -2760,10 +2772,10 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { body = " null " } $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty + Invoke-RestMethod -Uri $uri | Should -Be $null $query['body'] = " null `n" $uri = Get-WebListenerUrl -Test 'Response' -Query $query - Invoke-RestMethod -Uri $uri | Should -BeNullOrEmpty + Invoke-RestMethod -Uri $uri | Should -Be $null } } @@ -2844,7 +2856,12 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu It "" -TestCases $testCases { param ($scriptblock, $expectedFullyQualifiedErrorId) - { & $scriptblock } | Should -Throw -ErrorId $ExpectedFullyQualifiedErrorId + try { + & $scriptblock + throw "No Exception!" + } catch { + $_.FullyQualifiedErrorId | Should -Be $ExpectedFullyQualifiedErrorId + } } } From 9b418832c9f62d888fe5fd0632095a84720130c2 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Mon, 19 Mar 2018 11:31:07 -0700 Subject: [PATCH 17/21] [Feature] Tests correction in Utility: -Be => -BeExactly for strings --- .../Add-Member.Tests.ps1 | 14 +- .../Add-Type.Tests.ps1 | 6 +- .../Clear-Variable.Tests.ps1 | 40 ++-- .../Compare-Object.Tests.ps1 | 56 +++--- .../ConvertFrom-Csv.Tests.ps1 | 12 +- .../ConvertFrom-StringData.Tests.ps1 | 8 +- .../ConvertTo-Csv.Tests.ps1 | 24 +-- .../ConvertTo-Xml.Tests.ps1 | 2 +- .../Export-Csv.Tests.ps1 | 12 +- .../Export-FormatData.Tests.ps1 | 2 +- .../Get-Alias.Tests.ps1 | 114 +++++------ .../Get-Event.Tests.ps1 | 2 +- .../Get-EventSubscriber.Tests.ps1 | 2 +- .../Get-Host.Tests.ps1 | 2 +- .../Get-Member.Tests.ps1 | 10 +- .../Get-PSCallStack.Tests.ps1 | 4 +- .../Get-Unique.Tests.ps1 | 8 +- .../Get-Variable.Tests.ps1 | 26 +-- .../Implicit.Remoting.Tests.ps1 | 184 +++++++++--------- .../Import-Alias.Tests.ps1 | 4 +- .../Import-Csv.Tests.ps1 | 6 +- .../Import-LocalizedData.Tests.ps1 | 2 +- .../Invoke-Expression.Tests.ps1 | 4 +- .../New-Alias.Tests.ps1 | 20 +- .../New-Event.Tests.ps1 | 2 +- .../New-Object.Tests.ps1 | 6 +- .../New-Variable.Tests.ps1 | 36 ++-- .../NewGuid.Tests.ps1 | 2 +- .../NewTemporaryFile.Tests.ps1 | 2 +- .../Out-File.Tests.ps1 | 6 +- .../Out-String.Tests.ps1 | 6 +- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 36 ++-- .../Register-ObjectEvent.Tests.ps1 | 2 +- .../Remove-TypeData.Tests.ps1 | 2 +- .../Remove-Variable.Tests.ps1 | 26 +-- .../Select-Object.Tests.ps1 | 6 +- .../Select-XML.Tests.ps1 | 4 +- .../Set-Alias.Tests.ps1 | 50 ++--- .../Set-PSBreakpoint.Tests.ps1 | 8 +- .../Set-Variable.Tests.ps1 | 104 +++++----- .../Sort-Object.Tests.ps1 | 14 +- .../Tee-Object.Tests.ps1 | 4 +- .../Update-TypeData.Tests.ps1 | 66 +++---- .../Write-Stream.Tests.ps1 | 8 +- .../Write-Verbose.Tests.ps1 | 4 +- 45 files changed, 479 insertions(+), 479 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 index 3c81fa00cbf..4a25597eb10 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 @@ -114,7 +114,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { $al | Add-Member -MemberType ScriptProperty -Name NewDescription -Value {$this.Description} -SecondValue {$this.Description=$args[0]} $al.NewDescription | Should -BeExactly 'MyDescription' $al.NewDescription = "some description" - $al.NewDescription | Should -Be 'some description' + $al.NewDescription | Should -BeExactly 'some description' } It "Add TypeName MemberSet Success" { @@ -159,16 +159,16 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { It "Simplified Add-Member should support using 'Property' as the NoteProperty member name" { $results = add-member -InputObject a property Any -passthru - $results.property | Should -Be 'Any' + $results.property | Should -BeExactly 'Any' $results = add-member -InputObject a Method Any -passthru - $results.Method | Should -Be 'Any' + $results.Method | Should -BeExactly 'Any' $results = add-member -InputObject a 23 Any -passthru - $results.23 | Should -Be 'Any' + $results.23 | Should -BeExactly 'Any' $results = add-member -InputObject a 8 np Any -passthru - $results.np | Should -Be 'Any' + $results.np | Should -BeExactly 'Any' $results = add-member -InputObject a 16 sp {1+1} -passthru $results.sp | Should -Be 2 @@ -190,7 +190,7 @@ Describe "Add-Member" -Tags "CI" { Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal" $o.proppy | Should -Not -BeNullOrEmpty - $o.proppy | Should -Be "superVal" + $o.proppy | Should -BeExactly "superVal" } It "Should be able to add a member to an object that already has a member in it" { @@ -199,6 +199,6 @@ Describe "Add-Member" -Tags "CI" { Add-Member -InputObject $o -MemberType NoteProperty -Name AnotherMember -Value "AnotherValue" $o.AnotherMember | Should -Not -BeNullOrEmpty - $o.AnotherMember | Should -Be "AnotherValue" + $o.AnotherMember | Should -BeExactly "AnotherValue" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 index 853a1227a13..ce069161860 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Type.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Add-Type" -Tags "CI" { } It "Public 'Language' enumeration contains all members" { - [Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should -Be "CSharp,VisualBasic" + [Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should -BeExactly "CSharp,VisualBasic" } It "Should not throw given a simple class definition" { @@ -57,8 +57,8 @@ public class AttributeTest$guid {} It "Can compile C# files" { - { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Throw - { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should -Throw + { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Throw -ErrorId "TypeNotFound" + { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should -Throw -ErrorId "TypeNotFound" Add-Type -Path $codeFile1,$codeFile2 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 index 7d5dfab70aa..3099e88b6ea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Clear-Variable.Tests.ps1 @@ -5,9 +5,9 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Set-Variable foo bar Clear-Variable -Name foo $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" + $var1.Name|Should -BeExactly "foo" $var1.Value|Should -BeNullOrEmpty - $var1.Options|Should -Be "None" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } @@ -19,9 +19,9 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo -Force $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" + $var1.Name|Should -BeExactly "foo" $var1.Value|Should -BeNullOrEmpty - $var1.Options|Should -Be "ReadOnly" + $var1.Options|Should -BeExactly "ReadOnly" $var1.Description| Should -BeNullOrEmpty } @@ -33,16 +33,16 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should -Be "foo" + $var1.Name|Should -BeExactly "foo" $var1.Value|Should -BeNullOrEmpty - $var1.Options|Should -Be "None" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } @@ -55,9 +55,9 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { } $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "Private" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "Private" $var1.Description|Should -BeNullOrEmpty } @@ -68,22 +68,22 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { Clear-Variable -Name foo -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should -Be "foo" + $var1.Name|Should -BeExactly "foo" $var1.Value|Should -BeNullOrEmpty - $var1.Options|Should -Be "None" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index 40e13634cf5..8f773de56db 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -35,21 +35,21 @@ Describe "Compare-Object" -Tags "CI" { It "Should indicate data that exists only in the reference dataset" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) - $actualOutput[1].SideIndicator | Should -Be "<=" + $actualOutput[1].SideIndicator | Should -BeExactly "<=" } It "Should indicate data that exists only in the difference dataset" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) - $actualOutput[1].SideIndicator | Should -Be "<=" + $actualOutput[1].SideIndicator | Should -BeExactly "<=" } It "Should indicate data that exists in both datasets when the includeEqual switch is used" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual $actualOutput.Length | Should -Be 4 - $actualOutput[0].SideIndicator | Should -Be "==" - $actualOutput[1].SideIndicator | Should -Be "==" + $actualOutput[0].SideIndicator | Should -BeExactly "==" + $actualOutput[1].SideIndicator | Should -BeExactly "==" } It "Should be able to use the casesensitive switch" { @@ -115,10 +115,10 @@ Describe "Compare-Object" -Tags "CI" { $actualOutput[2].InputObject | Should -Be 1 $actualOutput[3].InputObject | Should -Be 15 - $actualOutput[0].SideIndicator | Should -Be "=>" - $actualOutput[1].SideIndicator | Should -Be "<=" - $actualOutput[2].SideIndicator | Should -Be "=>" - $actualOutput[3].SideIndicator | Should -Be "<=" + $actualOutput[0].SideIndicator | Should -BeExactly "=>" + $actualOutput[1].SideIndicator | Should -BeExactly "<=" + $actualOutput[2].SideIndicator | Should -BeExactly "=>" + $actualOutput[3].SideIndicator | Should -BeExactly "<=" } } @@ -240,8 +240,8 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { $result[0].InputObject | Should -Be $empsDifference $result[1].InputObject | Should -Be $empsReference - $result[0].SideIndicator | Should -Be "=>" - $result[1].SideIndicator | Should -Be "<=" + $result[0].SideIndicator | Should -BeExactly "=>" + $result[1].SideIndicator | Should -BeExactly "<=" } } else @@ -278,8 +278,8 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { $result[0].InputObject | Should -Be $empsReference[0] $result[1].InputObject | Should -Be $empsReference[1] - $result[0].SideIndicator | Should -Be "==" - $result[1].SideIndicator | Should -Be "<=" + $result[0].SideIndicator | Should -BeExactly "==" + $result[1].SideIndicator | Should -BeExactly "<=" } } else @@ -291,7 +291,7 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { else { $result.InputObject | Should -Be $empsReference[0] - $result.SideIndicator | Should -Be "==" + $result.SideIndicator | Should -BeExactly "==" } } } @@ -306,7 +306,7 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { else { $result.InputObject | Should -Be $empsReference[1] - $result.SideIndicator | Should -Be "<=" + $result.SideIndicator | Should -BeExactly "<=" } } else @@ -344,8 +344,8 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { { $result[0].InputObject | Should -Be $empsReference $result[1].InputObject | Should -Be $empsDifference[1] - $result[0].SideIndicator | Should -Be "==" - $result[1].SideIndicator | Should -Be "=>" + $result[0].SideIndicator | Should -BeExactly "==" + $result[1].SideIndicator | Should -BeExactly "=>" } } else @@ -357,7 +357,7 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { else { $result.InputObject | Should -Be $empsReference - $result.SideIndicator | Should -Be "==" + $result.SideIndicator | Should -BeExactly "==" } } } @@ -372,7 +372,7 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { else { $result.InputObject | Should -Be $empsDifference[1] - $result.SideIndicator | Should -Be "=>" + $result.SideIndicator | Should -BeExactly "=>" } } else @@ -410,13 +410,13 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { else { $result[0].InputObject | Should -Be $empsReference[0] - $result[0].SideIndicator | Should -Be "==" + $result[0].SideIndicator | Should -BeExactly "==" $result[1].InputObject | Should -Be $empsReference[2] - $result[1].SideIndicator | Should -Be "==" + $result[1].SideIndicator | Should -BeExactly "==" $result[2].InputObject | Should -Be $empsReference[1] - $result[2].SideIndicator | Should -Be "==" + $result[2].SideIndicator | Should -BeExactly "==" $result[3].InputObject | Should -Be $empsReference[3] - $result[3].SideIndicator | Should -Be "==" + $result[3].SideIndicator | Should -BeExactly "==" } } else @@ -434,10 +434,10 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { $result = Compare-Object $a $b -IncludeEqual -Property {$_.Major},{$_.Minor} $result[0] | Select-Object -ExpandProperty "*Major" | Should -Be 5 $result[0] | Select-Object -ExpandProperty "*Minor" | Should -Be 6 - $result[0].SideIndicator | Should -Be "=>" + $result[0].SideIndicator | Should -BeExactly "=>" $result[1] | Select-Object -ExpandProperty "*Major" | Should -Be 1 $result[1] | Select-Object -ExpandProperty "*Minor" | Should -Be 2 - $result[1].SideIndicator | Should -Be "<=" + $result[1].SideIndicator | Should -BeExactly "<=" } It "Compare-Object with no ReferenceObject nor DifferenceObject: output nothing, no error and should work"{ @@ -447,13 +447,13 @@ Describe "Compare-Object DRT basic functionality" -Tags "CI" { It "Compare-Object with no DifferenceObject should work"{ $result = Compare-Object @() @("diffObject") - $result.InputObject | Should -Be "diffObject" - $result.SideIndicator | Should -Be "=>" + $result.InputObject | Should -BeExactly "diffObject" + $result.SideIndicator | Should -BeExactly "=>" } It "Compare-Object with no ReferenceObject should work"{ $result = Compare-Object @("refObject") @() - $result.InputObject | Should -Be "refObject" - $result.SideIndicator | Should -Be "<=" + $result.InputObject | Should -BeExactly "refObject" + $result.SideIndicator | Should -BeExactly "<=" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 index 1f4cc660b9a..693c9e025c0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Csv.Tests.ps1 @@ -64,8 +64,8 @@ a,b,c It "Should Contain the Imported Type data" { $actualData = $testTypeData | ConvertFrom-Csv $actualData.PSObject.TypeNames.Count | Should -Be 2 - $actualData.PSObject.TypeNames[0] | Should -Be "My.Custom.Object" - $actualData.PSObject.TypeNames[1] | Should -Be "CSV:My.Custom.Object" + $actualData.PSObject.TypeNames[0] | Should -BeExactly "My.Custom.Object" + $actualData.PSObject.TypeNames[1] | Should -BeExactly "CSV:My.Custom.Object" } } @@ -75,9 +75,9 @@ Describe "ConvertFrom-Csv DRT Unit Tests" -Tags "CI" { $res = $inputObject | ConvertTo-Csv $result = $res | ConvertFrom-Csv -Header "Header1","Header2" - $result[0].Header1 | Should -Be "First" - $result[0].Header2 | Should -Be "Second" - $result[1].Header1 | Should -Be "1" - $result[1].Header2 | Should -Be "2" + $result[0].Header1 | Should -BeExactly "First" + $result[0].Header2 | Should -BeExactly "Second" + $result[1].Header1 | Should -BeExactly "1" + $result[1].Header2 | Should -BeExactly "2" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index edf0ed371da..6cfb3f71d53 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -39,21 +39,21 @@ bazz = 2 It "Should return the data on the left side in the key" { $actualValue = ConvertFrom-StringData -StringData 'a=b' - $actualValue.Keys | Should -Be "a" + $actualValue.Keys | Should -BeExactly "a" } It "Should return the data on the right side in the value" { $actualValue = ConvertFrom-StringData -StringData 'a=b' - $actualValue.Values | Should -Be "b" + $actualValue.Values | Should -BeExactly "b" } It "Should return a keycollection for the keys" { - $(ConvertFrom-StringData -StringData 'a=b').Keys.PSObject.TypeNames[0] | Should -Be "System.Collections.Hashtable+KeyCollection" + $(ConvertFrom-StringData -StringData 'a=b').Keys.PSObject.TypeNames[0] | Should -BeExactly "System.Collections.Hashtable+KeyCollection" } It "Should return a valuecollection for the values" { - $(ConvertFrom-StringData -StringData 'a=b').Values.PSObject.TypeNames[0] | Should -Be "System.Collections.Hashtable+ValueCollection" + $(ConvertFrom-StringData -StringData 'a=b').Values.PSObject.TypeNames[0] | Should -BeExactly "System.Collections.Hashtable+ValueCollection" } It "Should work for multiple lines" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 index e76c3a12c25..c98d082a10d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 @@ -6,34 +6,34 @@ Describe "ConvertTo-Csv DRT Unit Tests" -Tags "CI" { It "Test convertto-csv with psobject pipelined" { $returnObject = $inputObject | ConvertTo-Csv -IncludeTypeInformation $returnObject.Count | Should -Be 3 - $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should -Be "`"First`",`"Second`"" - $returnObject[2] | Should -Be "`"1`",`"2`"" + $returnObject[0] | Should -BeExactly "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -BeExactly "`"First`",`"Second`"" + $returnObject[2] | Should -BeExactly "`"1`",`"2`"" } It "Test convertto-csv with NoTypeInformation and psobject pipelined" { $returnObject = $inputObject | ConvertTo-Csv -NoTypeInformation $returnObject.Count | Should -Be 2 - $returnObject[0] | Should -Be "`"First`",`"Second`"" - $returnObject[1] | Should -Be "`"1`",`"2`"" + $returnObject[0] | Should -BeExactly "`"First`",`"Second`"" + $returnObject[1] | Should -BeExactly "`"1`",`"2`"" } It "Test convertto-csv with a useculture flag" { #The default value is ',' $returnObject = $inputObject | ConvertTo-Csv -UseCulture -IncludeTypeInformation $returnObject.Count | Should -Be 3 - $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should -Be "`"First`",`"Second`"" - $returnObject[2] | Should -Be "`"1`",`"2`"" + $returnObject[0] | Should -BeExactly "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -BeExactly "`"First`",`"Second`"" + $returnObject[2] | Should -BeExactly "`"1`",`"2`"" } It "Test convertto-csv with Delimiter" { #The default value is ',' $returnObject = $inputObject | ConvertTo-Csv -Delimiter ";" -IncludeTypeInformation $returnObject.Count | Should -Be 3 - $returnObject[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" - $returnObject[1] | Should -Be "`"First`";`"Second`"" - $returnObject[2] | Should -Be "`"1`";`"2`"" + $returnObject[0] | Should -BeExactly "#TYPE System.Management.Automation.PSCustomObject" + $returnObject[1] | Should -BeExactly "`"First`";`"Second`"" + $returnObject[2] | Should -BeExactly "`"1`";`"2`"" } } @@ -53,7 +53,7 @@ Describe "ConvertTo-Csv" -Tags "CI" { It "Should return the type of data in the first element of the output array" { $result = $testObject | ConvertTo-Csv -IncludeTypeInformation - $result[0] | Should -Be "#TYPE System.Management.Automation.PSCustomObject" + $result[0] | Should -BeExactly "#TYPE System.Management.Automation.PSCustomObject" } It "Should return the column info in the second element of the output array" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 index 73052388f7a..848167703ab 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -65,7 +65,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $ps.AddParameter("Depth", 2) $ps.BeginInvoke() $ps.Stop() - $ps.InvocationStateInfo.State | Should -Be "Stopped" + $ps.InvocationStateInfo.State | Should -BeExactly "Stopped" } # these tests just cover aspects that aren't normally exercised being used as a cmdlet diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 index bae559440bf..6dc8c328dfc 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 @@ -83,9 +83,9 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input = [pscustomobject]@{ "P1" = "V11"; "P2" = "V12"; "P3" = "V13" } $input | Export-Csv -Path $filePath -NoTypeInformation $results = Import-Csv $filePath - $results.P1 | Should -Be "V11" - $results.P2 | Should -Be "V12" - $results.P3 | Should -Be "V13" + $results.P1 | Should -BeExactly "V11" + $results.P2 | Should -BeExactly "V12" + $results.P3 | Should -BeExactly "V13" } It "Test if it works with special character" { @@ -93,8 +93,8 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input = [pscustomobject]@{ "P1" = " "; "P2" = "abc,foo"; "P3" = $v3} $input | Export-Csv -Path $filePath -NoTypeInformation $results = Import-Csv $filePath - $results.P1 | Should -Be " " - $results.P2 | Should -Be "abc,foo" + $results.P1 | Should -BeExactly " " + $results.P2 | Should -BeExactly "abc,foo" $results.P3 | Should -Be $v3 } @@ -106,7 +106,7 @@ Describe "Export-Csv DRT Unit Tests" -Tags "CI" { $input | Export-Csv -Path $filePath -Force $results = Import-Csv $filePath - $results.P2 | Should -Be "second" + $results.P2 | Should -BeExactly "second" $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } $property | Should -Not -Be P1 } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index 394b65972c9..2920a21f4c8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Export-FormatData" -Tags "CI" { It "Should have a valid xml tag at the start of the file" { Get-FormatData | Export-FormatData -Path $testOutput $piped = Get-Content $testOutput - $piped[0] | Should -Be "<" + $piped[0] | Should -BeExactly "<" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 5bc449cba9f..c3b472622e2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -11,81 +11,81 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { It "Get-Alias Named Single Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Get-Alias Positional Single Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Get-Alias Named Multiple Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name AEFG -Value "bar" $result=Get-Alias -Name ABCD,AEFG - $result[0].Name| Should -Be "ABCD" - $result[0].Definition| Should -Be "foo" + $result[0].Name| Should -BeExactly "ABCD" + $result[0].Definition| Should -BeExactly "foo" $result[0].Description| Should -BeNullOrEmpty - $result[0].Options| Should -Be "None" - $result[1].Name| Should -Be "AEFG" - $result[1].Definition| Should -Be "bar" + $result[0].Options| Should -BeExactly "None" + $result[1].Name| Should -BeExactly "AEFG" + $result[1].Definition| Should -BeExactly "bar" $result[1].Description| Should -BeNullOrEmpty - $result[1].Options| Should -Be "None" + $result[1].Options| Should -BeExactly "None" } It "Get-Alias Named Wildcard Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias -Name ABC* - $result[0].Name| Should -Be "ABCD" - $result[0].Definition| Should -Be "foo" + $result[0].Name| Should -BeExactly "ABCD" + $result[0].Definition| Should -BeExactly "foo" $result[0].Description| Should -BeNullOrEmpty - $result[0].Options| Should -Be "None" - $result[1].Name| Should -Be "ABCG" - $result[1].Definition| Should -Be "bar" + $result[0].Options| Should -BeExactly "None" + $result[1].Name| Should -BeExactly "ABCG" + $result[1].Definition| Should -BeExactly "bar" $result[1].Description| Should -BeNullOrEmpty - $result[1].Options| Should -Be "None" + $result[1].Options| Should -BeExactly "None" } It "Get-Alias Positional Wildcard Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias ABC* - $result[0].Name| Should -Be "ABCD" - $result[0].Definition| Should -Be "foo" + $result[0].Name| Should -BeExactly "ABCD" + $result[0].Definition| Should -BeExactly "foo" $result[0].Description| Should -BeNullOrEmpty - $result[0].Options| Should -Be "None" - $result[1].Name| Should -Be "ABCG" - $result[1].Definition| Should -Be "bar" + $result[0].Options| Should -BeExactly "None" + $result[1].Name| Should -BeExactly "ABCG" + $result[1].Definition| Should -BeExactly "bar" $result[1].Description| Should -BeNullOrEmpty - $result[1].Options| Should -Be "None" + $result[1].Options| Should -BeExactly "None" } It "Get-Alias Named Wildcard And Exclude Valid"{ Set-Alias -Name ABCD -Value "foo" Set-Alias -Name ABCG -Value "bar" $result=Get-Alias -Name ABC* -Exclude "*BCG" - $result[0].Name| Should -Be "ABCD" - $result[0].Definition| Should -Be "foo" + $result[0].Name| Should -BeExactly "ABCD" + $result[0].Definition| Should -BeExactly "foo" $result[0].Description| Should -BeNullOrEmpty - $result[0].Options| Should -Be "None" + $result[0].Options| Should -BeExactly "None" } It "Get-Alias Scope Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" Set-Alias -Name ABCD -Value "localfoo" -scope local $result=Get-Alias -Name ABCD -scope local - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "localfoo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "localfoo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" Set-Alias -Name ABCD -Value "globalfoo" -scope global Set-Alias -Name ABCD -Value "scriptfoo" -scope "script" @@ -93,40 +93,40 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { Set-Alias -Name ABCD -Value "foo1" -scope "1" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo0" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo0" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope local - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo0" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo0" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope global - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "globalfoo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "globalfoo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope "script" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "scriptfoo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "scriptfoo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope "0" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo0" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo0" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope "1" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo1" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo1" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Get-Alias Expose Bug 1065828, BugId:905235"{ { Get-Alias -Name "ABCD" -Scope "100" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetAliasCommand" @@ -134,16 +134,16 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { It "Get-Alias Zero Scope Valid"{ Set-Alias -Name ABCD -Value "foo" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope "0" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Test get-alias with Definition parameter" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 index 16e819800b0..7f2fbfeb309 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Event.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-Event" -Tags "CI" { } It "Should return PesterTestMessage as the MessageData" { - { (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -Be "PesterTestMessage" } + { (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -BeExactly "PesterTestMessage" } } It "Should return Sender as Windows.timer" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 index 7c37f9f05b8..1ffeefe8659 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-EventSubscriber.Tests.ps1 @@ -19,7 +19,7 @@ Describe "Get-EventSubscriber" -Tags "CI" { It "Should return source identifier of PesterTimer " { $pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object]) Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -Be "PesterTestRegister" + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -BeExactly "PesterTestRegister" } It "Should return an integer greater than 0 for the SubscriptionId" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 index a54b2679f69..5a3928aae37 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Host.Tests.ps1 @@ -4,6 +4,6 @@ Describe "Get-Host DRT Unit Tests" -Tags "CI" { It "Should works proper with get-host" { $results = Get-Host $results | Should -Be $Host - $results.PSObject.TypeNames[0] | Should -Be "System.Management.Automation.Internal.Host.InternalHost" + $results.PSObject.TypeNames[0] | Should -BeExactly "System.Management.Automation.Internal.Host.InternalHost" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 index c95736e36bc..35d3e5c7f2e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Member.Tests.ps1 @@ -156,9 +156,9 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { $emps = [Employee]::New("john", "smith", 5), [Employee]::New("joesph", "smith", 15), [Employee]::New("john", "smyth", 2) $results = $emps | Get-Member -MemberType Property $results.Length | Should -Be 3 - $results[0].Name | Should -Be "FirstName" - $results[1].Name | Should -Be "LastName" - $results[2].Name | Should -Be "YearsInMS" + $results[0].Name | Should -BeExactly "FirstName" + $results[1].Name | Should -BeExactly "LastName" + $results[2].Name | Should -BeExactly "YearsInMS" } It 'Get the Public Methods of "Employee" object' { @@ -189,8 +189,8 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" { $emps = [Employee]::New("john", "smith", 5), [Employee]::New("joesph", "smith", 15), [Employee]::New("john", "smyth", 2) $results = $emps | Get-Member -MemberType PropertySet $results.Length | Should -Be 2 - $results[0].Name | Should -Be "FullSet" - $results[1].Name | Should -Be "PropertySetName" + $results[0].Name | Should -BeExactly "FullSet" + $results[1].Name | Should -BeExactly "PropertySetName" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 index 3a88280463d..be5aaca1b1e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-PSCallStack.Tests.ps1 @@ -45,12 +45,12 @@ Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" { $results = & "$scriptFilePath" $results.Count | Should -BeGreaterThan 3 - $results[0].Command | Should -Be "bar" + $results[0].Command | Should -BeExactly "bar" $results[0].ScriptName | Should -Be $scriptFilePath $results[0].ScriptLineNumber | Should -Be 27 $results[0].InvocationInfo.ScriptLineNumber | Should -Be 9 - $results[1].Command | Should -Be "foo" + $results[1].Command | Should -BeExactly "foo" $results[1].ScriptName | Should -Be $scriptFilePath $results[1].ScriptLineNumber | Should -Be 9 $results[1].InvocationInfo.ScriptLineNumber | Should -Be 32 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 index 535ec1a22e1..bb922a6fc5f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Unique.Tests.ps1 @@ -7,10 +7,10 @@ Describe "Get-Unique DRT Unit Tests" -Tags "CI" { $results.Length | Should -Be 4 - $results[0] | Should -Be "aa" - $results[1] | Should -Be "Aa" - $results[2] | Should -Be "ba" - $results[3] | Should -Be "BA" + $results[0] | Should -BeExactly "aa" + $results[1] | Should -BeExactly "Aa" + $results[2] | Should -BeExactly "ba" + $results[3] | Should -BeExactly "BA" $results[0] | Should -BeOfType "System.String" $results[1] | Should -BeOfType "System.String" diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 index 2c8802209a0..6dba5a18bea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Variable.Tests.ps1 @@ -10,17 +10,17 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { It "Get-Variable of existing variable Name with include and bogus exclude should work"{ Set-Variable newVar testing $var1=get-variable -Name newVar -Include newVar -Exclude bogus - $var1.Name|Should -Be "newVar" - $var1.Value|Should -Be "testing" + $var1.Name|Should -BeExactly "newVar" + $var1.Value|Should -BeExactly "testing" } It "Get-Variable of existing variable Name with Description and Option should work"{ Set-Variable newVar testing -Option ReadOnly -Description "testing description" $var1=get-variable -Name newVar - $var1.Name|Should -Be "newVar" - $var1.Value|Should -Be "testing" - $var1.Options|Should -Be "ReadOnly" - $var1.Description|Should -Be "testing description" + $var1.Name|Should -BeExactly "newVar" + $var1.Value|Should -BeExactly "testing" + $var1.Options|Should -BeExactly "ReadOnly" + $var1.Description|Should -BeExactly "testing description" } It "Get-Variable of existing variable Globbing Name should work"{ @@ -29,12 +29,12 @@ Describe "Get-Variable DRT Unit Tests" -Tags "CI" { Set-Variable aVarfoo wow $var1=get-variable -Name *aVar* -Scope local $var1.Count | Should -Be 3 - $var1[0].Name|Should -Be "abcaVar" - $var1[0].Value|Should -Be "testing" - $var1[1].Name|Should -Be "aVarfoo" - $var1[1].Value|Should -Be "wow" - $var1[2].Name|Should -Be "bcdaVar" - $var1[2].Value|Should -Be "another test" + $var1[0].Name|Should -BeExactly "abcaVar" + $var1[0].Value|Should -BeExactly "testing" + $var1[1].Name|Should -BeExactly "aVarfoo" + $var1[1].Value|Should -BeExactly "wow" + $var1[2].Name|Should -BeExactly "bcdaVar" + $var1[2].Value|Should -BeExactly "another test" } It "Get-Variable of existing private variable Name should throw ItemNotFoundException"{ @@ -78,7 +78,7 @@ Describe "Get-Variable" -Tags "CI" { New-Variable -Name var2 -Value "test" (Get-Variable -Name var*).Value[0] | Should -Be 4 - (Get-Variable -Name var*).Value[1] | Should -Be "test" + (Get-Variable -Name var*).Value[1] | Should -BeExactly "test" Remove-Variable var1 Remove-Variable var2 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index 66434d56382..d877c893283 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -149,7 +149,7 @@ try # The enum is treated as an int (foo -x "Value2") | Should -Be 2 # The enum is to-string-ed appropriately - (foo -x "Value2").ToString() | Should -Be "Value2" + (foo -x "Value2").ToString() | Should -BeExactly "Value2" } finally { if ($null -ne $module) { Remove-Module $module -Force -ErrorAction SilentlyContinue } } @@ -421,7 +421,7 @@ try } It "Verifies ApplicationArguments got preserved correctly" -Pending { - $(Invoke-Command $internalSession { $PSSenderInfo.ApplicationArguments.MyTest }) | Should -Be "MyValue" + $(Invoke-Command $internalSession { $PSSenderInfo.ApplicationArguments.MyTest }) | Should -BeExactly "MyValue" } It "Verifies Remove-Module removed the runspace that was automatically created" -Pending { @@ -430,7 +430,7 @@ try } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Closed" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -BeExactly "Closed" } } @@ -452,10 +452,10 @@ try # culture settings should be taken from the explicitly passed session options It "Verifies proxy returns modified culture" -Pending { - (Get-Variable -Name PSCulture).Value | Should -Be "fr-FR" + (Get-Variable -Name PSCulture).Value | Should -BeExactly "fr-FR" } It "Verifies proxy returns modified culture" -Pending { - (Get-Variable -Name PSUICulture).Value | Should -Be "de-DE" + (Get-Variable -Name PSUICulture).Value | Should -BeExactly "de-DE" } # removing the module should remove the implicitly/magically created runspace @@ -464,7 +464,7 @@ try (Get-PSSession -InstanceId $internalSession.InstanceId -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } It "Verifies Runspace is closed after removing module from Export-PSSession that got initialized with an internal r-space" -Pending { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Closed" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -BeExactly "Closed" } } @@ -491,12 +491,12 @@ try } It "Verifies Adding a module affects runspace's state" { - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Opened" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -BeExactly "Opened" } It "Verifies Runspace stays opened after removing module from Export-PSSession that got initialized with an external runspace" { Remove-Module $module -Force - ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -Be "Opened" + ($internalSession.Runspace.RunspaceStateInfo.ToString()) | Should -BeExactly "Opened" } } } @@ -720,17 +720,17 @@ try It "Serialization works for top-level properties" { $x = foo - $x.text | Should -Be "root" + $x.text | Should -BeExactly "root" } It "Serialization settings works for deep properties" { $x = foo - $x.Son.Grandson.text | Should -Be "Grandson" + $x.Son.Grandson.text | Should -BeExactly "Grandson" } It "Serialization settings are preserved even if types.ps1xml is missing on the client" { $y = foo | bar - $y | Should -Be "Grandson" + $y | Should -BeExactly "Grandson" } } } @@ -776,7 +776,7 @@ try } It "Calls implicit remoting proxies 'MyFunction'" { - (MyFunction 1 2 3) | Should -Be "x = '1'; args = '2 3'" + (MyFunction 1 2 3) | Should -BeExactly "x = '1'; args = '2 3'" } It "proxy should return remote pid" { @@ -793,7 +793,7 @@ try It "NoName-c8aeb5c8-2388-4d64-98c1-a9c6c218d404" { Invoke-Command -Session $session { $env:TestImplicitRemotingVariable = 123 } - (cmd.exe /c "echo TestImplicitRemotingVariable=%TestImplicitRemotingVariable%") | Should -Be "TestImplicitRemotingVariable=123" + (cmd.exe /c "echo TestImplicitRemotingVariable=%TestImplicitRemotingVariable%") | Should -BeExactly "TestImplicitRemotingVariable=123" } Context "Test what happens after the runspace is closed" { @@ -880,8 +880,8 @@ try } # Sanity checks. - Invoke-Command $session {"s" | foo} | Should -Be "Bound parameter: string" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" + Invoke-Command $session {"s" | foo} | Should -BeExactly "Bound parameter: string" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -BeExactly "Bound parameter: ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -892,11 +892,11 @@ try } It "Pipeline binding works even if it relies on type constraints" { - ("s" | foo) | Should -Be "Bound parameter: string" + ("s" | foo) | Should -BeExactly "Bound parameter: string" } It "Pipeline binding works even if it relies on type constraints" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -BeExactly "Bound parameter: ipaddress" } } @@ -921,8 +921,8 @@ try } # Sanity checks. - Invoke-Command $session {"s" | foo} | Should -Be "Bound parameter: string" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" + Invoke-Command $session {"s" | foo} | Should -BeExactly "Bound parameter: string" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -BeExactly "Bound parameter: ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -933,11 +933,11 @@ try } It "Pipeline binding works even if it relies on type constraints and parameter set is ambiguous" { - ("s" | foo) | Should -Be "Bound parameter: string" + ("s" | foo) | Should -BeExactly "Bound parameter: string" } It "Pipeline binding works even if it relies on type constraints and parameter set is ambiguous" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -BeExactly "Bound parameter: ipaddress" } } @@ -962,10 +962,10 @@ try } # Sanity checks. - Invoke-Command $session {Get-Date | foo} | Should -Be "Bound parameter: date" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -Be "Bound parameter: ipaddress" - Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo -date (get-date)} | Should -Be "Bound parameter: date ipaddress" - Invoke-Command $session {Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))} | Should -Be "Bound parameter: date ipaddress" + Invoke-Command $session {Get-Date | foo} | Should -BeExactly "Bound parameter: date" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo} | Should -BeExactly "Bound parameter: ipaddress" + Invoke-Command $session {[ipaddress]::parse("127.0.0.1") | foo -date (get-date)} | Should -BeExactly "Bound parameter: date ipaddress" + Invoke-Command $session {Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))} | Should -BeExactly "Bound parameter: date ipaddress" $module = Import-PSSession $session foo -AllowClobber } @@ -976,19 +976,19 @@ try } It "Pipeline binding works even when also binding by name" { - (Get-Date | foo) | Should -Be "Bound parameter: date" + (Get-Date | foo) | Should -BeExactly "Bound parameter: date" } It "Pipeline binding works even when also binding by name" { - ([ipaddress]::parse("127.0.0.1") | foo) | Should -Be "Bound parameter: ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo) | Should -BeExactly "Bound parameter: ipaddress" } It "Pipeline binding works even when also binding by name" { - ([ipaddress]::parse("127.0.0.1") | foo -date $(Get-Date)) | Should -Be "Bound parameter: date ipaddress" + ([ipaddress]::parse("127.0.0.1") | foo -date $(Get-Date)) | Should -BeExactly "Bound parameter: date ipaddress" } It "Pipeline binding works even when also binding by name" { - (Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))) | Should -Be "Bound parameter: date ipaddress" + (Get-Date | foo -ipaddress ([ipaddress]::parse("127.0.0.1"))) | Should -BeExactly "Bound parameter: date ipaddress" } } @@ -1013,9 +1013,9 @@ try } # Sanity checks. - Invoke-Command $session {gps -pid $pid | foo} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" - Invoke-Command $session {gps -pid $pid | foo -Total 5} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" - Invoke-Command $session {gps -pid $pid | foo -Priority normal} | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo} | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo -Total 5} | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" + Invoke-Command $session {gps -pid $pid | foo -Priority normal} | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" $module = Import-PSSession $session foo -AllowClobber } @@ -1026,15 +1026,15 @@ try } It "Pipeline binding works by property name" { - (gps -id $pid | foo) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo) | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" } It "Pipeline binding works by property name" { - (gps -id $pid | foo -Total 5) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo -Total 5) | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" } It "Pipeline binding works by property name" { - (gps -id $pid | foo -Priority normal) | Should -Be "Bound parameter: PriorityClass TotalProcessorTime" + (gps -id $pid | foo -Priority normal) | Should -BeExactly "Bound parameter: PriorityClass TotalProcessorTime" } } @@ -1059,8 +1059,8 @@ try } # Sanity checks. - Invoke-Command $session {foo ([ipaddress]::parse("127.0.0.1"))} | Should -Be "Bound parameter: ipaddress" - Invoke-Command $session {foo "blah"} | Should -Be "Bound parameter: string" + Invoke-Command $session {foo ([ipaddress]::parse("127.0.0.1"))} | Should -BeExactly "Bound parameter: ipaddress" + Invoke-Command $session {foo "blah"} | Should -BeExactly "Bound parameter: string" $module = Import-PSSession $session foo -AllowClobber } @@ -1071,11 +1071,11 @@ try } It "Positional binding works" { - foo "blah" | Should -Be "Bound parameter: string" + foo "blah" | Should -BeExactly "Bound parameter: string" } It "Positional binding works" { - foo ([ipaddress]::parse("127.0.0.1")) | Should -Be "Bound parameter: ipaddress" + foo ([ipaddress]::parse("127.0.0.1")) | Should -BeExactly "Bound parameter: ipaddress" } } @@ -1100,11 +1100,11 @@ try } # Sanity checks. - Invoke-Command $session {foo 1,2,3} | Should -Be "1 2 3 : " - Invoke-Command $session {foo 1,2,3 4} | Should -Be "1 2 3 : 4" - Invoke-Command $session {foo -p2 4 1,2,3} | Should -Be "1 2 3 : 4" - Invoke-Command $session {foo 1 4} | Should -Be "1 : 4" - Invoke-Command $session {foo -p2 4 1} | Should -Be "1 : 4" + Invoke-Command $session {foo 1,2,3} | Should -BeExactly "1 2 3 : " + Invoke-Command $session {foo 1,2,3 4} | Should -BeExactly "1 2 3 : 4" + Invoke-Command $session {foo -p2 4 1,2,3} | Should -BeExactly "1 2 3 : 4" + Invoke-Command $session {foo 1 4} | Should -BeExactly "1 : 4" + Invoke-Command $session {foo -p2 4 1} | Should -BeExactly "1 : 4" $module = Import-PSSession $session foo -AllowClobber } @@ -1115,23 +1115,23 @@ try } It "Positional binding works when binding an array value" { - foo 1,2,3 | Should -Be "1 2 3 : " + foo 1,2,3 | Should -BeExactly "1 2 3 : " } It "Positional binding works when binding an array value" { - foo 1,2,3 4 | Should -Be "1 2 3 : 4" + foo 1,2,3 4 | Should -BeExactly "1 2 3 : 4" } It "Positional binding works when binding an array value" { - foo -p2 4 1,2,3 | Should -Be "1 2 3 : 4" + foo -p2 4 1,2,3 | Should -BeExactly "1 2 3 : 4" } It "Positional binding works when binding an array value" { - foo 1 4 | Should -Be "1 : 4" + foo 1 4 | Should -BeExactly "1 : 4" } It "Positional binding works when binding an array value" { - foo -p2 4 1 | Should -Be "1 : 4" + foo -p2 4 1 | Should -BeExactly "1 : 4" } } @@ -1156,13 +1156,13 @@ try } # Sanity checks. - Invoke-Command $session {foo} | Should -Be " : " - Invoke-Command $session {foo 1} | Should -Be "1 : " - Invoke-Command $session {foo -first 1} | Should -Be "1 : " - Invoke-Command $session {foo 1 2 3} | Should -Be "1 : 2 3" - Invoke-Command $session {foo -first 1 2 3} | Should -Be "1 : 2 3" - Invoke-Command $session {foo 2 3 -first 1 4 5} | Should -Be "1 : 2 3 4 5" - Invoke-Command $session {foo -remainingArgs 2,3 1} | Should -Be "1 : 2 3" + Invoke-Command $session {foo} | Should -BeExactly " : " + Invoke-Command $session {foo 1} | Should -BeExactly "1 : " + Invoke-Command $session {foo -first 1} | Should -BeExactly "1 : " + Invoke-Command $session {foo 1 2 3} | Should -BeExactly "1 : 2 3" + Invoke-Command $session {foo -first 1 2 3} | Should -BeExactly "1 : 2 3" + Invoke-Command $session {foo 2 3 -first 1 4 5} | Should -BeExactly "1 : 2 3 4 5" + Invoke-Command $session {foo -remainingArgs 2,3 1} | Should -BeExactly "1 : 2 3" $module = Import-PSSession $session foo -AllowClobber } @@ -1173,31 +1173,31 @@ try } It "Value from remaining arguments works" { - $( foo ) | Should -Be " : " + $( foo ) | Should -BeExactly " : " } It "Value from remaining arguments works" { - $( foo 1 ) | Should -Be "1 : " + $( foo 1 ) | Should -BeExactly "1 : " } It "Value from remaining arguments works" { - $( foo -first 1 ) | Should -Be "1 : " + $( foo -first 1 ) | Should -BeExactly "1 : " } It "Value from remaining arguments works" { - $( foo 1 2 3 ) | Should -Be "1 : 2 3" + $( foo 1 2 3 ) | Should -BeExactly "1 : 2 3" } It "Value from remaining arguments works" { - $( foo -first 1 2 3 ) | Should -Be "1 : 2 3" + $( foo -first 1 2 3 ) | Should -BeExactly "1 : 2 3" } It "Value from remaining arguments works" { - $( foo 2 3 -first 1 4 5 ) | Should -Be "1 : 2 3 4 5" + $( foo 2 3 -first 1 4 5 ) | Should -BeExactly "1 : 2 3 4 5" } It "Value from remaining arguments works" { - $( foo -remainingArgs 2,3 1 ) | Should -Be "1 : 2 3" + $( foo -remainingArgs 2,3 1 ) | Should -BeExactly "1 : 2 3" } } @@ -1217,17 +1217,17 @@ try } # Sanity checks. - Invoke-Command $session { foo } | Should -Be " : : " - Invoke-Command $session { foo 1 } | Should -Be "1 : : " - Invoke-Command $session { foo -first 1 } | Should -Be "1 : : " - Invoke-Command $session { foo 1 2 } | Should -Be "1 : 2 : " - Invoke-Command $session { foo 1 -second 2 } | Should -Be "1 : 2 : " - Invoke-Command $session { foo -first 1 -second 2 } | Should -Be "1 : 2 : " - Invoke-Command $session { foo 1 2 3 4 } | Should -Be "1 : 2 : 3 4" - Invoke-Command $session { foo -first 1 2 3 4 } | Should -Be "1 : 2 : 3 4" - Invoke-Command $session { foo 1 -second 2 3 4 } | Should -Be "1 : 2 : 3 4" - Invoke-Command $session { foo 1 3 -second 2 4 } | Should -Be "1 : 2 : 3 4" - Invoke-Command $session { foo -first 1 -second 2 3 4 } | Should -Be "1 : 2 : 3 4" + Invoke-Command $session { foo } | Should -BeExactly " : : " + Invoke-Command $session { foo 1 } | Should -BeExactly "1 : : " + Invoke-Command $session { foo -first 1 } | Should -BeExactly "1 : : " + Invoke-Command $session { foo 1 2 } | Should -BeExactly "1 : 2 : " + Invoke-Command $session { foo 1 -second 2 } | Should -BeExactly "1 : 2 : " + Invoke-Command $session { foo -first 1 -second 2 } | Should -BeExactly "1 : 2 : " + Invoke-Command $session { foo 1 2 3 4 } | Should -BeExactly "1 : 2 : 3 4" + Invoke-Command $session { foo -first 1 2 3 4 } | Should -BeExactly "1 : 2 : 3 4" + Invoke-Command $session { foo 1 -second 2 3 4 } | Should -BeExactly "1 : 2 : 3 4" + Invoke-Command $session { foo 1 3 -second 2 4 } | Should -BeExactly "1 : 2 : 3 4" + Invoke-Command $session { foo -first 1 -second 2 3 4 } | Should -BeExactly "1 : 2 : 3 4" $module = Import-PSSession $session foo -AllowClobber } @@ -1238,47 +1238,47 @@ try } It "Non cmdlet-based binding works." { - foo | Should -Be " : : " + foo | Should -BeExactly " : : " } It "Non cmdlet-based binding works." { - foo 1 | Should -Be "1 : : " + foo 1 | Should -BeExactly "1 : : " } It "Non cmdlet-based binding works." { - foo -first 1 | Should -Be "1 : : " + foo -first 1 | Should -BeExactly "1 : : " } It "Non cmdlet-based binding works." { - foo 1 2 | Should -Be "1 : 2 : " + foo 1 2 | Should -BeExactly "1 : 2 : " } It "Non cmdlet-based binding works." { - foo 1 -second 2 | Should -Be "1 : 2 : " + foo 1 -second 2 | Should -BeExactly "1 : 2 : " } It "Non cmdlet-based binding works." { - foo -first 1 -second 2 | Should -Be "1 : 2 : " + foo -first 1 -second 2 | Should -BeExactly "1 : 2 : " } It "Non cmdlet-based binding works." { - foo 1 2 3 4 | Should -Be "1 : 2 : 3 4" + foo 1 2 3 4 | Should -BeExactly "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo -first 1 2 3 4 | Should -Be "1 : 2 : 3 4" + foo -first 1 2 3 4 | Should -BeExactly "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo 1 -second 2 3 4 | Should -Be "1 : 2 : 3 4" + foo 1 -second 2 3 4 | Should -BeExactly "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo 1 3 -second 2 4 | Should -Be "1 : 2 : 3 4" + foo 1 3 -second 2 4 | Should -BeExactly "1 : 2 : 3 4" } It "Non cmdlet-based binding works." { - foo -first 1 -second 2 3 4 | Should -Be "1 : 2 : 3 4" + foo -first 1 -second 2 3 4 | Should -BeExactly "1 : 2 : 3 4" } } @@ -1394,7 +1394,7 @@ try Invoke-Command $session { function foo { param($OutVariable) "OutVariable = $OutVariable" } } # Sanity check - Invoke-Command $session { foo -OutVariable x } | Should -Be "OutVariable = x" + Invoke-Command $session { foo -OutVariable x } | Should -BeExactly "OutVariable = x" $module = Import-PSSession -Session $session -Name foo -Type function -AllowClobber } @@ -1405,7 +1405,7 @@ try } It "Implicit remoting: OutVariable is not intercepted for non-cmdlet-bound functions" { - foo -OutVariable x | Should -Be "OutVariable = x" + foo -OutVariable x | Should -BeExactly "OutVariable = x" } } @@ -1587,13 +1587,13 @@ try It "Get-Command returns only 1 public command from implicit remoting module (1)" { $c = @(Get-Command -Module $module) $c.Count | Should -Be 1 - $c[0].Name | Should -Be "Get-MyVariable" + $c[0].Name | Should -BeExactly "Get-MyVariable" } It "Get-Command returns only 1 public command from implicit remoting module (2)" { $c = @(Get-Command -Module $module.Name) $c.Count | Should -Be 1 - $c[0].Name | Should -Be "Get-MyVariable" + $c[0].Name | Should -BeExactly "Get-MyVariable" } } @@ -1612,7 +1612,7 @@ try } It "'Completed' progress record should be present" { - ($powerShell.Streams.Progress | Select-Object -last 1).RecordType.ToString() | Should -Be "Completed" + ($powerShell.Streams.Progress | Select-Object -last 1).RecordType.ToString() | Should -BeExactly "Completed" } } @@ -1998,8 +1998,8 @@ try $bar = foo | Select-Object -First 2 $bar | Should -Not -Be NullOrEmpty $bar.Count | Should -Be 2 - $bar[0] | Should -Be "a" - $bar[1] | Should -Be "b" + $bar[0] | Should -BeExactly "a" + $bar[1] | Should -BeExactly "b" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 index 5163d39c43f..1b3959e72df 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Alias.Tests.ps1 @@ -73,11 +73,11 @@ Describe "Import-Alias" -Tags "CI" { It "Should be able to import an alias file and perform imported aliased echo cmd" { (Import-Alias $pesteraliasfile) - (pesterecho pestertesting) | Should -Be "pestertesting" + (pesterecho pestertesting) | Should -BeExactly "pestertesting" } It "Should be able to use ipal alias to import an alias file and perform cmd" { (ipal $pesteraliasfile) - (pesterecho pestertesting) | Should -Be "pestertesting" + (pesterecho pestertesting) | Should -BeExactly "pestertesting" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 index 25d6ec0469a..e707cb3a0f0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 @@ -67,9 +67,9 @@ Describe "Import-Csv File Format Tests" -Tags "CI" { It "Should be able to import correct values" { $actual = Import-Csv -Path $testCsv @HeaderParams $actual.count | Should -Be 4 - $actual[0].'Column1' | Should -Be "data1" - $actual[0].'Column2' | Should -Be "1" - $actual[0].'Column 3' | Should -Be "A" + $actual[0].'Column1' | Should -BeExactly "data1" + $actual[0].'Column2' | Should -BeExactly "1" + $actual[0].'Column 3' | Should -BeExactly "A" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 index e5bbb401b28..2807c0eba36 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-LocalizedData.Tests.ps1 @@ -13,7 +13,7 @@ Describe "Import-LocalizedData" -Tags "CI" { It "Should be able to import string using default culture" { # Set-Culture is broken, but let's verify that default culture is en-US $culture = Get-Culture -$culture.Name | Should -Be "en-US" +$culture.Name | Should -BeExactly "en-US" $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir $d.d0 | Should -Be $sunday diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 index 9700a514b92..874516e209c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Expression.Tests.ps1 @@ -5,14 +5,14 @@ Describe "Invoke-Expression" -Tags "CI" { Context "Should execute the invoked command validly" { It "Should return the echoed text" { - (Invoke-Expression -command "echo pestertest1") | Should -Be "pestertest1" + (Invoke-Expression -command "echo pestertest1") | Should -BeExactly "pestertest1" } It "Should return the echoed text from a script" { $testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1 $testcommand = "echo pestertestscript" $testcommand | Add-Content -Path "$testfile" - (Invoke-Expression "& '$testfile'") | Should -Be "pestertestscript" + (Invoke-Expression "& '$testfile'") | Should -BeExactly "pestertestscript" Remove-Item "$testfile" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 39c5c260bc6..8c397ebef40 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -11,28 +11,28 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { It "New-Alias NamePositional And Value Valid" { New-Alias ABCD -Value "MyCommand" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "MyCommand" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "MyCommand" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "New-Alias NamePositional And ValuePositional Valid" { New-Alias ABCD "MyCommand" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "MyCommand" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "MyCommand" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "New-Alias Description Valid" { New-Alias -Name ABCD -Value "MyCommand" -Description "test description" -Scope "0" $result=Get-Alias -Name ABCD -Scope "0" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "MyCommand" - $result.Description| Should -Be "test description" - $result.Options| Should -Be "None" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "MyCommand" + $result.Description| Should -BeExactly "test description" + $result.Options| Should -BeExactly "None" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 index aed16882ae4..851bfdf49ae 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 @@ -12,7 +12,7 @@ Describe "New-Event" -Tags "CI" { Context "Check New-Event can register an event"{ It "Should return PesterTestMessage as the MessageData" { (New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage") - (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -Be "PesterTestMessage" + (Get-Event -SourceIdentifier PesterTimer).MessageData | Should -BeExactly "PesterTestMessage" Remove-Event -sourceidentifier PesterTimer } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index f212e913319..2f7eaf3ccf7 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -40,7 +40,7 @@ Describe "New-Object" -Tags "CI" { $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" $o.GetType() | Should -Be ([System.Version]) - $o | Should -Be "1.2.3.4" + $o | Should -BeExactly "1.2.3.4" } } @@ -78,8 +78,8 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } $result = New-Object -TypeName Employee -ArgumentList "Mary", "Soe", 11 $result.Count | Should -Be 1 - $result.FirstName | Should -Be "Mary" - $result.LastName | Should -Be "Soe" + $result.FirstName | Should -BeExactly "Mary" + $result.LastName | Should -BeExactly "Soe" $result.YearsInMS | Should -Be 11 } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index 9b4e5d8354e..cbadfd76920 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -5,18 +5,18 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable variable with description should works"{ New-Variable foo bar -description "my description" $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" - $var1.Description|Should -Be "my description" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" + $var1.Description|Should -BeExactly "my description" } It "New-Variable variable with option should works"{ New-Variable foo bar -option Constant $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "Constant" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "Constant" $var1.Description|Should -BeNullOrEmpty } @@ -28,9 +28,9 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } @@ -42,9 +42,9 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { New-Variable foo bar -Force -PassThru $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } } @@ -67,13 +67,13 @@ Describe "New-Variable" -Tags "CI" { It "Should be able to assign a value to a new variable without using the value switch" { New-Variable var1 "test" - $var1 | Should -Be "test" + $var1 | Should -BeExactly "test" } It "Should assign a description to a new variable using the description switch" { New-Variable var1 100 -Description "Test Description" - (Get-Variable var1).Description | Should -Be "Test Description" + (Get-Variable var1).Description | Should -BeExactly "Test Description" } It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" { @@ -105,7 +105,7 @@ Describe "New-Variable" -Tags "CI" { It "Should be able to pipe object properties to output using the PassThru switch" { $in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru - $in.Description | Should -Be "test description" + $in.Description | Should -BeExactly "test description" } It "Should be able to set the value using the value switch" { @@ -120,7 +120,7 @@ Describe "New-Variable" -Tags "CI" { } It "Should default to none as the value for options" { - (new-variable -name var2 -value 4 -passthru).Options | Should -Be "None" + (new-variable -name var2 -value 4 -passthru).Options | Should -BeExactly "None" } It "Should be able to set ReadOnly option" { @@ -144,7 +144,7 @@ Describe "New-Variable" -Tags "CI" { Set-Variable -Name var1 -Option Constant -ErrorAction SilentlyContinue - (Get-Variable var1).Options | Should -Be "None" + (Get-Variable var1).Options | Should -BeExactly "None" } It "Should not be able to delete a constant variable" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 index 2ce6390d901..ec5760cc269 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewGuid.Tests.ps1 @@ -9,7 +9,7 @@ Describe "New-Guid" -Tags "CI" { It "should not be all zeros" { $guid = New-Guid - $guid.ToString() | Should -Not -Be "00000000-0000-0000-0000-000000000000" + $guid.ToString() | Should -Not -BeExactly "00000000-0000-0000-0000-000000000000" } It "should return different guids with each call" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 index 46c7bc65602..04f0554f49f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/NewTemporaryFile.Tests.ps1 @@ -33,6 +33,6 @@ Describe "New-TemporaryFile" -Tags "CI" { } It "has an OutputType of System.IO.FileInfo" { - (Get-Command New-TemporaryFile).OutputType | Should -Be "System.IO.FileInfo" + (Get-Command New-TemporaryFile).OutputType | Should -BeExactly "System.IO.FileInfo" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index 7438bbaf55b..b438c30a372 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -98,9 +98,9 @@ Describe "Out-File" -Tags "CI" { $actual = Get-Content $testfile $actual[0] | Should -BeNullOrEmpty - $actual[1] | Should -Be "text" - $actual[2] | Should -Be "----" - $actual[3] | Should -Be "some te..." + $actual[1] | Should -BeExactly "text" + $actual[2] | Should -BeExactly "----" + $actual[3] | Should -BeExactly "some te..." } It "Should allow the cmdlet to overwrite an existing read-only file" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 index 091d4c883fb..165ee0f0d52 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-String.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Out-String" -Tags "CI" { It "Should accumulate the strings and returns them as a single string" { $testArray = "a", " b" - $testArray | Out-String | Should -Be "a$nl b$nl" + $testArray | Out-String | Should -BeExactly "a$nl b$nl" ,$($testArray | Out-String) | Should -BeOfType "System.String" } @@ -50,12 +50,12 @@ Describe "Out-String" -Tags "CI" { It "Should not print a newline when the nonewline switch is used" { $testArray = "a", "b" - $testArray | Out-String -NoNewLine | Should -Be "ab" + $testArray | Out-String -NoNewLine | Should -BeExactly "ab" } It "Should preserve embedded newline when the nonewline switch is used" { $testArray = "a$nl", "b" - $testArray | Out-String -NoNewLine | Should -Be "a${nl}b" + $testArray | Out-String -NoNewLine | Should -BeExactly "a${nl}b" } It "Should throw error when NoNewLine and Stream are used together" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index 229015cd6b2..35d3bc68ba2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -77,8 +77,8 @@ Describe "Json Tests" -Tags "Feature" { }" } $op = [JsonEnumTest]::New() | convertto-json | convertfrom-json - $op.TestEnum1 | Should -Be "One" - $op.TestEnum2 | Should -Be "Two" + $op.TestEnum1 | Should -BeExactly "One" + $op.TestEnum2 | Should -BeExactly "Two" $op.TestEnum3 | Should -Be 1 } @@ -87,9 +87,9 @@ Describe "Json Tests" -Tags "Feature" { $JsonString = Get-Command Get-help |Select-Object Name, Noun, Verb| ConvertTo-Json $actual = ConvertFrom-Json $JsonString - $actual.Name | Should -Be "Get-Help" - $actual.Noun | Should -Be "Help" - $actual.Verb | Should -Be "Get" + $actual.Name | Should -BeExactly "Get-Help" + $actual.Noun | Should -BeExactly "Help" + $actual.Verb | Should -BeExactly "Get" } } @@ -113,7 +113,7 @@ Describe "Json Tests" -Tags "Feature" { $response2 = ConvertTo-Json -InputObject $response -Depth 1 -Compress $nameString = [System.Management.Automation.LanguagePrimitives]::ConvertTo($response.d.Name, [string]) - $response2 | Should -Be "{`"d`":{`"Name`":`"$nameString`",`"Greeting`":`"Hello`"}}" + $response2 | Should -BeExactly "{`"d`":{`"Name`":`"$nameString`",`"Greeting`":`"Hello`"}}" $result1 = @" { @@ -289,17 +289,17 @@ Describe "Json Tests" -Tags "Feature" { $result = ConvertFrom-Json $json $result.Count | Should -Be 4 - $result[0] | Should -Be "one" - $result[1] | Should -Be "two" - $result[3] | Should -Be "four" + $result[0] | Should -BeExactly "one" + $result[1] | Should -BeExactly "two" + $result[3] | Should -BeExactly "four" $hash = $result[2] $hash.First | Should -Be 1 $hash.Second | Should -Be 2 $hash.Third.Count | Should -Be 3 - $hash.Third[0] | Should -Be "Five" - $hash.Third[1] | Should -Be "Six" - $hash.Third[2] | Should -Be "Seven" + $hash.Third[0] | Should -BeExactly "Five" + $hash.Third[1] | Should -BeExactly "Six" + $hash.Third[2] | Should -BeExactly "Seven" } It "ConvertFrom-Json array nested in hash table" { @@ -308,15 +308,15 @@ Describe "Json Tests" -Tags "Feature" { $result = ConvertFrom-Json $json $result.First.Count | Should -Be 3 - $result.First[0] | Should -Be "one" - $result.First[1] | Should -Be "two" - $result.First[2] | Should -Be "three" + $result.First[0] | Should -BeExactly "one" + $result.First[1] | Should -BeExactly "two" + $result.First[2] | Should -BeExactly "three" $result.Second.Count | Should -Be 2 - $result.Second[0] | Should -Be "four" - $result.Second[1] | Should -Be "five" + $result.Second[0] | Should -BeExactly "four" + $result.Second[1] | Should -BeExactly "five" - $result.Third.blah | Should -Be "4" + $result.Third.blah | Should -BeExactly "4" } It "ConvertFrom-Json case insensitive test" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 index 683024fefff..79e77222294 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Register-ObjectEvent.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Register-ObjectEvent" -Tags "CI" { Context "Check Register-ObjectEvent can validly register events"{ It "Should return source identifier of PesterTimer " { Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister - (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -Be "PesterTestRegister" + (Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should -BeExactly "PesterTestRegister" } It "Should return an integer greater than 0 for the SubscriptionId" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 index f2cda04e3ae..2f82d2823b6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-TypeData.Tests.ps1 @@ -80,6 +80,6 @@ Describe "Remove-TypeData DRT Unit Tests" -Tags "CI" { It "Remove Type File In Initial Session State File Not In Cache" { $null = $ps.AddScript("Remove-TypeData -Path fakefile").Invoke() $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorID | Should -Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorID | Should -BeExactly "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index ab1a46b2807..df5c2faefe9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpvar2 -Value 2 New-Variable tmpmyvar1 -Value 234 - $tmpvar1 | Should -Be "tempvalue" + $tmpvar1 | Should -BeExactly "tempvalue" $tmpvar2 | Should -Be 2 $tmpmyvar1 | Should -Be 234 @@ -52,7 +52,7 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpvar2 -Value 2 New-Variable tmpmyvar1 -Value 234 - $tmpvar1 | Should -Be "tempvalue" + $tmpvar1 | Should -BeExactly "tempvalue" $tmpvar2 | Should -Be 2 $tmpmyvar1 | Should -Be 234 @@ -69,14 +69,14 @@ Describe "Remove-Variable" -Tags "CI" { New-Variable tmpmyvar1 -Value 234 New-Variable thevar -Value 1 - $tmpvar1 | Should -Be "tempvalue" + $tmpvar1 | Should -BeExactly "tempvalue" $tmpvar2 | Should -Be 2 $tmpmyvar1 | Should -Be 234 $thevar | Should -Be 1 Remove-Variable -Name tmp* -Include *my* - $tmpvar1 | Should -Be "tempvalue" + $tmpvar1 | Should -BeExactly "tempvalue" $tmpvar2 | Should -Be 2 $tmpmyvar1 | Should -Be #nothing. it should be Nothing at all. $thevar | Should -Be 1 @@ -119,7 +119,7 @@ Describe "Remove-Variable" -Tags "CI" { { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should -Throw - $var1 | Should -Be "context" + $var1 | Should -BeExactly "context" Remove-Variable -Name var1 -Scope global $var1 | Should -BeNullOrEmpty @@ -130,7 +130,7 @@ Describe "Remove-Variable" -Tags "CI" { { Remove-Variable -Name var1 -Scope local -ErrorAction Stop } | Should -Throw - $var1 | Should -Be "context" + $var1 | Should -BeExactly "context" Remove-Variable -Name var1 -Scope global $var1 | Should -BeNullOrEmpty @@ -149,7 +149,7 @@ Describe "Remove-Variable" -Tags "CI" { { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should -Throw - $var1 | Should -Be "context" + $var1 | Should -BeExactly "context" Remove-Variable -Name var1 -Scope local $var1 | Should -BeNullOrEmpty @@ -160,7 +160,7 @@ Describe "Remove-Variable" -Tags "CI" { { Remove-Variable -Name var1 -Scope script -ErrorAction Stop } | Should -Throw - $var1 | Should -Be "context" + $var1 | Should -BeExactly "context" Remove-Variable -Name var1 -Scope local $var1 | Should -BeNullOrEmpty @@ -179,7 +179,7 @@ Describe "Remove-Variable" -Tags "CI" { { Remove-Variable -Name var1 -Scope global -ErrorAction Stop } | Should -Throw - $var1 | Should -Be "context" + $var1 | Should -BeExactly "context" } } } @@ -226,10 +226,10 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { } $var1 = Get-Variable -Name foo - $var1.Name | Should -Be "foo" - $var1.Value | Should -Be "bar" - $var1.Options | Should -Be "None" - $var1.Description | Should -Be "" + $var1.Name | Should -BeExactly "foo" + $var1.Value | Should -BeExactly "bar" + $var1.Options | Should -BeExactly "None" + $var1.Description | Should -BeExactly "" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index ad029f8ee08..e3095cb2129 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -239,7 +239,7 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { It "Select-Object with Index should work"{ $results = "1","2","3" | Select-Object -Index 2 $results.Count | Should -Be 1 - $results[0] | Should -Be "3" + $results[0] | Should -BeExactly "3" } } @@ -275,14 +275,14 @@ Describe "Select-Object with Property = '*'" -Tags "CI" { It "Select-Object with implicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -ExcludeProperty Param2 $results.Param2 | Should -BeNullOrEmpty - $results.Thing | Should -Be "thing1" + $results.Thing | Should -BeExactly "thing1" } # Issue #2351 It "Select-Object with explicit Property = '*' exclude not single property"{ $results = [pscustomobject]@{Thing="thing1";Param2="param2"} | Select-Object -Property * -ExcludeProperty Param2 $results.Param2 | Should -BeNullOrEmpty - $results.Thing | Should -Be "thing1" + $results.Thing | Should -BeExactly "thing1" } It "Select-Object with ExpandProperty and Property don't skip processing ExcludeProperty" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 index 520523e7ed5..e14dcd39265 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-XML.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Select-XML DRT Unit Tests" -Tags "CI" { It "Select-XML should work"{ $results = Select-XML -Path $testfile -XPath "/bookstore/book/title" $results.Count | Should -Be 2 - $results[0].Node."#text" | Should -Be "Harry Potter" - $results[1].Node."#text" | Should -Be "Learning XML" + $results[0].Node."#text" | Should -BeExactly "Harry Potter" + $results[1].Node."#text" | Should -BeExactly "Learning XML" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 index 789862d81b7..327114113b6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Alias.Tests.ps1 @@ -9,64 +9,64 @@ Describe "Set-Alias DRT Unit Tests" -Tags "CI" { It "Set-Alias ReadOnly Force"{ Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "ReadOnly" + $result.Options| Should -BeExactly "ReadOnly" Set-Alias -Name ABCD -Value "foo" -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Set-Alias Name And Value Valid"{ Set-Alias -Name ABCD -Value "MyCommand" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "MyCommand" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "MyCommand" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Set-Alias Name And Value Positional Valid"{ Set-Alias -Name ABCD "foo" $result=Get-Alias ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Set-Alias Description Valid"{ Set-Alias -Name ABCD -Value "MyCommand" -Description "test description" $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "MyCommand" - $result.Description| Should -Be "test description" - $result.Options| Should -Be "None" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "MyCommand" + $result.Description| Should -BeExactly "test description" + $result.Options| Should -BeExactly "None" } It "Set-Alias Scope Valid"{ Set-Alias -Name ABCD -Value "localfoo" -scope local -Force:$true Set-Alias -Name ABCD -Value "foo1" -scope "1" -Force:$true $result=Get-Alias -Name ABCD - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "localfoo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "localfoo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope local - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "localfoo" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "localfoo" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" $result=Get-Alias -Name ABCD -scope "1" - $result.Name| Should -Be "ABCD" - $result.Definition| Should -Be "foo1" + $result.Name| Should -BeExactly "ABCD" + $result.Definition| Should -BeExactly "foo1" $result.Description| Should -BeNullOrEmpty - $result.Options| Should -Be "None" + $result.Options| Should -BeExactly "None" } It "Set-Alias Expose Bug 1062958, BugId:905449"{ { Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand" diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 index d05635977a8..0df446588f6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-PSBreakpoint.Tests.ps1 @@ -98,13 +98,13 @@ set-psbreakpoint -command foo It "Should be able to set psbreakpoints for -command" { $brk = set-psbreakpoint -command "write-host" - $brk.Command | Should -Be "write-host" + $brk.Command | Should -BeExactly "write-host" Remove-PSBreakPoint -Id $brk.Id } It "Should be able to set psbreakpoints for -command, -script" { $brk = set-psbreakpoint -command "write-host" -script $scriptFileName - $brk.Command | Should -Be "write-host" + $brk.Command | Should -BeExactly "write-host" Remove-PSBreakPoint -Id $brk.Id } @@ -122,11 +122,11 @@ set-psbreakpoint -command foo It "-Script is positional" { $brk = set-psbreakpoint -command "Hello" $scriptFileName - $brk.Command | Should -Be "Hello" + $brk.Command | Should -BeExactly "Hello" Remove-PSBreakPoint -Id $brk.Id $brk = set-psbreakpoint $scriptFileName -command "Hello" - $brk.Command | Should -Be "Hello" + $brk.Command | Should -BeExactly "Hello" Remove-PSBreakPoint -Id $brk.Id } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 index 6977081d0e3..b2a46790e1d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 @@ -5,18 +5,18 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable normal variable Name should works"{ Set-Variable foo bar $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } It "Set-Variable normal variable Name with position should works"{ Set-Variable -Name foo bar $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } @@ -25,23 +25,23 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable -Name foo -Value bar -Scope "1" $var1=Get-Variable -Name foo -scope "1" - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty Set-Variable -Name foo -Value newValue -Scope "local" $var1=Get-Variable -Name foo -scope "local" - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "newValue" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "newValue" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty Set-Variable -Name foo -Value newValue2 -Scope "script" $var1=Get-Variable -Name foo -scope "script" - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "newValue2" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "newValue2" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } @@ -53,19 +53,19 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable -Name "*aV*" -Value "overwrite" -Include "*Var*" -Exclude "bcd*" $var1=Get-Variable -Name "*aVar*" -Scope "local" - $var1[0].Name|Should -Be "abcaVar" - $var1[0].Value|Should -Be "overwrite" - $var1[0].Options|Should -Be "None" + $var1[0].Name|Should -BeExactly "abcaVar" + $var1[0].Value|Should -BeExactly "overwrite" + $var1[0].Options|Should -BeExactly "None" $var1[0].Description|Should -BeNullOrEmpty - $var1[1].Name|Should -Be "aVarfoo" - $var1[1].Value|Should -Be "overwrite" - $var1[1].Options|Should -Be "None" + $var1[1].Name|Should -BeExactly "aVarfoo" + $var1[1].Value|Should -BeExactly "overwrite" + $var1[1].Options|Should -BeExactly "None" $var1[1].Description|Should -BeNullOrEmpty - $var1[2].Name|Should -Be "bcdaVar" - $var1[2].Value|Should -Be "anotherVal" - $var1[2].Options|Should -Be "None" + $var1[2].Name|Should -BeExactly "bcdaVar" + $var1[2].Value|Should -BeExactly "anotherVal" + $var1[2].Options|Should -BeExactly "None" $var1[2].Description|Should -BeNullOrEmpty } @@ -73,20 +73,20 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { Set-Variable foo bar Set-Variable -Name foo $null -Description "new description" -PassThru:$true -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should -Be "foo" + $var1.Name|Should -BeExactly "foo" $var1.Value|Should -BeNullOrEmpty - $var1.Options|Should -Be "None" - $var1.Description|Should -Be "new description" + $var1.Options|Should -BeExactly "None" + $var1.Description|Should -BeExactly "new description" } It "Set-Variable normal variable Name with just Description should works"{ Set-Variable foo bar Set-Variable -Name foo -Description "new description" -PassThru:$true -Scope "local" $var1=Get-Variable -Name foo -Scope "local" - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" - $var1.Description|Should -Be "new description" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" + $var1.Description|Should -BeExactly "new description" } It "Set-Variable overwrite Constant Option should throw SessionStateUnauthorizedAccessException"{ @@ -97,17 +97,17 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable of existing Private variable without force should throw Exception"{ Set-Variable abcaVar bar -Description "new description" -Option Private $var1=Get-Variable -Name abcaVar - $var1.Name|Should -Be "abcaVar" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "Private" - $var1.Description|Should -Be "new description" + $var1.Name|Should -BeExactly "abcaVar" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "Private" + $var1.Description|Should -BeExactly "new description" Set-Variable abcaVar other -Description "new description" $var1=Get-Variable -Name abcaVar - $var1.Name|Should -Be "abcaVar" - $var1.Value|Should -Be "other" - $var1.Options|Should -Be "Private" - $var1.Description|Should -Be "new description" + $var1.Name|Should -BeExactly "abcaVar" + $var1.Value|Should -BeExactly "other" + $var1.Options|Should -BeExactly "Private" + $var1.Description|Should -BeExactly "new description" } It "Set-Variable with Exclude, then Get-Variable it should throw ItemNotFoundException"{ @@ -118,29 +118,29 @@ Describe "Set-Variable DRT Unit Tests" -Tags "CI" { It "Set-Variable of existing ReadOnly variable without force should throw Exception"{ Set-Variable abcaVar bar -Description "new description" -Option ReadOnly $var1=Get-Variable -Name abcaVar - $var1.Name|Should -Be "abcaVar" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "ReadOnly" - $var1.Description|Should -Be "new description" + $var1.Name|Should -BeExactly "abcaVar" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "ReadOnly" + $var1.Description|Should -BeExactly "new description" { Set-Variable abcaVar -Option None -Scope 1 -EA Stop } | Should -Throw -ErrorId "VariableNotWritable,Microsoft.PowerShell.Commands.SetVariableCommand" } It "Set-Variable of ReadOnly variable with private scope should work"{ Set-Variable foo bar -Description "new description" -Option ReadOnly -scope "private" $var1=Get-Variable -Name foo - $var1.Name|Should -Be "foo" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "ReadOnly, Private" - $var1.Description|Should -Be "new description" + $var1.Name|Should -BeExactly "foo" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "ReadOnly, Private" + $var1.Description|Should -BeExactly "new description" } It "Set-Variable pipeline with Get-Variable should work"{ $footest1="bar" ${Get-Variable footest1 -valueonly|Set-Variable bootest1 -passthru} $var1=Get-Variable -Name footest1 - $var1.Name|Should -Be "footest1" - $var1.Value|Should -Be "bar" - $var1.Options|Should -Be "None" + $var1.Name|Should -BeExactly "footest1" + $var1.Value|Should -BeExactly "bar" + $var1.Options|Should -BeExactly "None" $var1.Description|Should -BeNullOrEmpty } } @@ -198,7 +198,7 @@ Describe "Set-Variable" -Tags "CI" { $output = $in | Format-List -Property Description | Out-String # This will cause errors running these tests in Windows - $output.Trim() | Should -Be "Description : test description" + $output.Trim() | Should -BeExactly "Description : test description" } It "Should be able to set the value using the value switch" { @@ -208,7 +208,7 @@ Describe "Set-Variable" -Tags "CI" { Set-Variable -Name testVar -Value "test" - $testVar | Should -Be "test" + $testVar | Should -BeExactly "test" } Context "Scope Tests" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 index 1c2ce5ed842..d2e8154f081 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 @@ -31,19 +31,19 @@ Describe "Sort-Object DRT Unit Tests" -Tags "CI" { $employees = @($employee1,$employee2,$employee3,$employee4) $results = $employees | Sort-Object -Property YearsInMS - $results[0].FirstName | Should -Be "Minus" - $results[0].LastName | Should -Be "Two" + $results[0].FirstName | Should -BeExactly "Minus" + $results[0].LastName | Should -BeExactly "Two" $results[0].YearsInMS | Should -Be -2 - $results[1].FirstName | Should -Be "Eight" + $results[1].FirstName | Should -BeExactly "Eight" $results[1].YearsInMS | Should -BeNullOrEmpty - $results[2].FirstName | Should -Be "One" - $results[2].LastName | Should -Be "One" + $results[2].FirstName | Should -BeExactly "One" + $results[2].LastName | Should -BeExactly "One" $results[2].YearsInMS | Should -Be 1 - $results[3].FirstName | Should -Be "Eight" - $results[3].LastName | Should -Be "Eight" + $results[3].FirstName | Should -BeExactly "Eight" + $results[3].LastName | Should -BeExactly "Eight" $results[3].YearsInMS | Should -Be 8 } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 index cdb36fd9a0f..1d5781be499 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 @@ -9,14 +9,14 @@ Describe "Tee-Object" -Tags "CI" { It "Should return the output to the screen and to the variable" { $teefile = $testfile echo teeobjecttest1 | Tee-Object -variable teeresults - $teeresults | Should -Be "teeobjecttest1" + $teeresults | Should -BeExactly "teeobjecttest1" Remove-Item $teefile -ErrorAction SilentlyContinue } It "Should tee the output to a file" { $teefile = $testfile echo teeobjecttest3 | Tee-Object $teefile - Get-Content $teefile | Should -Be "teeobjecttest3" + Get-Content $teefile | Should -BeExactly "teeobjecttest3" Remove-Item $teefile -ErrorAction SilentlyContinue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index af417016d32..02902345794 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -52,7 +52,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript("Update-TypeData -PrependPath $testfile") $ps.Invoke() $ps.HadErrors | Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid File Extension should throw Exception"{ @@ -75,7 +75,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.commands.clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke()| Should -Be "test" + $ps.Invoke()| Should -BeExactly "test" $ps.commands.clear() $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value $null -TypeName System.String -Force') $ps.Invoke() @@ -90,7 +90,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should -Be "Int32" + $ps.Invoke()| Should -BeExactly "Int32" # test $ps.Commands.Clear() @@ -105,7 +105,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should -Be "String" + $ps.Invoke()| Should -BeExactly "String" # test $ps.Commands.Clear() @@ -120,7 +120,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $null = $ps.AddScript('"string".TestScriptMethod()') - $ps.Invoke()| Should -Be "script method" + $ps.Invoke()| Should -BeExactly "script method" $ps.Commands.Clear() $script2="new script method" $null = $ps.AddScript("Update-TypeData -MemberType ScriptMethod -MemberName TestScriptMethod -Value {'$script2'} -TypeName System.String -Force") @@ -128,7 +128,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $null = $ps.AddScript('"string".TestScriptMethod()') - $ps.Invoke() | Should -Be "new script method" + $ps.Invoke() | Should -BeExactly "new script method" } It "Update-TypeData with Valid Dynamic Type Accept TypeData Object should work"{ @@ -143,7 +143,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { # tests $ps.Commands.Clear() - $ps.AddScript('$result.TestNote1').Invoke() | Should -Be "Hello" + $ps.AddScript('$result.TestNote1').Invoke() | Should -BeExactly "Hello" $ps.Commands.Clear() $ps.AddScript('$result.TestNote').Invoke() | Should -Be 2 } @@ -152,59 +152,59 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript('Update-TypeData -MemberType AliasProperty -MemberName TestAlias -Value $null -TypeName System.String') $ps.Invoke() $ps.HadErrors |Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No MemberName should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -Value "Error" -TypeName System.String') $ps.Invoke() $ps.HadErrors |Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No Value should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -TypeName System.String') $ps.Invoke() $ps.HadErrors |Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with Empty TypeData should throw Exception"{ $null = $ps.AddScript("Update-TypeData -TypeName System.String") $ps.Invoke() $ps.HadErrors |Should -BeTrue - $ps.Streams.Error[0].FullyQualifiedErrorId | Should -Be "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" + $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Valid Standard Members Serialization Method String should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod string -StringSerializationSource Length -TargetTypeForDeserialization string -TypeName System.String') $ps.Invoke() $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -Be "String" + $ps.Invoke()| Should -BeExactly "String" $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.StringSerializationSource') $ps.Invoke()| Should -Be 6 $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should -Be "string" + $ps.Invoke()| Should -BeExactly "string" } It "Update-TypeData with Valid Standard Members Serialization Method SpecificProperties should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod SpecificProperties -StringSerializationSource Length -PropertySerializationSet Length -InheritPropertySerializationSet $true -SerializationDepth 2 -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke() | Should -Be "SpecificProperties" + $ps.Invoke() | Should -BeExactly "SpecificProperties" $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.StringSerializationSource') $ps.Invoke() | Should -Be 6 $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.SerializationDepth') $ps.Invoke() | Should -Be 2 $ps.Commands.Clear();$null=$ps.AddScript('"string".PSStandardMembers.InheritPropertySerializationSet') - $ps.Invoke() | Should -Be "True" + $ps.Invoke() | Should -BeExactly "True" } It "Update-TypeData with Valid Standard Members Serialization Method AllPublicProperties should work"{ $null = $ps.AddScript('Update-TypeData -SerializationMethod AllPublicProperties -StringSerializationSource Length -SerializationDepth 2 -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -Be "AllPublicProperties" + $ps.Invoke()| Should -BeExactly "AllPublicProperties" $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.StringSerializationSource') $ps.Invoke()| Should -Be 6 $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationDepth') @@ -215,30 +215,30 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName "TestNote" -Value "test the note" -SerializationMethod SpecificProperties -SerializationDepth 5 -PropertySerializationSet Length -DefaultDisplayPropertySet Length -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should -Be "test the note" + $ps.Invoke()| Should -BeExactly "test the note" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -Be "SpecificProperties" + $ps.Invoke()| Should -BeExactly "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') $ps.Invoke()| Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -Be "Length" + $ps.Invoke()| Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -Be "Length" + $ps.Invoke()| Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value "test the note again" -TargetTypeForDeserialization string -Force -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should -Be "test the note again" + $ps.Invoke()| Should -BeExactly "test the note again" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -Be "SpecificProperties" + $ps.Invoke()| Should -BeExactly "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') $ps.Invoke()| Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -Be "Length" + $ps.Invoke()| Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -Be "Length" + $ps.Invoke()| Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should -Be "string" + $ps.Invoke()| Should -BeExactly "string" } It "Update-TypeData with Valid ISS UpdateType Command Test With StrongType Set should work"{ @@ -254,14 +254,14 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.AddStatement() $ps.AddScript('Update-TypeData -TypeName System.Array -SerializationMethod AllPublicProperties -SerializationDepth 2 -StringSerializationSource Length -TargetTypeForDeserialization string') $ps.Invoke() - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestNote').Invoke() | Should -Be "TestNote" + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestNote').Invoke() | Should -BeExactly "TestNote" $ps.Commands.Clear();$ps.AddScript('(1, 3).TestAlias').Invoke() | Should -Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptMethod()').Invoke() | Should -Be "script method" + $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptMethod()').Invoke() | Should -BeExactly "script method" $ps.Commands.Clear();$ps.AddScript('(1, 3).TestScriptProperty').Invoke() | Should -Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationMethod').Invoke() | Should -Be "AllPublicProperties" + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationMethod').Invoke() | Should -BeExactly "AllPublicProperties" $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.SerializationDepth').Invoke() | Should -Be 2 $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.StringSerializationSource').Invoke() | Should -Be 2 - $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.TargetTypeForDeserialization').Invoke() | Should -Be "string" + $ps.Commands.Clear();$ps.AddScript('(1, 3).PSStandardMembers.TargetTypeForDeserialization').Invoke() | Should -BeExactly "string" } # this looks identical to the test directly above @@ -274,14 +274,14 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $script2={$this.Length} Update-TypeData -TypeName System.Object[] -MemberType ScriptProperty -MemberName TestScriptProperty -Value $script2 Update-TypeData -TypeName System.Object[] -SerializationMethod AllPublicProperties -SerializationDepth 2 -StringSerializationSource Length -TargetTypeForDeserialization string - (1, 3).TestNote | Should -Be "TestNote" + (1, 3).TestNote | Should -BeExactly "TestNote" (1, 3).TestAlias | Should -Be 2 - (1, 3).TestScriptMethod() | Should -Be "script method" + (1, 3).TestScriptMethod() | Should -BeExactly "script method" (1, 3).TestScriptProperty | Should -Be 2 - (1, 3).PSStandardMembers.SerializationMethod | Should -Be "AllPublicProperties" + (1, 3).PSStandardMembers.SerializationMethod | Should -BeExactly "AllPublicProperties" (1, 3).PSStandardMembers.SerializationDepth | Should -Be 2 (1, 3).PSStandardMembers.StringSerializationSource | Should -Be 2 - (1, 3).PSStandardMembers.TargetTypeForDeserialization | Should -Be "string" + (1, 3).PSStandardMembers.TargetTypeForDeserialization | Should -BeExactly "string" } finally { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 index 3cc92e0151d..99e822adde0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Stream writer tests" -Tags "CI" { It "Should write warnings to the warning stream" { Write-Warning "Test Warning" 3>&1 > $targetfile - Get-Content $targetfile | Should -Be "Test Warning" + Get-Content $targetfile | Should -BeExactly "Test Warning" } It "Should write error messages to the error stream" { @@ -94,15 +94,15 @@ Describe "Stream writer tests" -Tags "CI" { $result.User | Should -Be $(whoami) } - "$result" | Should -Be "Test Message" + "$result" | Should -BeExactly "Test Message" } It "Write-Information accept objects from pipe" { $ps.AddScript("'teststring',12345 | Write-Information -InformationAction Continue").Invoke() $result = $ps.Streams.Information $result.Count | Should -Be 2 - $result[0].MessageData | Should -Be "teststring" - $result[1].MessageData | Should -Be "12345" + $result[0].MessageData | Should -BeExactly "teststring" + $result[1].MessageData | Should -BeExactly "12345" } It "Write-Information works with " -TestCases:$testInfoData { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 index f4caee8e1bc..77bbbaf3321 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Verbose.Tests.ps1 @@ -20,13 +20,13 @@ Describe "Write-Verbose" -Tags "CI" { } It "Should be able to set verbose output to display by using the verbose switch" { - Write-Verbose -Message "test" -Verbose 4>&1 | Should -Be "test" + Write-Verbose -Message "test" -Verbose 4>&1 | Should -BeExactly "test" } It "Should be able to set verbose switch using a colon and boolean" { { Write-Verbose -Message "test" -Verbose:$false } | Should -Not -Throw - $(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should -Be "test" + $(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should -BeExactly "test" } It "Should not have added line breaks" { From 31b777c628172b64f73e2ab4f67da0fc4328c749 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Mon, 19 Mar 2018 13:20:14 -0700 Subject: [PATCH 18/21] [Feature] Utility tests correction - adding ErrorId to Throw statement --- .../ConvertFrom-StringData.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 index 6cfb3f71d53..00eb504fc04 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-StringData.Tests.ps1 @@ -29,11 +29,11 @@ bazz = 2 } It "Should throw if not in x=y format" { - { ConvertFrom-StringData -StringData 'ab' } | Should -Throw - { ConvertFrom-StringData -StringData 'a,b' } | Should -Throw - { ConvertFrom-StringData -StringData 'a b' } | Should -Throw - { ConvertFrom-StringData -StringData 'a\tb' } | Should -Throw - { ConvertFrom-StringData -StringData 'a:b' } | Should -Throw + { ConvertFrom-StringData -StringData 'ab' } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + { ConvertFrom-StringData -StringData 'a,b' } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + { ConvertFrom-StringData -StringData 'a b' } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + { ConvertFrom-StringData -StringData 'a\tb' } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" + { ConvertFrom-StringData -StringData 'a:b' } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand" } It "Should return the data on the left side in the key" { From 4cc6225412a15a16d2b8a896c138e312ff1654c4 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Tue, 20 Mar 2018 11:34:58 -0700 Subject: [PATCH 19/21] [Feature] Tests in Utility module syntax correction. --- .../Export-Alias.Tests.ps1 | 9 +-- .../Format-Custom.Tests.ps1 | 5 +- .../Format-List.Tests.ps1 | 4 +- .../Format-Table.Tests.ps1 | 3 +- .../Get-Uptime.Tests.ps1 | 8 +-- .../New-Alias.Tests.ps1 | 24 ++++---- .../New-Object.Tests.ps1 | 11 ++-- .../New-Variable.Tests.ps1 | 6 +- .../Remove-Variable.Tests.ps1 | 15 +++-- .../Select-Object.Tests.ps1 | 3 +- .../Update-TypeData.Tests.ps1 | 58 +++++++++---------- 11 files changed, 75 insertions(+), 71 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 index b36f342ef6a..b15ac09ee8d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Alias.Tests.ps1 @@ -38,12 +38,9 @@ Describe "Export-Alias DRT Unit Tests" -Tags "CI" { } It "Export-Alias resolving to multiple files will throw ReadWriteMultipleFilesNotSupported" { - { - $null = New-Item -Path $TestDrive\foo -ItemType File - $null = New-Item -Path $TestDrive\bar -ItemType File - Export-Alias $TestDrive\* - Throw "Execution OK" - } | Should -Throw -ErrorId "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" + $null = New-Item -Path $TestDrive\foo -ItemType File + $null = New-Item -Path $TestDrive\bar -ItemType File + { Export-Alias $TestDrive\* } | Should -Throw -ErrorId "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand" Remove-Item $TestDrive\foo -Force -ErrorAction SilentlyContinue Remove-Item $TestDrive\bar -Force -ErrorAction SilentlyContinue diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 index f22ac7294b7..55d211a0120 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 @@ -15,12 +15,11 @@ Describe "Format-Custom" -Tags "CI" { It "Should be able to specify the depth in output" { $getprocesspester = Get-FormatData | Format-Custom -depth 1 - ($getprocesspester).Count | Should -BeGreaterThan 0 + ($getprocesspester).Count | Should -BeGreaterThan 0 } It "Should be able to use the Property flag to select properties" { - $CommandName = Get-Command | Format-Custom -Property "Name" - $CommandName | Should -Not -Match "Source" + Get-Command | Format-Custom -Property "Name" | Should -Not -Match "Source" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 index 03ff9cdba8d..78563a680ec 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 @@ -34,9 +34,9 @@ Describe "Format-List" -Tags "CI" { It "Should be able to call a property of the piped input" { # Tested on two input commands to verify functionality. - { Get-Command | Select-Object -First 5 | Format-List -Property Name } | Should -Not -BeNullOrEmpty + Get-Command | Select-Object -First 5 | Format-List -Property Name | Should -Not -BeNullOrEmpty - { Get-Date | Format-List -Property DisplayName } | Should -Not -BeNullOrEmpty + Get-Date | Format-List -Property DisplayName | Should -Not -BeNullOrEmpty } It "Should be able to display a list of props when separated by a comma" { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index be09d60be7b..e5359e67e01 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -32,7 +32,8 @@ Describe "Format-Table" -Tags "CI" { Describe "Format-Table DRT Unit Tests" -Tags "CI" { It "Format-Table with not existing table with force should throw PipelineStoppedException"{ $obj = New-Object -typename PSObject - $e = { $obj | Format-Table -view bar -force -EA Stop } | ShouldBeErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" + $e = { $obj | Format-Table -view bar -force -EA Stop } | + Should -Throw -ErrorId "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand" -PassThru $e.CategoryInfo | Should -Match "PipelineStoppedException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index d33f8e905ab..21ece0a7db8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -26,12 +26,10 @@ Describe "Get-Uptime" -Tags "CI" { $upt | Should -BeOfType "DateTime" } It "Get-Uptime throw if IsHighResolution == false" { - { - # Enable the test hook - [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true) + # Enable the test hook + [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true) - Get-Uptime - } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + { Get-Uptime } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" # Disable the test hook [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false) } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 index 8c397ebef40..ecee9d9f6fa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Alias.Tests.ps1 @@ -4,7 +4,7 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{ New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true $e = { New-Alias -Name "ABCD" -Value "foo" -Force:$true -Scope 1 -ErrorAction Stop } | - ShouldBeErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" + Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } @@ -38,8 +38,8 @@ Describe "New-Alias DRT Unit Tests" -Tags "CI" { Describe "New-Alias" -Tags "CI" { It "Should be able to be called using the name and value parameters without error" { - { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw - } + { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw + } It "Should have the same output between the alias and the original cmdlet" { New-Alias -Name testAlias -Value Get-Command @@ -53,20 +53,20 @@ Describe "New-Alias" -Tags "CI" { } It "Should be able to call the New-Alias cmdlet using the nal alias without error" { - { nal -Name testAlias -Value 100 } | Should -Not -Throw + { nal -Name testAlias -Value 100 } | Should -Not -Throw } It "Should have the same output between the nal alias and the New-Alias cmdlet" { - nal -Name testAlias -Value Get-Command + nal -Name testAlias -Value Get-Command - New-Alias -Name testalias2 -Value Get-Command + New-Alias -Name testalias2 -Value Get-Command - $aliasData = $(testAlias).Id - $cmdletData = $(testAlias2).Id + $aliasData = $(testAlias).Id + $cmdletData = $(testAlias2).Id - foreach ($IdNumber in $aliasData) - { - $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber] - } + foreach ($IdNumber in $aliasData) + { + $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber] + } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index 2f7eaf3ccf7..2a20fae24af 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -84,19 +84,20 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { } It "New-Object with invalid type should throw Exception"{ - $e = { New-Object -TypeName LiarType -EA Stop } | ShouldBeErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName LiarType -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" -PassThru $e.CategoryInfo | Should -Match "PSArgumentException" } It "New-Object with invalid argument should throw Exception"{ $e = { New-Object -TypeName System.Management.Automation.PSVariable -ArgumentList "A", 1, None, "asd" -EA Stop } | - ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" -PassThru $e.CategoryInfo | Should -Match "MethodException" } It "New-Object with abstract class should throw Exception"{ Add-Type -TypeDefinition "public abstract class AbstractEmployee{public AbstractEmployee(){}}" - $e = { New-Object -TypeName AbstractEmployee -EA Stop } | ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName AbstractEmployee -EA Stop } | + Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" -PassThru $e.CategoryInfo | Should -Match "MethodInvocationException" } @@ -105,7 +106,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { { Add-Type -TypeDefinition "public class Employee{public Employee(string firstName,string lastName,int yearsInMS){FirstName = firstName;LastName=lastName;YearsInMS = yearsInMS;}public string FirstName;public string LastName;public int YearsInMS;}" } - $e = { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | ShouldBeErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName Employee -ArgumentList 11 -EA Stop } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand" -PassThru $e.CategoryInfo | Should -Match "MethodException" } @@ -120,7 +121,7 @@ Describe "New-Object DRT basic functionality" -Tags "CI" { It "New-Object with Private Nested class should throw Exception"{ Add-Type -TypeDefinition "public class WeirdEmployee{public WeirdEmployee(){}private class PrivateNestedWeirdEmployee{public PrivateNestedWeirdEmployee(){}}}" - $e = { New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | ShouldBeErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" + $e = { New-Object -TypeName WeirdEmployee+PrivateNestedWeirdEmployee -EA Stop } | Should -Throw -ErrorId "TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand" -PassThru $e.CategoryInfo | Should -Match "PSArgumentException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 index cbadfd76920..af487e989f2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Variable.Tests.ps1 @@ -23,7 +23,8 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable variable twice should throw Exception"{ New-Variable foo bogus - $e = { New-Variable foo bar -Scope 1 -EA Stop } | ShouldBeErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e = { New-Variable foo bar -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateException" New-Variable foo bar -Force -PassThru @@ -37,7 +38,8 @@ Describe "New-Variable DRT Unit Tests" -Tags "CI" { It "New-Variable ReadOnly variable twice should throw Exception"{ New-Variable foo bogus -option ReadOnly - $e = { New-Variable foo bar -Scope 1 -EA Stop } | ShouldBeErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" + $e = { New-Variable foo bar -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableAlreadyExists,Microsoft.PowerShell.Commands.NewVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateException" New-Variable foo bar -Force -PassThru diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 index df5c2faefe9..6268813657b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Variable.Tests.ps1 @@ -194,13 +194,15 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException"{ New-Variable foo bar -Option Constant - $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e = { Remove-Variable foo -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } It "Remove-Variable ReadOnly variable should throw SessionStateUnauthorizedAccessException and force remove should work"{ New-Variable foo bar -Option ReadOnly - $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e = { Remove-Variable foo -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" Remove-Variable foo -Force $var1 = Get-Variable -Name foo -EA SilentlyContinue @@ -209,10 +211,12 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { It "Remove-Variable Constant variable should throw SessionStateUnauthorizedAccessException and force remove should also throw exception"{ New-Variable foo bar -Option Constant - $e = { Remove-Variable foo -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + $e = { Remove-Variable foo -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" - { Remove-Variable foo -Force -Scope 1 -EA Stop } | ShouldBeErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" + { Remove-Variable foo -Force -Scope 1 -EA Stop } | + Should -Throw -ErrorId "VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveVariableCommand" -PassThru $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException" } @@ -221,7 +225,8 @@ Describe "Remove-Variable basic functionality" -Tags "CI" { &{ Clear-Variable foo Remove-Variable foo - $e = { Get-Variable -Name foo -Scope local -EA Stop } | ShouldBeErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" + $e = { Get-Variable -Name foo -Scope local -EA Stop } | + Should -Throw -ErrorId "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand" -PassThru $e.CategoryInfo | Should -Match "ItemNotFoundException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index e3095cb2129..b1d44da530f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -124,7 +124,8 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { } It "Select-Object with empty script block property should throw"{ - $e = { "bar" | select-object -Prop {} -EA Stop } | ShouldBeErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" + $e = { "bar" | select-object -Prop {} -EA Stop } | + Should -Throw -ErrorId "EmptyScriptBlockAndNoName,Microsoft.PowerShell.Commands.SelectObjectCommand" -PassThru $e.CategoryInfo | Should -Match "PSArgumentException" } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index 02902345794..7704bdefcf6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -75,13 +75,13 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.commands.clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke()| Should -BeExactly "test" + $ps.Invoke() | Should -BeExactly "test" $ps.commands.clear() $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value $null -TypeName System.String -Force') $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestNote") - $ps.Invoke()| Should -BeNullOrEmpty + $ps.Invoke() | Should -BeNullOrEmpty } It "Update-TypeData with Valid Dynamic Type AliasProperty with Force should work"{ @@ -90,12 +90,12 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Invoke() $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should -BeExactly "Int32" + $ps.Invoke() | Should -BeExactly "Int32" # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias") - $ps.Invoke()| Should -Be 6 + $ps.Invoke() | Should -Be 6 # setup $ps.Commands.Clear() @@ -105,12 +105,12 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias.GetType().Name") - $ps.Invoke()| Should -BeExactly "String" + $ps.Invoke() | Should -BeExactly "String" # test $ps.Commands.Clear() $null = $ps.AddScript("'string'.TestAlias") - $ps.Invoke()| Should -Be 6 + $ps.Invoke() | Should -Be 6 } It "Update-TypeData with Valid Dynamic Type ScriptMethod with Force should work"{ @@ -120,7 +120,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $null = $ps.AddScript('"string".TestScriptMethod()') - $ps.Invoke()| Should -BeExactly "script method" + $ps.Invoke() | Should -BeExactly "script method" $ps.Commands.Clear() $script2="new script method" $null = $ps.AddScript("Update-TypeData -MemberType ScriptMethod -MemberName TestScriptMethod -Value {'$script2'} -TypeName System.String -Force") @@ -151,28 +151,28 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid DynamicType Null Value For AliasProperty should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType AliasProperty -MemberName TestAlias -Value $null -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No MemberName should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -Value "Error" -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No Value should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -TypeName System.String') $ps.Invoke() - $ps.HadErrors |Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with Empty TypeData should throw Exception"{ $null = $ps.AddScript("Update-TypeData -TypeName System.String") $ps.Invoke() - $ps.HadErrors |Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } @@ -180,11 +180,11 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript('Update-TypeData -SerializationMethod string -StringSerializationSource Length -TargetTypeForDeserialization string -TypeName System.String') $ps.Invoke() $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -BeExactly "String" + $ps.Invoke() | Should -BeExactly "String" $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.StringSerializationSource') - $ps.Invoke()| Should -Be 6 + $ps.Invoke() | Should -Be 6 $ps.Commands.Clear(); $null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should -BeExactly "string" + $ps.Invoke() | Should -BeExactly "string" } It "Update-TypeData with Valid Standard Members Serialization Method SpecificProperties should work"{ @@ -204,41 +204,41 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $null = $ps.AddScript('Update-TypeData -SerializationMethod AllPublicProperties -StringSerializationSource Length -SerializationDepth 2 -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -BeExactly "AllPublicProperties" + $ps.Invoke() | Should -BeExactly "AllPublicProperties" $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.StringSerializationSource') - $ps.Invoke()| Should -Be 6 + $ps.Invoke() | Should -Be 6 $ps.Commands.Clear();$ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should -Be 2 + $ps.Invoke() | Should -Be 2 } It "Update-TypeData with Valid ISS UpdateType Command Test With DynamicType Set should work"{ $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName "TestNote" -Value "test the note" -SerializationMethod SpecificProperties -SerializationDepth 5 -PropertySerializationSet Length -DefaultDisplayPropertySet Length -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should -BeExactly "test the note" + $ps.Invoke() | Should -BeExactly "test the note" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -BeExactly "SpecificProperties" + $ps.Invoke() | Should -BeExactly "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should -Be 5 + $ps.Invoke() | Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -BeExactly "Length" + $ps.Invoke() | Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -BeExactly "Length" + $ps.Invoke() | Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value "test the note again" -TargetTypeForDeserialization string -Force -TypeName System.String') $ps.Invoke() $ps.Commands.Clear();$null = $ps.AddScript('"string".TestNote') - $ps.Invoke()| Should -BeExactly "test the note again" + $ps.Invoke() | Should -BeExactly "test the note again" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationMethod') - $ps.Invoke()| Should -BeExactly "SpecificProperties" + $ps.Invoke() | Should -BeExactly "SpecificProperties" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.SerializationDepth') - $ps.Invoke()| Should -Be 5 + $ps.Invoke() | Should -Be 5 $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.PropertySerializationSet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -BeExactly "Length" + $ps.Invoke() | Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames[0]') - $ps.Invoke()| Should -BeExactly "Length" + $ps.Invoke() | Should -BeExactly "Length" $ps.Commands.Clear();$null = $ps.AddScript('"string".PSStandardMembers.TargetTypeForDeserialization') - $ps.Invoke()| Should -BeExactly "string" + $ps.Invoke() | Should -BeExactly "string" } It "Update-TypeData with Valid ISS UpdateType Command Test With StrongType Set should work"{ @@ -314,7 +314,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { $ps.Commands.Clear() $ps.AddScript('$a.Yada').Invoke() | Should -Be 3 $ps.AddScript("Remove-TypeData -Path $testfile").Invoke() - $ps.HadErrors|Should -BeFalse + $ps.HadErrors | Should -BeFalse } } } From 89f2573c444a276025c5ed4234db6b27345b7121 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Tue, 20 Mar 2018 11:53:02 -0700 Subject: [PATCH 20/21] [Feature] Tests in Utility module correction. --- .../Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 index 7704bdefcf6..74ae2a513b3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-TypeData.Tests.ps1 @@ -151,14 +151,14 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid DynamicType Null Value For AliasProperty should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType AliasProperty -MemberName TestAlias -Value $null -TypeName System.String') $ps.Invoke() - $ps.HadErrors | Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "ValueShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } It "Update-TypeData with Invalid DynamicType with No MemberName should throw Exception"{ $null = $ps.AddScript('Update-TypeData -MemberType NoteProperty -Value "Error" -TypeName System.String') $ps.Invoke() - $ps.HadErrors | Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "MemberNameShouldBeSpecified,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } @@ -172,7 +172,7 @@ Describe "Update-TypeData basic functionality" -Tags "CI" { It "Update-TypeData with Invalid DynamicType with Empty TypeData should throw Exception"{ $null = $ps.AddScript("Update-TypeData -TypeName System.String") $ps.Invoke() - $ps.HadErrors | Should -BeTrue + $ps.HadErrors | Should -BeTrue $ps.Streams.Error[0].FullyQualifiedErrorId | Should -BeExactly "TypeDataEmpty,Microsoft.PowerShell.Commands.UpdateTypeDataCommand" } From 9890acdde0a8897313238d58647f9690de69c378 Mon Sep 17 00:00:00 2001 From: kalgiz Date: Tue, 20 Mar 2018 15:22:47 -0700 Subject: [PATCH 21/21] [Feature] Tests correction. --- .../Microsoft.PowerShell.Utility/Format-List.Tests.ps1 | 2 +- .../Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 index 78563a680ec..ff348869332 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Format-List" -Tags "CI" { It "Should be able to call a property of the piped input" { # Tested on two input commands to verify functionality. - Get-Command | Select-Object -First 5 | Format-List -Property Name | Should -Not -BeNullOrEmpty + Get-Command | Select-Object -First 1 | Format-List -Property Name | Should -Not -BeNullOrEmpty Get-Date | Format-List -Property DisplayName | Should -Not -BeNullOrEmpty } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 index 21ece0a7db8..1315588dfb6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1 @@ -29,8 +29,11 @@ Describe "Get-Uptime" -Tags "CI" { # Enable the test hook [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true) - { Get-Uptime } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" - # Disable the test hook - [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false) + try { + { Get-Uptime } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand" + } finally { + # Disable the test hook + [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false) + } } }