diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Add-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Add-Content.Tests.ps1 index 4452da3b5bb..880c6d3f9ff 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Add-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Add-Content.Tests.ps1 @@ -7,46 +7,43 @@ Describe "Add-Content cmdlet tests" -Tags "CI" { Context "Add-Content should actually add content" { It "should Add-Content to testdrive:\$file1" { $result=add-content -path testdrive:\$file1 -value "ExpectedContent" -passthru - $result| Should be "ExpectedContent" + $result| Should -BeExactly "ExpectedContent" } It "should return expected string from testdrive:\$file1" { $result = get-content -path testdrive:\$file1 - $result | Should BeExactly "ExpectedContent" + $result | Should -BeExactly "ExpectedContent" } It "should Add-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsMacOS) {#https://github.com/PowerShell/PowerShell/issues/891 $result=add-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru - $result| Should BeExactly "ExpectedContent" + $result| Should -BeExactly "ExpectedContent" } It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsMacOS) {#https://github.com/PowerShell/PowerShell/issues/891 $result = get-content -path testdrive:\dynamicfile.txt - $result | Should BeExactly "ExpectedContent" + $result | Should -BeExactly "ExpectedContent" } It "should Add-Content to testdrive:\$file1 even when -Value is `$null" { $AsItWas=get-content testdrive:\$file1 - {add-content -path testdrive:\$file1 -value $null -ea stop} | Should Not Throw - get-content testdrive:\$file1 | Should BeExactly $AsItWas + {add-content -path testdrive:\$file1 -value $null -ErrorAction Stop} | Should -Not -Throw + get-content testdrive:\$file1 | Should -BeExactly $AsItWas } It "should throw 'ParameterArgumentValidationErrorNullNotAllowed' when -Path is `$null" { - Try {add-content -path $null -value "ShouldNotWorkBecausePathIsNull" -ea stop; Throw "Previous statement unexpectedly succeeded..." - } Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"} + { Add-Content -Path $null -Value "ShouldNotWorkBecausePathIsNull" -ErrorAction Stop } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand" } #[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)] It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" { - Try {add-content -path $() -value "ShouldNotWorkBecausePathIsInvalid" -ea stop; Throw "Previous statement unexpectedly succeeded..." - } Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"} + { Add-Content -Path $() -Value "ShouldNotWorkBecausePathIsInvalid" -ErrorAction Stop } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand" } #[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)] It "should throw 'NotSupportedException' when you add-content to an unsupported provider" -Skip:($IsLinux -Or $IsMacOS) { - Try {add-content -path HKLM:\\software\\microsoft -value "ShouldNotWorkBecausePathIsUnsupported" -ea stop; Throw "Previous statement unexpectedly succeeded..." - } Catch {$_.FullyQualifiedErrorId | Should Be "NotSupported,Microsoft.PowerShell.Commands.AddContentCommand"} + { Add-Content -Path HKLM:\\software\\microsoft -Value "ShouldNotWorkBecausePathIsUnsupported" -ErrorAction Stop } | Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.AddContentCommand" } #[BugId(BugDatabase.WindowsOutOfBandReleases, 9058182)] It "should be able to pass multiple [string]`$objects to Add-Content through the pipeline to output a dynamic Path file" -Pending:($IsLinux -Or $IsMacOS) {#https://github.com/PowerShell/PowerShell/issues/891 "hello","world"|add-content testdrive:\dynamicfile2.txt $result=get-content testdrive:\dynamicfile2.txt - $result.length |Should be 2 - $result[0] |Should be "hello" - $result[1] |Should be "world" + $result.length | Should -Be 2 + $result[0] | Should -BeExactly "hello" + $result[1] | Should -BeExactly "world" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Alias.Tests.ps1 index 2c313a053bd..f3061acc7f8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Alias.Tests.ps1 @@ -16,22 +16,22 @@ Describe "Basic Alias Provider Tests" -Tags "CI" { It "Test number of alias not Zero" { $aliases = @(Get-ChildItem "Alias:\") - $aliases.Count | Should Not Be 0 + $aliases.Count | Should -Not -Be 0 } It "Test alias dir" { $dirAlias = Get-Item "Alias:\dir" - $dirAlias.CommandType | Should Be "Alias" - $dirAlias.Name | Should Be "dir" - $dirAlias.Definition | Should Be "Get-ChildItem" + $dirAlias.CommandType | Should -BeExactly "Alias" + $dirAlias.Name | Should -BeExactly "dir" + $dirAlias.Definition | Should -BeExactly "Get-ChildItem" } It "Test creating new alias" { try { $newAlias = New-Item -Path "Alias:\" -Name "NewTestAlias" -Value $testAliasValue - $newAlias.CommandType | Should Be "Alias" - $newAlias.Name | Should Be "NewTestAlias" - $newAlias.Definition | Should Be $testAliasValue + $newAlias.CommandType | Should -BeExactly "Alias" + $newAlias.Name | Should -BeExactly "NewTestAlias" + $newAlias.Definition | Should -BeExactly $testAliasValue } finally { Remove-Item -Path "Alias:\NewTestAlias" -Force -ErrorAction SilentlyContinue @@ -40,19 +40,19 @@ Describe "Basic Alias Provider Tests" -Tags "CI" { It "Test Get-Item on alias provider" { $alias = Get-Item -Path "Alias:\${testAliasName}" - $alias.CommandType | Should Be "Alias" - $alias.Name | Should Be $testAliasName - $alias.Definition | Should Be $testAliasValue + $alias.CommandType | Should -BeExactly "Alias" + $alias.Name | Should -BeExactly $testAliasName + $alias.Definition | Should -BeExactly $testAliasValue } It "Test Test-Path on alias provider" { $aliasExists = Test-Path "Alias:\testAlias" - $aliasExists | Should Be $true + $aliasExists | Should -BeTrue } It "Test executing the new alias" { $result = Invoke-Expression $testAliasName - $result | Should BeOfType DateTime + $result | Should -BeOfType [DateTime] } } @@ -78,35 +78,35 @@ Describe "Extended Alias Provider Tests" -Tags "Feature" { $before = (Get-Item -Path "Alias:\${testAliasName}").Definition Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Whatif $after = (Get-Item -Path "Alias:\${testAliasName}").Definition - $after | Should Be $before # Definition should not have changed + $after | Should -BeExactly $before # Definition should not have changed } It "Verifying Confirm can be bypassed" { Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Confirm:$false $result = Get-Item -Path "Alias:\${testAliasName}" - $result.Definition | Should Be "Get-Location" + $result.Definition | Should -BeExactly "Get-Location" } It "Verifying Force" { Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Force $result = Get-Item -Path "Alias:\${testAliasName}" - $result.Definition | Should Be "Get-Location" + $result.Definition | Should -BeExactly "Get-Location" } It "Verifying Include" { Set-Item -Path "Alias:\*" -Value "Get-Location" -Include "TestAlias*" $alias1 = Get-Item -Path "Alias:\${testAliasName}" $alias2 = Get-Item -Path "Alias:\${testAliasName2}" - $alias1.Definition | Should Be "Get-Location" - $alias2.Definition | Should Be "Get-Location" + $alias1.Definition | Should -BeExactly "Get-Location" + $alias2.Definition | Should -BeExactly "Get-Location" } It "Verifying Exclude" { Set-Item -Path "Alias:\TestAlias*" -Value "Get-Location" -Exclude "*2" $alias1 = Get-Item -Path "Alias:\${testAliasName}" $alias2 = Get-Item -Path "Alias:\${testAliasName2}" - $alias1.Definition | Should Be "Get-Location" - $alias2.Definition | Should Be "Get-Date" + $alias1.Definition | Should -BeExactly "Get-Location" + $alias2.Definition | Should -BeExactly "Get-Date" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Content.Tests.ps1 index 3eb9fd66f26..4d93f457241 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Content.Tests.ps1 @@ -55,41 +55,41 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" { Context "Clear-Content should actually clear content" { It "should clear-Content of testdrive:\$file1" { - set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should be "ExpectedContent" + set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should -BeExactly "ExpectedContent" clear-content -Path testdrive:\$file1 } It "shouldn't get any content from testdrive:\$file1" { $result = get-content -path testdrive:\$file1 - $result | Should BeExactly $null + $result | Should -BeNullOrEmpty } # we could suppress the WhatIf output here if we use the testhost, but it's not necessary It "The filesystem provider supports should process" -skip:(!$IsWindows) { clear-content TESTDRIVE:\$file2 -WhatIf - "TESTDRIVE:\$file2" | should FileContentMatch "This is content" + "TESTDRIVE:\$file2" | Should -FileContentMatch "This is content" } It "The filesystem provider should support ShouldProcess (reference ProviderSupportsShouldProcess member)" { $cci = ((get-command clear-content).ImplementingType)::new() - $cci.SupportsShouldProcess | should be $true + $cci.SupportsShouldProcess | Should -BeTrue } It "Alternate streams should be cleared with clear-content" -skip:(!$IsWindows) { # make sure that the content is correct # this is here rather than BeforeAll because only windows can write to an alternate stream set-content -path "TESTDRIVE:/$file3" -stream $streamName -value $streamContent - get-content -path "TESTDRIVE:/$file3" | Should be $content2 - get-content -Path "TESTDRIVE:/$file3" -stream $streamName | should be $streamContent + get-content -path "TESTDRIVE:/$file3" | Should -BeExactly $content2 + get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeExactly $streamContent clear-content -PATH "TESTDRIVE:/$file3" -stream $streamName - get-content -Path "TESTDRIVE:/$file3" | should be $content2 - get-content -Path "TESTDRIVE:/$file3" -stream $streamName | should BeNullOrEmpty + get-content -Path "TESTDRIVE:/$file3" | Should -BeExactly $content2 + get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeNullOrEmpty } It "the '-Stream' dynamic parameter is visible to get-command in the filesystem" -Skip:(!$IsWindows) { try { push-location TESTDRIVE: - (get-command clear-content -stream foo).parameters.keys -eq "stream" | should be "stream" + (get-command clear-content -stream foo).parameters.keys -eq "stream" | Should -Be "stream" } finally { pop-location @@ -103,7 +103,7 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" { throw "ExpectedExceptionNotDelivered" } catch { - $_.FullyQualifiedErrorId | should be "NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand" + $_.FullyQualifiedErrorId | Should -Be "NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand" } finally { pop-location @@ -114,21 +114,21 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" { Context "Proper errors should be delivered when bad locations are specified" { It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" { try { - clear-content -path $null -ea stop + clear-content -path $null -ErrorAction Stop throw "expected exception was not delivered" } catch { - $_.FullyQualifiedErrorId | should be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand" } } #[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)] It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" { try { - clear-content -path $() -ea stop + clear-content -path $() -ErrorAction Stop throw "expected exception was not delivered" } catch { - $_.FullyQualifiedErrorId | should be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand" } } #[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)] @@ -136,42 +136,42 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" { $functionName = Get-NonExistantFunctionName $null = new-item function:$functionName -Value { 1 } try { - clear-content -path function:$functionName -ea Stop + clear-content -path function:$functionName -ErrorAction Stop throw "Expected exception was not thrown" } catch { - $_.FullyQualifiedErrorId | should be "NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand" } } It "should throw FileNotFound error when referencing a non-existant file" { try { $badFile = "TESTDRIVE:/badfilename.txt" - clear-content -path $badFile -ea Stop + clear-content -path $badFile -ErrorAction Stop throw "ExpectedExceptionNotDelivered" } catch { - $_.FullyQualifiedErrorId | should be "PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" } } It "should throw DriveNotFound error when referencing a non-existant drive" { try { $badDrive = "{0}:/file.txt" -f (Get-NonExistantDriveName) - clear-content -path $badDrive -ea Stop + clear-content -path $badDrive -ErrorAction Stop thow "ExpectedExceptionNotDelivered" } catch { - $_.FullyQualifiedErrorId | Should be "DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" } } # we'll use a provider qualified path to produce this error It "should throw ProviderNotFound error when referencing a non-existant provider" { try { $badProviderPath = "{0}::C:/file.txt" -f (Get-NonExistantProviderName) - clear-content -path $badProviderPath -ea Stop + clear-content -path $badProviderPath -ErrorAction Stop thow "ExpectedExceptionNotDelivered" } catch { - $_.FullyQualifiedErrorId | Should be "ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" + $_.FullyQualifiedErrorId | Should -Be "ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 index 86d649a6816..2cab4021103 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-EventLog.Tests.ps1 @@ -13,22 +13,20 @@ Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') { It "should be able to Clear-EventLog" -Pending:($True) { Remove-EventLog -LogName TestLog -ea Ignore - {New-EventLog -LogName TestLog -Source TestSource -ea Stop} | Should Not Throw - {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop } | Should Not Throw - {$result=Get-EventLog -LogName TestLog} | Should Not Throw - ($result.Count) | Should be 1 - {Clear-EventLog -LogName TestLog} | Should Not Throw + {New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop} | Should -Not -Throw + {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Not -Throw + {$result=Get-EventLog -LogName TestLog} | Should -Not -Throw + ($result.Count) | Should -Be 1 + {Clear-EventLog -LogName TestLog} | Should -Not -Throw $result=Get-EventLog -LogName TestLog -ea Ignore - ($result.Count) | Should be 0 - {Remove-EventLog -LogName TestLog -ea Stop} | Should Not Throw + ($result.Count) | Should -Be 0 + {Remove-EventLog -LogName TestLog -ErrorAction Stop} | Should -Not -Throw } It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Pending:($True) { Remove-EventLog -LogName MissingTestLog -ea Ignore - try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..." - } catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.ClearEventLogCommand"} + { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand" } It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True) { - try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..." - } catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.ClearEventLogCommand"} + { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Item.Tests.ps1 index 78924f81814..5bec6948ded 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Item.Tests.ps1 @@ -5,9 +5,9 @@ Describe "Clear-Item tests" -Tag "CI" { ${myClearItemVariableTest} = "Value is here" } It "Clear-Item can clear an item" { - $myClearItemVariableTest | Should be "Value is here" + $myClearItemVariableTest | Should -BeExactly "Value is here" Clear-Item variable:myClearItemVariableTest - test-path variable:myClearItemVariableTest | should be $true - $myClearItemVariableTest | Should BeNullOrEmpty + test-path variable:myClearItemVariableTest | Should -BeTrue + $myClearItemVariableTest | Should -BeNullOrEmpty } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/ControlService.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/ControlService.Tests.ps1 index 8bd2ee56bd0..48864dfec82 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/ControlService.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/ControlService.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Control Service cmdlet tests" -Tags "Feature","RequireAdminOnWindows" param($parameter, $value) $stopservicecmd = [Microsoft.PowerShell.Commands.StopServiceCommand]::new() $stopservicecmd.$parameter = $value - $stopservicecmd.$parameter | Should Be $value + $stopservicecmd.$parameter | Should -Be $value } It "RestartServiceCommand can be used as API for '' with ''" -TestCases @( @@ -30,30 +30,30 @@ Describe "Control Service cmdlet tests" -Tags "Feature","RequireAdminOnWindows" param($parameter, $value) $restartservicecmd = [Microsoft.PowerShell.Commands.RestartServiceCommand]::new() $restartservicecmd.$parameter = $value - $restartservicecmd.$parameter | Should Be $value + $restartservicecmd.$parameter | Should -Be $value } It "Stop/Start/Restart-Service works" { $wasStopped = $false try { $spooler = Get-Service Spooler - $spooler | Should Not BeNullOrEmpty + $spooler | Should -Not -BeNullOrEmpty if ($spooler.Status -ne "Running") { $wasStopped = $true $spooler = Start-Service Spooler -PassThru } - $spooler.Status | Should Be "Running" + $spooler.Status | Should -BeExactly "Running" $spooler = Stop-Service Spooler -PassThru - $spooler.Status | Should Be "Stopped" - (Get-Service Spooler).Status | Should Be "Stopped" + $spooler.Status | Should -BeExactly "Stopped" + (Get-Service Spooler).Status | Should -BeExactly "Stopped" $spooler = Start-Service Spooler -PassThru - $spooler.Status | Should Be "Running" - (Get-Service Spooler).Status | Should Be "Running" + $spooler.Status | Should -BeExactly "Running" + (Get-Service Spooler).Status | Should -BeExactly "Running" Stop-Service Spooler - (Get-Service Spooler).Status | Should Be "Stopped" + (Get-Service Spooler).Status | Should -BeExactly "Stopped" $spooler = Restart-Service Spooler -PassThru - $spooler.Status | Should Be "Running" - (Get-Service Spooler).Status | Should Be "Running" + $spooler.Status | Should -BeExactly "Running" + (Get-Service Spooler).Status | Should -BeExactly "Running" } finally { if ($wasStopped) { Stop-Service Spooler @@ -70,11 +70,11 @@ Describe "Control Service cmdlet tests" -Tags "Feature","RequireAdminOnWindows" $originalState = $service.Status Start-Service $serviceName } - $service | Should Not BeNullOrEmpty + $service | Should -Not -BeNullOrEmpty Suspend-Service $serviceName - (Get-Service $serviceName).Status | Should Be "Paused" + (Get-Service $serviceName).Status | Should -BeExactly "Paused" Resume-Service $serviceName - (Get-Service $serviceName).Status | Should Be "Running" + (Get-Service $serviceName).Status | Should -BeExactly "Running" } finally { Set-Service $serviceName -Status $originalState } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Convert-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Convert-Path.Tests.ps1 index e376153aec7..f6358ee89ec 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Convert-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Convert-Path.Tests.ps1 @@ -2,53 +2,35 @@ # Licensed under the MIT License. Describe "Convert-Path tests" -Tag CI { It "Convert-Path should handle provider qualified paths" { - Convert-Path "FileSystem::${TESTDRIVE}" | should be "${TESTDRIVE}" + Convert-Path "FileSystem::${TESTDRIVE}" | Should -BeExactly "${TESTDRIVE}" } It "Convert-Path should return the proper path" { - Convert-Path "$TESTDRIVE" | Should be "$TESTDRIVE" + Convert-Path "$TESTDRIVE" | Should -BeExactly "$TESTDRIVE" } It "Convert-Path supports pipelined input" { - "$TESTDRIVE" | Convert-Path | Should be "$TESTDRIVE" + "$TESTDRIVE" | Convert-Path | Should -BeExactly "$TESTDRIVE" } It "Convert-Path supports pipelined input by property name" { - get-item $TESTDRIVE | Convert-Path | Should be "$TESTDRIVE" + get-item $TESTDRIVE | Convert-Path | Should -BeExactly "$TESTDRIVE" } It "Convert-Path without arguments is an error" { - try { - $ps = [powershell]::Create() - $ps.AddCommand("Convert-Path").Invoke() - throw "Execution should not have reached here" - } - catch { - $_.fullyqualifiederrorid | should be ParameterBindingException - } + $ps = [powershell]::Create() + { $ps.AddCommand("Convert-Path").Invoke() } | Should -Throw -ErrorId "ParameterBindingException" } It "Convert-Path with null path is an error" { - try { - Convert-Path -path "" - throw "Execution should not have reached here" - } - catch { - $_.fullyqualifiederrorid | should be "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.ConvertPathCommand" - } + { Convert-Path -path "" } | Should -Throw -ErrorId "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.ConvertPathCommand" } It "Convert-Path with non-existing non-filesystem path is an error" { - try { - Convert-Path -path "env:thisvariableshouldnotexist" -ea stop - throw "Execution should not have reached here" - } - catch { - $_.fullyqualifiederrorid | should be "PathNotFound,Microsoft.PowerShell.Commands.ConvertPathCommand" - } + { Convert-Path -path "env:thisvariableshouldnotexist" -ErrorAction Stop } | Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ConvertPathCommand" } It "Convert-Path can handle multiple directories" { $d1 = Setup -D dir1 -pass $d2 = Setup -D dir2 -pass $result = convert-path "${TESTDRIVE}/dir?" - $result.count | Should be 2 - $result -join "," | should be (@("$d1","$d2") -join ",") + $result.count | Should -Be 2 + $result -join "," | Should -BeExactly (@("$d1","$d2") -join ",") } It "Convert-Path should return something which exists" { - Convert-Path $TESTDRIVE | Test-Path | should be $true + Convert-Path $TESTDRIVE | Should -Exist } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 index 0cae3cd1e29..febcbaaf8f3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 @@ -36,21 +36,21 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { $copiedFilePath = Join-Path $destination $fileName } - $copiedFilePath | should Exist + $copiedFilePath | Should -Exist # Validate file attributes $originalFile = Get-Item $filePath -Force $newFile = Get-Item $copiedFilePath -Force # Validate file Length - $newFile.Length | should be $originalFile.Length + $newFile.Length | Should -Be $originalFile.Length # Validate LastWriteTime - $newFile.LastWriteTime | should be $originalFile.LastWriteTime - $newFile.LastWriteTimeUtc | should be $originalFile.LastWriteTimeUtc + $newFile.LastWriteTime | Should -Be $originalFile.LastWriteTime + $newFile.LastWriteTimeUtc | Should -Be $originalFile.LastWriteTimeUtc # Validate Attributes - $newFile.Attributes.value__ | Should Be $originalFile.Attributes.value__ + $newFile.Attributes.value__ | Should -Be $originalFile.Attributes.value__ } # Validate a copy item operation. @@ -61,12 +61,12 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { param ([string]$filePath, $streamName, $expectedStreamContent) $copiedFilePath = ([string]$filePath).Replace("SourceDirectory", "DestinationDirectory") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $filePath).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $filePath).Length # Validate the stream $actualStreamContent = Get-Content -Path $copiedFilePath -Stream $streamName -ea SilentlyContinue - $actualStreamContent | Should Match $expectedStreamContent + $actualStreamContent | Should -Match $expectedStreamContent } BeforeAll { @@ -258,7 +258,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\SourceDirectory") - $copiedFilePath | should Exist + $copiedFilePath | Should -Exist } } } @@ -297,8 +297,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\SourceDirectory") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -310,8 +310,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\SourceDirectory") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -329,7 +329,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | should be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId } } @@ -342,8 +342,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\FoderThatDoesNotExist") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -352,10 +352,10 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { $filePath = CreateTestFile -emptyFile $destinationFolderPath = GetDestinationFolderPath $copiedFilePath = ([string]$filePath).Replace("SourceDirectory", "DestinationDirectory") - $copiedFilePath | should Not Exist + $copiedFilePath | Should -Not -Exist Copy-Item -Path $filePath -ToSession $s -Destination $destinationFolderPath - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $filePath).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $filePath).Length } It "Copy-Item to session supports alternate data streams." { @@ -377,7 +377,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { $filePath = CreateTestFile $destinationFolderPath = GetDestinationFolderPath $copiedFilePath = ([string]$filePath).Replace("SourceDirectory", "DestinationDirectory") - $copiedFilePath | should Not Exist + $copiedFilePath | Should -Not -Exist Copy-Item -Path $filePath -FromSession $s -Destination $destinationFolderPath ValidateCopyItemOperation -filePath $filePath } @@ -387,7 +387,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { $filePath = CreateTestFile -emptyFile $destinationFolderPath = GetDestinationFolderPath $copiedFilePath = ([string]$filePath).Replace("SourceDirectory", "DestinationDirectory") - $copiedFilePath | should Not Exist + $copiedFilePath | Should -Not -Exist Copy-Item -Path $filePath -FromSession $s -Destination $destinationFolderPath ValidateCopyItemOperation -filePath $filePath } @@ -402,8 +402,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\SourceDirectory") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -420,7 +420,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | should be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId } } @@ -435,8 +435,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $testObject.Files) { $copiedFilePath = ([string]$file).Replace("SourceDirectory", "DestinationDirectory\FoderThatDoesNotExist") - $copiedFilePath | should Exist - (Get-Item $copiedFilePath).Length | should be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -524,8 +524,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $sourceFiles) { $copiedFilePath = Join-Path $destinationFolderPath (Split-Path $file -Leaf) - $copiedFilePath | Should Exist - (Get-Item $copiedFilePath).Length | Should Be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } @@ -540,8 +540,8 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { foreach ($file in $sourceFiles) { $copiedFilePath = Join-Path $destinationFolderPath (Split-Path $file -Leaf) - $copiedFilePath | Should Exist - (Get-Item $copiedFilePath).Length | Should Be (Get-Item $file).Length + $copiedFilePath | Should -Exist + (Get-Item $copiedFilePath).Length | Should -Be (Get-Item $file).Length } } } @@ -572,7 +572,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | should be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId } } } @@ -586,7 +586,7 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" { } catch { - $_.FullyQualifiedErrorId | should be $expectedFullyQualifiedErrorId + $_.FullyQualifiedErrorId | Should -Be $expectedFullyQualifiedErrorId } } } @@ -707,7 +707,7 @@ Describe "Validate Copy-Item error for target sessions not in FullLanguageMode." $testSession = New-PSSession -ConfigurationName $sessionName # Validate that the session is opened. - $testSession.State | Should Be "Opened" + $testSession.State | Should -Be "Opened" # Add the new session to the list. $testSessions[$languageMode] = $testSession @@ -735,23 +735,23 @@ Describe "Validate Copy-Item error for target sessions not in FullLanguageMode." # FromSession try { - Copy-Item -Path $testFilePath -FromSession $session -Destination $destination -Force -Verbose -ea Stop + Copy-Item -Path $testFilePath -FromSession $session -Destination $destination -Force -Verbose -ErrorAction Stop throw "CodeExecuted" } catch { - $_.FullyQualifiedErrorId | should be "SessionIsNotInFullLanguageMode,Microsoft.PowerShell.Commands.CopyItemCommand" + $_.FullyQualifiedErrorId | Should -Be "SessionIsNotInFullLanguageMode,Microsoft.PowerShell.Commands.CopyItemCommand" } # ToSession try { - Copy-Item -Path $testFilePath -ToSession $session -Destination $destination -Force -Verbose -ea Stop + Copy-Item -Path $testFilePath -ToSession $session -Destination $destination -Force -Verbose -ErrorAction Stop throw "CodeExecuted" } catch { - $_.FullyQualifiedErrorId | should be "SessionIsNotInFullLanguageMode,Microsoft.PowerShell.Commands.CopyItemCommand" + $_.FullyQualifiedErrorId | Should -Be "SessionIsNotInFullLanguageMode,Microsoft.PowerShell.Commands.CopyItemCommand" } } } @@ -781,19 +781,19 @@ Describe "Copy-Item can use Recurse and Exclude together" -Tags "Feature" { It "can exclude files at sub directory" { Copy-Item -Path TestDrive:\Parent\* -Recurse -Exclude s*.txt -Destination TestDrive:\Temp -Force $copiedFiles = Get-ChildItem -Recurse -Path TestDrive:\Temp - $copiedFiles.Count | Should Be 3 + $copiedFiles.Count | Should -Be 3 } It "can exclude files at sub directory to a session" { Copy-Item -Path TestDrive:\Parent\* -Recurse -Exclude s*.txt -Destination $TestDrive\Temp2 -Force -ToSession $s $copiedFiles = Get-ChildItem -Recurse -Path TestDrive:\Temp - $copiedFiles.Count | Should Be 3 + $copiedFiles.Count | Should -Be 3 } It "can exclude files at sub directory from a session" { Copy-Item -Path $TestDrive\Parent\* -Recurse -Exclude s*.txt -Destination TestDrive:\Temp3 -FromSession $s $copiedFiles = Get-ChildItem -Recurse -Path TestDrive:\Temp2 - $copiedFiles.Count | Should Be 3 + $copiedFiles.Count | Should -Be 3 } AfterAll { @@ -844,7 +844,7 @@ Describe "Copy-Item remotely bug fixes" -Tags "Feature" { # Validate the the file was overwritten $fileContent = Get-Content "TestDrive:\Destination\testFile1.txt" -ea SilentlyContinue -Raw - $fileContent | Should Match $newContent + $fileContent | Should -Match $newContent } It "Copy item -fromsession overwrites the content of an existing file." { @@ -854,7 +854,7 @@ Describe "Copy-Item remotely bug fixes" -Tags "Feature" { # Validate the the file was overwritten $fileContent = Get-Content "TestDrive:\Destination\testFile1.txt" -ea SilentlyContinue -Raw - $fileContent | Should Match $newContent + $fileContent | Should -Match $newContent } } @@ -869,7 +869,7 @@ Describe "Copy-Item remotely bug fixes" -Tags "Feature" { $null = New-Item -ItemType Directory -Path "TestDrive:\AnotherDestination" # Ensure the file does not exist - "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should Not Exist + "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should -Not -Exist } It "Copy-Item -tosession creates the file if it does not exist on the remote destination." { @@ -878,7 +878,7 @@ Describe "Copy-Item remotely bug fixes" -Tags "Feature" { Copy-Item -Path "TestDrive:\Source\testFile1.txt" -Destination "$TestDrive\AnotherDestination\FileThatDoesNotExist.txt" -ToSession $s # Verify that the file was created - "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should Exist + "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should -Exist } It "Copy-Item -fromsession creates the file if it does not exist on the local machine." { @@ -887,7 +887,7 @@ Describe "Copy-Item remotely bug fixes" -Tags "Feature" { Copy-Item -Path "$TestDrive\Source\testFile1.txt" -Destination "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" -FromSession $s # Verify that the file was created - "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should Exist + "TestDrive:\AnotherDestination\FileThatDoesNotExist.txt" | Should -Exist } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index 5aad92b50e3..25ba4b5fd00 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -40,62 +40,61 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { It "Verify New-Item for directory" { $newDir = New-Item -Path $newTestDir -ItemType Directory $directoryExists = Test-Path $newTestDir - $directoryExists | Should Be $true - $newDir.Name | Should Be $newTestDir + $directoryExists | Should -BeTrue + $newDir.Name | Should -BeExactly $newTestDir } It "Verify New-Item for file" { $newFile = New-Item -Path $newTestFile -ItemType File - $fileExists = Test-Path $newTestFile - $fileExists | Should Be $true - $newFile.Name | Should Be $newTestFile + $newTestFile | Should -Exist + $newFile.Name | Should -BeExactly $newTestFile } It "Verify Remove-Item for directory" { $existsBefore = Test-Path $testDir Remove-Item -Path $testDir -Recurse -Force $existsAfter = Test-Path $testDir - $existsBefore | Should Be $true - $existsAfter | Should Be $false + $existsBefore | Should -BeTrue + $existsAfter | Should -BeFalse } It "Verify Remove-Item for file" { $existsBefore = Test-Path $testFile Remove-Item -Path $testFile -Force $existsAfter = Test-Path $testFile - $existsBefore | Should Be $true - $existsAfter | Should Be $false + $existsBefore | Should -BeTrue + $existsAfter | Should -BeFalse } It "Verify Rename-Item for file" { Rename-Item -Path $testFile -NewName $newTestFile -ErrorAction Stop - $testFile | Should Not Exist - $newTestFile | Should Exist + $testFile | Should -Not -Exist + $newTestFile | Should -Exist } It "Verify Rename-Item for directory" { Rename-Item -Path $testDir -NewName $newTestDir -ErrorAction Stop - $testDir | Should Not Exist - $newTestDir | Should Exist + $testDir | Should -Not -Exist + $newTestDir | Should -Exist } It "Verify Rename-Item will not rename to an existing name" { { Rename-Item -Path $testFile -NewName $testDir -ErrorAction Stop } | ShouldBeErrorId "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand" - $Error[0].Exception | Should BeOfType System.IO.IOException - $testFile | Should Exist + $Error[0].Exception | Should -BeOfType System.IO.IOException + $testFile | Should -Exist } It "Verify Copy-Item" { $newFile = Copy-Item -Path $testFile -Destination $newTestFile -PassThru $fileExists = Test-Path $newTestFile - $fileExists | Should Be $true - $newFile.Name | Should Be $newTestFile + $fileExists | Should -BeTrue + $newFile.Name | Should -BeExactly $newTestFile } It "Verify Move-Item for file" { Move-Item -Path $testFile -Destination $testDir -ErrorAction Stop - $testFile | Should Not Exist - "$testDir/$testFile" | Should Exist + $testFile | Should -Not -Exist + "$testDir/$testFile" | Should -Exist } It "Verify Move-Item for directory" { @@ -103,47 +102,47 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { New-Item -Path $destDir -ItemType Directory -ErrorAction Stop >$null Move-Item -Path $testFile -Destination $testDir Move-Item -Path $testDir -Destination $destDir - $testDir | Should Not Exist - "$destDir/$testDir" | Should Exist - "$destDir/$testDir/$testFile" | Should Exist + $testDir | Should -Not -Exist + "$destDir/$testDir" | Should -Exist + "$destDir/$testDir/$testFile" | Should -Exist } It "Verify Move-Item will not move to an existing file" { { Move-Item -Path $testDir -Destination $testFile -ErrorAction Stop } | ShouldBeErrorId "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand" - $Error[0].Exception | Should BeOfType System.IO.IOException - $testDir | Should Exist + $Error[0].Exception | Should -BeOfType System.IO.IOException + $testDir | Should -Exist } It "Verify Move-Item as substitute for Rename-Item" { $newFile = Move-Item -Path $testFile -Destination $newTestFile -PassThru $fileExists = Test-Path $newTestFile - $fileExists | Should Be $true - $newFile.Name | Should Be $newTestFile + $fileExists | Should -BeTrue + $newFile.Name | Should -Be $newTestFile } It "Verify Get-ChildItem" { $dirContents = Get-ChildItem "." - $dirContents.Count | Should Be 2 + $dirContents.Count | Should -Be 2 } It "Verify Get-ChildItem can get the name of a specified item." { $fileName = Get-ChildItem $testFile -Name $fileInfo = Get-ChildItem $testFile - $fileName | Should BeExactly $fileInfo.Name + $fileName | Should -BeExactly $fileInfo.Name } It "Set-Content to a file" { $content = Set-Content -Value $testContent -Path $testFile -PassThru - $content | Should BeExactly $testContent + $content | Should -BeExactly $testContent } It "Add-Content to a file" { $content = Set-Content -Value $testContent -Path $testFile -PassThru $addContent = Add-Content -Value $testContent2 -Path $testFile -PassThru $fullContent = Get-Content -Path $testFile - $content | Should Match $testContent - $addContent | Should Match $testContent2 - ($fullContent[0] + $fullContent[1]) | Should Match ($testContent + $testContent2) + $content | Should -Match $testContent + $addContent | Should -Match $testContent2 + ($fullContent[0] + $fullContent[1]) | Should -Match ($testContent + $testContent2) } It "Clear-Content of a file" { @@ -151,8 +150,8 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { $contentBefore = Get-Content -Path $testFile Clear-Content -Path $testFile $contentAfter = Get-Content -Path $testFile - $contentBefore.Count | Should Be 1 - $contentAfter.Count | Should Be 0 + $contentBefore.Count | Should -Be 1 + $contentAfter.Count | Should -Be 0 } It "Copy-Item on Windows rejects Windows reserved device names" -Skip:(-not $IsWindows) { @@ -180,7 +179,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { foreach ($deviceName in $reservedNames) { Copy-Item -Path $testFile -Destination $deviceName -Force -ErrorAction SilentlyContinue - Test-Path $deviceName | Should Be $true + Test-Path $deviceName | Should -BeTrue } } @@ -188,7 +187,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { foreach ($deviceName in $reservedNames) { Move-Item -Path $testFile -Destination $deviceName -Force -ErrorAction SilentlyContinue - Test-Path $deviceName | Should Be $true + Test-Path $deviceName | Should -BeTrue New-Item -Path $testFile -ItemType File -Force -ErrorAction SilentlyContinue } } @@ -197,7 +196,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { foreach ($deviceName in $reservedNames) { Rename-Item -Path $testFile -NewName $deviceName -Force -ErrorAction SilentlyContinue - Test-Path $deviceName | Should Be $true + Test-Path $deviceName | Should -BeTrue New-Item -Path $testFile -ItemType File -Force -ErrorAction SilentlyContinue } } @@ -212,7 +211,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { New-Item -Path "$testdrive$path" -ItemType Directory > $null Set-Location "$testdrive" Set-Location ".$path" - (Get-Location).Path | Should Be "$testdrive/$($path.Substring(1,$path.Length-1))" + (Get-Location).Path | Should -BeExactly "$testdrive/$($path.Substring(1,$path.Length-1))" } finally { Remove-Item -Path "$testdrive$path" -ErrorAction SilentlyContinue @@ -230,9 +229,9 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { New-Item -Path "$testPath" -ItemType Directory > $null Set-Content -Path "$testPath$path" -Value "Hello" $files = Get-ChildItem "$testPath" - $files.Count | Should Be 1 - $files[0].Name | Should BeExactly $path.Substring(1,$path.Length-1) - $files[0] | Get-Content | Should BeExactly "Hello" + $files.Count | Should -Be 1 + $files[0].Name | Should -BeExactly $path.Substring(1,$path.Length-1) + $files[0] | Get-Content | Should -BeExactly "Hello" } finally { Remove-Item -Path $testPath -Recurse -Force -ErrorAction SilentlyContinue @@ -275,7 +274,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { Wait-FileToBePresent -File $doneFile -TimeoutInSeconds 15 -IntervalInMilliseconds 100 $err = Get-Content $errFile - $err | Should Be $expectedError + $err | Should -Be $expectedError } } @@ -300,9 +299,9 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { $level1Loc = Get-Location Set-Location $level2_0 $level2Loc = Get-Location - $currentLoc.Path | Should Be $root - $level1Loc.Path | Should Be $level1_0Full - $level2Loc.Path | Should Be $level2_0Full + $currentLoc.Path | Should -BeExactly $root + $level1Loc.Path | Should -BeExactly $level1_0Full + $level2Loc.Path | Should -BeExactly $level2_0Full } It "Verify Push-Location and Pop-Location" { @@ -327,44 +326,44 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { Pop-Location $pop2 = Get-Location - $pop0.Path | Should Be $push2.Path - $pop1.Path | Should Be $push1.Path - $pop2.Path | Should Be $push0.Path + $pop0.Path | Should -BeExactly $push2.Path + $pop1.Path | Should -BeExactly $push1.Path + $pop2.Path | Should -BeExactly $push0.Path } } Context "Validate Basic Path Cmdlets" { It "Verify Convert-Path" { $result = Convert-Path "." - ($result.TrimEnd('/\')) | Should Be "$TESTDRIVE" + ($result.TrimEnd('/\')) | Should -BeExactly "$TESTDRIVE" } It "Verify Join-Path" { $result = Join-Path -Path "TestDrive:" -ChildPath "temp" if ($IsWindows) { - $result | Should BeExactly "TestDrive:\temp" + $result | Should -BeExactly "TestDrive:\temp" } else { - $result | Should BeExactly "TestDrive:/temp" + $result | Should -BeExactly "TestDrive:/temp" } } It "Verify Split-Path" { $testPath = Join-Path "TestDrive:" "MyTestFile.txt" $result = Split-Path $testPath -Qualifier - $result | Should BeExactly "TestDrive:" + $result | Should -BeExactly "TestDrive:" } It "Verify Test-Path" { $result = Test-Path $HOME - $result | Should Be $true + $result | Should -BeTrue } It "Verify HOME" { $homePath = $HOME $tildePath = (Resolve-Path -Path ~).Path - $homePath | Should Be $tildePath + $homePath | Should -BeExactly $tildePath } } } @@ -387,26 +386,26 @@ Describe "Handling of globbing patterns" -Tags "CI" { It "Rename-Item -LiteralPath can rename a file with Unix globbing characters" { Rename-Item -LiteralPath $file.FullName -NewName $newPath - Test-Path -LiteralPath $file.FullName | Should Be $false - Test-Path -LiteralPath $newPath | Should Be $true + Test-Path -LiteralPath $file.FullName | Should -BeFalse + Test-Path -LiteralPath $newPath | Should -BeTrue } It "Remove-Item -LiteralPath can delete a file with Unix globbing characters" { Remove-Item -LiteralPath $file.FullName - Test-Path -LiteralPath $file.FullName | Should Be $false + Test-Path -LiteralPath $file.FullName | Should -BeFalse } It "Move-Item -LiteralPath can move a file with Unix globbing characters" { $dir = New-Item -ItemType Directory -Path $dirPath Move-Item -LiteralPath $file.FullName -Destination $dir.FullName - Test-Path -LiteralPath $file.FullName | Should Be $false + Test-Path -LiteralPath $file.FullName | Should -BeFalse $newPath = Join-Path $dir.FullName $file.Name - Test-Path -LiteralPath $newPath | Should Be $true + Test-Path -LiteralPath $newPath | Should -BeTrue } It "Copy-Item -LiteralPath can copy a file with Unix globbing characters" { Copy-Item -LiteralPath $file.FullName -Destination $newPath - Test-Path -LiteralPath $newPath | Should Be $true + Test-Path -LiteralPath $newPath | Should -BeTrue } } @@ -420,12 +419,12 @@ Describe "Handling of globbing patterns" -Tags "CI" { $testPath2 = "$testdrive\foo*2" New-Item -Path $testPath -ItemType File New-Item -Path $testPath2 -ItemType File - Test-Path -LiteralPath $testPath | Should Be $true - Test-Path -LiteralPath $testPath2 | Should Be $true - { Remove-Item -LiteralPath $testPath } | Should Not Throw - Test-Path -LiteralPath $testPath | Should Be $false + Test-Path -LiteralPath $testPath | Should -BeTrue + Test-Path -LiteralPath $testPath2 | Should -BeTrue + { Remove-Item -LiteralPath $testPath } | Should -Not -Throw + Test-Path -LiteralPath $testPath | Should -BeFalse # make sure wildcard wasn't applied so this file should still exist - Test-Path -LiteralPath $testPath2 | Should Be $true + Test-Path -LiteralPath $testPath2 | Should -BeTrue } } } @@ -464,50 +463,50 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" Context "New-Item and hard/symbolic links" { It "New-Item can create a hard link to a file" { New-Item -ItemType HardLink -Path $hardLinkToFile -Value $realFile - Test-Path $hardLinkToFile | Should Be $true + Test-Path $hardLinkToFile | Should -BeTrue $link = Get-Item -Path $hardLinkToFile - $link.LinkType | Should BeExactly "HardLink" - Get-Content -Path $hardLinkToFile | Should be $fileContent + $link.LinkType | Should -BeExactly "HardLink" + Get-Content -Path $hardLinkToFile | Should -Be $fileContent } It "New-Item can create symbolic link to file" { New-Item -ItemType SymbolicLink -Path $symLinkToFile -Value $realFile - Test-Path $symLinkToFile | Should Be $true + Test-Path $symLinkToFile | Should -BeTrue $real = Get-Item -Path $realFile $link = Get-Item -Path $symLinkToFile - $link.LinkType | Should BeExactly "SymbolicLink" - $link.Target | Should Be $real.FullName - Get-Content -Path $symLinkToFile | Should be $fileContent + $link.LinkType | Should -BeExactly "SymbolicLink" + $link.Target | Should -Be $real.FullName + Get-Content -Path $symLinkToFile | Should -Be $fileContent } It "New-Item can create a symbolic link to nothing" { New-Item -ItemType SymbolicLink -Path $symLinkToNothing -Value $nonFile - Test-Path $symLinkToNothing | Should Be $true + Test-Path $symLinkToNothing | Should -BeTrue $link = Get-Item -Path $symLinkToNothing - $link.LinkType | Should BeExactly "SymbolicLink" - $link.Target | Should Be $nonFile + $link.LinkType | Should -BeExactly "SymbolicLink" + $link.Target | Should -Be $nonFile } It "New-Item emits an error when path to symbolic link already exists." { { New-Item -ItemType SymbolicLink -Path $realDir -Value $symLinkToDir -ErrorAction Stop } | ShouldBeErrorId "SymLinkExists,Microsoft.PowerShell.Commands.NewItemCommand" } It "New-Item can create a symbolic link to a directory" -Skip:($IsWindows) { New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $realDir - Test-Path $symLinkToDir | Should Be $true + Test-Path $symLinkToDir | Should -BeTrue $real = Get-Item -Path $realDir $link = Get-Item -Path $symLinkToDir - $link.LinkType | Should BeExactly "SymbolicLink" - $link.Target | Should Be $real.FullName + $link.LinkType | Should -BeExactly "SymbolicLink" + $link.Target | Should -Be $real.FullName } It "New-Item can create a directory symbolic link to a directory" -Skip:(-Not $IsWindows) { New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $realDir - Test-Path $symLinkToDir | Should Be $true + Test-Path $symLinkToDir | Should -BeTrue $real = Get-Item -Path $realDir $link = Get-Item -Path $symLinkToDir - $link | Should BeOfType System.IO.DirectoryInfo - $link.LinkType | Should BeExactly "SymbolicLink" - $link.Target | Should Be $real.FullName + $link | Should -BeOfType System.IO.DirectoryInfo + $link.LinkType | Should -BeExactly "SymbolicLink" + $link.Target | Should -BeExactly $real.FullName } It "New-Item can create a directory junction to a directory" -Skip:(-Not $IsWindows) { New-Item -ItemType Junction -Path $junctionToDir -Value $realDir - Test-Path $junctionToDir | Should Be $true + Test-Path $junctionToDir | Should -BeTrue } } @@ -521,8 +520,8 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" $omegaDir = Join-Path $TestDrive "sub-omega" $omegaFile1 = Join-Path $omegaDir "OmegaFile1" $omegaFile2 = Join-Path $omegaDir "OmegaFile2" - $betaDir = Join-Path $alphaDir "sub-beta" - $betaLink = Join-Path $alphaDir "link-beta" + $betaDir = Join-Path $alphaDir "sub-Beta" + $betaLink = Join-Path $alphaDir "link-Beta" $betaFile1 = Join-Path $betaDir "BetaFile1.txt" $betaFile2 = Join-Path $betaDir "BetaFile2.txt" $betaFile3 = Join-Path $betaDir "BetaFile3.txt" @@ -551,14 +550,14 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" $filenamePattern = "AlphaFile[12]\.txt" New-Item -ItemType SymbolicLink -Path $alphaLink -Value $alphaDir $ci = Get-ChildItem $alphaLink - $ci.Count | Should BeExactly 3 - $ci[1].Name | Should MatchExactly $filenamePattern - $ci[2].Name | Should MatchExactly $filenamePattern + $ci.Count | Should -Be 3 + $ci[1].Name | Should -MatchExactly $filenamePattern + $ci[2].Name | Should -MatchExactly $filenamePattern } It "Get-ChildItem does not recurse into symbolic links not explicitly given on the command line" { New-Item -ItemType SymbolicLink -Path $betaLink -Value $betaDir $ci = Get-ChildItem $alphaLink -Recurse - $ci.Count | Should BeExactly 7 + $ci.Count | Should -BeExactly 7 } It "Get-ChildItem will recurse into symlinks given -FollowSymlink, avoiding link loops" { New-Item -ItemType Directory -Path $gammaDir @@ -566,8 +565,8 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" New-Item -ItemType SymbolicLink -Path $uptwoLink -Value $alphaDir New-Item -ItemType SymbolicLink -Path $omegaLink -Value $omegaDir $ci = Get-ChildItem -Path $alphaDir -FollowSymlink -Recurse -WarningVariable w -WarningAction SilentlyContinue - $ci.Count | Should BeExactly 13 - $w.Count | Should BeExactly 3 + $ci.Count | Should -BeExactly 13 + $w.Count | Should -BeExactly 3 } } @@ -622,8 +621,8 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" ) Remove-Item -Path $Link -ErrorAction SilentlyContinue >$null - Test-Path -Path $Link | Should Be $false - Test-Path -Path $Target | Should Be $true + Test-Path -Path $Link | Should -BeFalse + Test-Path -Path $Target | Should -BeTrue } } @@ -667,9 +666,9 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" $childA = Get-Childitem $folder Remove-Item -Path $link -Recurse $childB = Get-ChildItem $folder - $childB.Count | Should Be 1 - $childB.Count | Should BeExactly $childA.Count - $childB.Name | Should BeExactly $childA.Name + $childB.Count | Should -Be 1 + $childB.Count | Should -BeExactly $childA.Count + $childB.Name | Should -BeExactly $childA.Name } } } @@ -728,14 +727,14 @@ Describe "Copy-Item can avoid copying an item onto itself" -Tags "CI", "RequireA It "Copy-Item can copy to file name differing only by case" { if ($isCaseSensitive) { - Copy-Item -Path $sourcePath -Destination $destinationPath -ErrorAction SilentlyContinue | Should Be $null - Test-Path -Path $destinationPath | Should Be $true + Copy-Item -Path $sourcePath -Destination $destinationPath -ErrorAction SilentlyContinue | Should -BeNullOrEmpty + Test-Path -Path $destinationPath | Should -BeTrue } else { { Copy-Item -Path $sourcePath -Destination $destinationPath -ErrorAction Stop } | ShouldBeErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand" - $Error[0].Exception | Should BeOfType System.IO.IOException - $Error[0].Exception.Data[$selfCopyKey] | Should Not Be $null + $Error[0].Exception | Should -BeOfType System.IO.IOException + $Error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty } } } @@ -797,8 +796,8 @@ Describe "Copy-Item can avoid copying an item onto itself" -Tags "CI", "RequireA ) { Copy-Item -Path $Source -Destination $Destination -ErrorAction Stop } | ShouldBeErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand" - $Error[0].Exception | Should BeOfType System.IO.IOException - $Error[0].Exception.Data[$selfCopyKey] | Should Not Be $null + $Error[0].Exception | Should -BeOfType System.IO.IOException + $Error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty } } @@ -844,24 +843,24 @@ Describe "Handling long paths" -Tags "CI" { It "Can remove a file via a long path" { Remove-Item -Path $longFilePath -ErrorVariable e -ErrorAction SilentlyContinue - $e | Should BeNullOrEmpty - $longFilePath | Should Not Exist + $e | Should -BeNullOrEmpty + $longFilePath | Should -Not -Exist } It "Can rename a file via a long path" { $newFileName = "new-file.txt" $newPath = Join-Path $longDirPath $newFileName Rename-Item -Path $longFilePath -NewName $newFileName - $longFilePath | Should Not Exist - $newPath | Should Exist + $longFilePath | Should -Not -Exist + $newPath | Should -Exist } It "Can change into a directory via a long path" { Set-Location -Path $longDirPath -ErrorVariable e -ErrorAction SilentlyContinue - $e | Should BeNullOrEmpty + $e | Should -BeNullOrEmpty $c = Get-Location - $fileName | Should Exist + $fileName | Should -Exist } It "Can use Test-Path to check for a file via a long path" { - Test-Path $longFilePath | Should Be $true + Test-Path $longFilePath | Should -BeTrue } } @@ -903,52 +902,52 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item -Path $testDir -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify Directory + Confirm bypass" { $result = New-Item -Path . -ItemType Directory -Name $testDir -Confirm:$false - $result.Name | Should Be $testDir + $result.Name | Should -BeExactly $testDir } It "Verify Directory + Force" { New-Item -Path . -ItemType Directory -Name $testDir > $null $result = New-Item -Path . -ItemType Directory -Name $testDir -Force #would normally fail without force - $result.Name | Should Be $testDir + $result.Name | Should -BeExactly $testDir } It "Verify File + Value" { $result = New-Item -Path . -ItemType File -Name $testFile -Value "Some String" $content = Get-Content -Path $testFile - $result.Name | Should Be $testFile - $content | Should Be "Some String" + $result.Name | Should -BeExactly $testFile + $content | Should -BeExactly "Some String" } } Context "Valdiate Get-Item parameters" { It "Verify Force" { $result = Get-Item -Path $testFile -Force - $result.Name | Should Be $testFile + $result.Name | Should -BeExactly $testFile } It "Verify Path Wildcard" { $result = Get-Item -Path "*2.txt" - $result.Name | Should Be $testFile2 + $result.Name | Should -BeExactly $testFile2 } It "Verify Include" { $result = Get-Item -Path "TestDrive:\*" -Include "*2.txt" - $result.Name | Should Be $testFile2 + $result.Name | Should -BeExactly $testFile2 } It "Verify Include and Exclude Intersection" { $result = Get-Item -Path "TestDrive:\*" -Include "*.txt" -Exclude "*2*" - $result.Name | Should Be $testFile + $result.Name | Should -BeExactly $testFile } It "Verify Filter" { $result = Get-Item -Path "TestDrive:\*" -filter "*2.txt" - $result.Name | Should Be $testFile2 + $result.Name | Should -BeExactly $testFile2 } It "Verify -LiteralPath with wildcard fails for file that doesn't exist" { @@ -958,7 +957,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature It "Verify -LiteralPath with wildcard succeeds for file" -Skip:($IsWindows) { New-Item -Path "$testdrive\a*b.txt" -ItemType File > $null $file = Get-Item -LiteralPath "$testdrive\a*b.txt" - $file.Name | Should BeExactly "a*b.txt" + $file.Name | Should -BeExactly "a*b.txt" } } @@ -982,7 +981,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item -Path $altTestFile -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify Include and Exclude Intersection" { @@ -990,16 +989,16 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Move-Item -Path "TestDrive:\*" -Destination "TestDrive:\dest" -Include "*.txt" -Exclude "*2*" $file1 = Get-Item "TestDrive:\dest\$testFile2" -ErrorAction SilentlyContinue $file2 = Get-Item "TestDrive:\dest\$testFile" -ErrorAction SilentlyContinue - $file1 | Should BeNullOrEmpty - $file2.Name | Should Be $testFile + $file1 | Should -BeNullOrEmpty + $file2.Name | Should -BeExactly $testFile } It "Verify Filter" { Move-Item -Path "TestDrive:\*" -Filter "*2.txt" -Destination $altTestFile $file1 = Get-Item $testFile2 -ErrorAction SilentlyContinue $file2 = Get-Item $altTestFile -ErrorAction SilentlyContinue - $file1 | Should BeNullOrEmpty - $file2.Name | Should Be $altTestFile + $file1 | Should -BeNullOrEmpty + $file2.Name | Should -BeExactly $altTestFile } } @@ -1014,15 +1013,15 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item -Path $newFile -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify Confirm can be bypassed" { Rename-Item -Path $testFile -NewName $newFile -Confirm:$false $file1 = Get-Item -Path $testFile -ErrorAction SilentlyContinue $file2 = Get-Item -Path $newFile -ErrorAction SilentlyContinue - $file1 | Should BeNullOrEmpty - $file2.Name | Should Be $newFile + $file1 | Should -BeNullOrEmpty + $file2.Name | Should -BeExactly $newFile } } @@ -1030,7 +1029,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature It "Verify WhatIf" { Remove-Item $testFile -WhatIf $result = Get-Item $testFile - $result.Name | Should Be $testFile + $result.Name | Should -BeExactly $testFile } It "Verify Confirm can be bypassed" { @@ -1039,7 +1038,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item $testFile -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify LiteralPath" { @@ -1048,13 +1047,13 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item $testFile -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify Filter" { Remove-Item "TestDrive:\*" -Filter "*.txt" $result = Get-Item "TestDrive:\*.txt" - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Verify Include" { @@ -1063,21 +1062,21 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Get-Item $testFile2 -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" } } It "Verify Include and Exclude Intersection" { Remove-Item "TestDrive:\*" -Include "*.txt" -exclude "*2*" $file1 = Get-Item $testFile -ErrorAction SilentlyContinue $file2 = Get-Item $testFile2 -ErrorAction SilentlyContinue - $file1 | Should BeNullOrEmpty - $file2.Name | Should Be $testFile2 + $file1 | Should -BeNullOrEmpty + $file2.Name | Should -BeExactly $testFile2 } It "Verify Path can accept wildcard" { Remove-Item "TestDrive:\*.txt" -Recurse -Force $result = Get-ChildItem "TestDrive:\*.txt" - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "Verify no error if wildcard doesn't match: " -TestCases @( @@ -1086,7 +1085,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature @{path="TestDrive:\z.*"} ) { param($path) - { Remove-Item $path } | Should Not Throw + { Remove-Item $path } | Should -Not -Throw } } @@ -1095,50 +1094,50 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature Set-Content -Path @($testFile,$testFile2) -Value @($testContent,$testContent2) $content1 = Get-Content $testFile $content2 = Get-Content $testFile2 - $content1 | Should Be $content2 - ($content1[0] + $content1[1]) | Should Be ($testContent + $testContent2) + $content1 | Should -BeExactly $content2 + ($content1[0] + $content1[1]) | Should -BeExactly ($testContent + $testContent2) } It "Validate LiteralPath" { Set-Content -LiteralPath "TestDrive:\$testFile" -Value $testContent $content = Get-Content $testFile - $content | Should Be $testContent + $content | Should -BeExactly $testContent } It "Validate Confirm can be bypassed" { Set-Content -Path $testFile -Value $testContent -Confirm:$false $content = Get-Content $testFile - $content | Should Be $testContent + $content | Should -BeExactly $testContent } It "Validate WhatIf" { Set-Content -Path $testFile -Value $testContent -WhatIf $content = Get-Content $testFile - $content | Should BeNullOrEmpty + $content | Should -BeNullOrEmpty } It "Validate Include" { Set-Content -Path "TestDrive:\*" -Value $testContent -Include "*2.txt" $content1 = Get-Content $testFile $content2 = Get-Content $testFile2 - $content1 | Should BeNullOrEmpty - $content2 | Should Be $testContent + $content1 | Should -BeNullOrEmpty + $content2 | Should -BeExactly $testContent } It "Validate Exclude" { Set-Content -Path "TestDrive:\*" -Value $testContent -Exclude "*2.txt" $content1 = Get-Content $testFile $content2 = Get-Content $testFile2 - $content1 | Should Be $testContent - $content2 | Should BeNullOrEmpty + $content1 | Should -BeExactly $testContent + $content2 | Should -BeNullOrEmpty } It "Validate Filter" { Set-Content -Path "TestDrive:\*" -Value $testContent -Filter "*2.txt" $content1 = Get-Content $testFile $content2 = Get-Content $testFile2 - $content1 | Should BeNullOrEmpty - $content2 | Should Be $testContent + $content1 | Should -BeNullOrEmpty + $content2 | Should -BeExactly $testContent } } @@ -1150,52 +1149,52 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature It "Validate Array Input for Path" { $result = Get-Content -Path @($testFile,$testFile2) - $result[0] | Should Be $testContent - $result[1] | Should Be $testContent2 + $result[0] | Should -BeExactly $testContent + $result[1] | Should -BeExactly $testContent2 } It "Validate Include" { $result = Get-Content -Path "TestDrive:\*" -Include "*2.txt" - $result | Should Be $testContent2 + $result | Should -BeExactly $testContent2 } It "Validate Exclude" { $result = Get-Content -Path "TestDrive:\*" -Exclude "*2.txt" - $result | Should Be $testContent + $result | Should -BeExactly $testContent } It "Validate Filter" { $result = Get-Content -Path "TestDrive:\*" -Filter "*2.txt" - $result | Should Be $testContent2 + $result | Should -BeExactly $testContent2 } It "Validate ReadCount" { Set-Content -Path $testFile -Value "Test Line 1`nTest Line 2`nTest Line 3`nTest Line 4`nTest Line 5`nTest Line 6" $result = (Get-Content -Path $testFile -ReadCount 2) - $result[0][0] | Should Be "Test Line 1" - $result[0][1] | Should Be "Test Line 2" - $result[1][0] | Should Be "Test Line 3" - $result[1][1] | Should Be "Test Line 4" - $result[2][0] | Should Be "Test Line 5" - $result[2][1] | Should Be "Test Line 6" + $result[0][0] | Should -BeExactly "Test Line 1" + $result[0][1] | Should -BeExactly "Test Line 2" + $result[1][0] | Should -BeExactly "Test Line 3" + $result[1][1] | Should -BeExactly "Test Line 4" + $result[2][0] | Should -BeExactly "Test Line 5" + $result[2][1] | Should -BeExactly "Test Line 6" } It "Validate TotalCount" { Set-Content -Path $testFile -Value "Test Line 1`nTest Line 2`nTest Line 3`nTest Line 4`nTest Line 5`nTest Line 6" $result = Get-Content -Path $testFile -TotalCount 4 - $result[0] | Should Be "Test Line 1" - $result[1] | Should Be "Test Line 2" - $result[2] | Should Be "Test Line 3" - $result[3] | Should Be "Test Line 4" - $result[4] | Should BeNullOrEmpty + $result[0] | Should -BeExactly "Test Line 1" + $result[1] | Should -BeExactly "Test Line 2" + $result[2] | Should -BeExactly "Test Line 3" + $result[3] | Should -BeExactly "Test Line 4" + $result[4] | Should -BeNullOrEmpty } It "Validate Tail" { Set-Content -Path $testFile -Value "Test Line 1`nTest Line 2`nTest Line 3`nTest Line 4`nTest Line 5`nTest Line 6" $result = Get-Content -Path $testFile -Tail 2 - $result[0] | Should Be "Test Line 5" - $result[1] | Should Be "Test Line 6" - $result[2] | Should BeNullOrEmpty + $result[0] | Should -BeExactly "Test Line 5" + $result[1] | Should -BeExactly "Test Line 6" + $result[2] | Should -BeNullOrEmpty } } } @@ -1236,12 +1235,12 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Context "Validate Resolve-Path Cmdlet Parameters" { It "Verify LiteralPath" { $result = Resolve-Path -LiteralPath "TestDrive:\" - ($result.Path.TrimEnd('/\')) | Should Be "TestDrive:" + ($result.Path.TrimEnd('/\')) | Should -BeExactly "TestDrive:" } It "Verify relative" { $relativePath = Resolve-Path -Path . -Relative - $relativePath | Should Be (Join-Path "." "") + $relativePath | Should -BeExactly (Join-Path "." "") } } @@ -1249,10 +1248,10 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur It "Validate Resolve" { $result = Join-Path -Path . -ChildPath $level1_0 -Resolve if ($IsWindows) { - $result | Should BeExactly "TestDrive:\$level1_0" + $result | Should -BeExactly "TestDrive:\$level1_0" } else { - $result | Should BeExactly "TestDrive:/$level1_0" + $result | Should -BeExactly "TestDrive:/$level1_0" } } } @@ -1260,63 +1259,63 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Context "Validate Split-Path Cmdlet Parameters" { It "Validate Parent" { $result = Split-Path -Path $level1_0Full -Parent -Resolve - ($result.TrimEnd('/\')) | Should Be "TestDrive:" + ($result.TrimEnd('/\')) | Should -BeExactly "TestDrive:" } It "Validate IsAbsolute" { $resolved = Split-Path -Path . -Resolve -IsAbsolute $unresolved = Split-Path -Path . -IsAbsolute - $resolved | Should Be $true - $unresolved | Should Be $false + $resolved | Should -BeTrue + $unresolved | Should -BeFalse } It "Validate Leaf" { $result = Split-Path -Path $level1_0Full -Leaf - $result | Should Be $level1_0 + $result | Should -BeExactly $level1_0 } It 'Validate LeafBase' { $result = Split-Path -Path "$level2_1Full$fileExt" -LeafBase - $result | Should Be $level2_1 + $result | Should -BeExactly $level2_1 } It 'Validate LeafBase is not over-zealous' { $result = Split-Path -Path "$level2_1Full$fileExt$fileExt" -LeafBase - $result | Should Be "$level2_1$fileExt" + $result | Should -BeExactly "$level2_1$fileExt" } It 'Validate LeafBase' { $result = Split-Path -Path "$level2_1Full$fileExt" -Extension - $result | Should Be $fileExt + $result | Should -BeExactly $fileExt } It "Validate NoQualifier" { $result = Split-Path -Path $level1_0Full -NoQualifier - ($result.TrimStart('/\')) | Should Be $level1_0 + ($result.TrimStart('/\')) | Should -BeExactly $level1_0 } It "Validate Qualifier" { $result = Split-Path -Path $level1_0Full -Qualifier - $result | Should Be "TestDrive:" + $result | Should -BeExactly "TestDrive:" } } Context "Valdiate Set-Location Cmdlets Parameters" { It "Without Passthru Doesn't Return a Path" { $result = Set-Location -Path $level1_0 - $result | Should BeNullOrEmpty + $result | Should -BeNullOrEmpty } It "By LiteralPath" { $result = Set-Location -LiteralPath $level1_0Full -PassThru - $result.Path | Should Be $level1_0Full + $result.Path | Should -BeExactly $level1_0Full } It "To Default Location Stack Does Nothing" { $beforeLoc = Get-Location Set-Location -StackName "" $afterLoc = Get-Location - $beforeLoc.Path | Should Be $afterLoc.Path + $beforeLoc.Path | Should -BeExactly $afterLoc.Path } It "WhatIf is Not Supported" { @@ -1324,7 +1323,7 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Set-Location $level1_0 -WhatIf throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "NamedParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "NamedParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand" } } } @@ -1338,9 +1337,9 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Pop-Location $location3 = Get-Location - $location1.Path | Should Be $level2_0Full - $location2.Path | Should Be $level1_0Full - $location3.Path | Should Be $root + $location1.Path | Should -BeExactly $level2_0Full + $location2.Path | Should -BeExactly $level1_0Full + $location3.Path | Should -BeExactly $root } It "Verify Push + PassThru" { @@ -1352,9 +1351,9 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Set-Location $level2_0 $location3 = Get-Location - $location1.Path | Should Be $passThru1.Path - $location2.Path | Should Be $passThru2.Path - $location3.Path | Should Be $level2_0Full + $location1.Path | Should -BeExactly $passThru1.Path + $location2.Path | Should -BeExactly $passThru2.Path + $location3.Path | Should -BeExactly $level2_0Full } It "Verify Push + LiteralPath" { @@ -1366,9 +1365,9 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Pop-Location $location3 = Get-Location - $location1.Path | Should Be $level2_0Full - $location2.Path | Should Be $level1_0Full - $location3.Path | Should Be $root + $location1.Path | Should -BeExactly $level2_0Full + $location2.Path | Should -BeExactly $level1_0Full + $location3.Path | Should -BeExactly $root } It "Verify Pop + Invalid Stack Name" { @@ -1376,7 +1375,7 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur Pop-Location -StackName UnknownStackName -ErrorAction Stop throw "Expected exception not thrown" } - catch { $_.FullyQualifiedErrorId | Should Be "Argument,Microsoft.PowerShell.Commands.PopLocationCommand" } + catch { $_.FullyQualifiedErrorId | Should -Be "Argument,Microsoft.PowerShell.Commands.PopLocationCommand" } } } } @@ -1392,9 +1391,9 @@ Describe "UNC paths" -Tags 'CI' { $systemDrive = ($env:SystemDrive).Replace(":","$") $testPath = Join-Path "\\localhost" $systemDrive & $cmdlet $testPath - Get-Location | Should BeExactly "Microsoft.PowerShell.Core\FileSystem::$testPath" + Get-Location | Should -BeExactly "Microsoft.PowerShell.Core\FileSystem::$testPath" $children = Get-ChildItem -ErrorAction Stop - $children.Count | Should BeGreaterThan 0 + $children.Count | Should -BeGreaterThan 0 } finally { Set-Location $originalLocation diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 index 4486f7c6982..01035f179a5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 @@ -35,64 +35,64 @@ Describe "Get-ChildItem" -Tags "CI" { } It "Should list the contents of the current folder" { - (Get-ChildItem .).Name.Length | Should BeGreaterThan 0 + (Get-ChildItem .).Name.Length | Should -BeGreaterThan 0 } It "Should list the contents of the home directory" { pushd $HOME - (Get-ChildItem .).Name.Length | Should BeGreaterThan 0 + (Get-ChildItem .).Name.Length | Should -BeGreaterThan 0 popd } It "Should have a the proper fields and be populated" { $var = Get-Childitem . - $var.Name.Length | Should BeGreaterThan 0 - $var.Mode.Length | Should BeGreaterThan 0 - $var.LastWriteTime | Should BeGreaterThan 0 - $var.Length.Length | Should BeGreaterThan 0 + $var.Name.Length | Should -BeGreaterThan 0 + $var.Mode.Length | Should -BeGreaterThan 0 + $var.LastWriteTime | Should -BeGreaterThan 0 + $var.Length.Length | Should -BeGreaterThan 0 } It "Should list files in sorted order" { $files = Get-ChildItem -Path $TestDrive - $files[0].Name | Should Be $item_E - $files[1].Name | Should Be $item_a - $files[2].Name | Should Be $item_B - $files[3].Name | Should Be $item_c - $files[4].Name | Should Be $item_D + $files[0].Name | Should -Be $item_E + $files[1].Name | Should -Be $item_a + $files[2].Name | Should -Be $item_B + $files[3].Name | Should -Be $item_c + $files[4].Name | Should -Be $item_D } It "Should list hidden files as well when 'Force' parameter is used" { $files = Get-ChildItem -path $TestDrive -Force - $files | Should not be $null - $files.Count | Should be 6 - $files.Name.Contains($item_F) | Should Be $true + $files | Should -Not -BeNullOrEmpty + $files.Count | Should -Be 6 + $files.Name.Contains($item_F) | Should -BeTrue } It "Should list only hidden files when 'Hidden' parameter is used" { $files = Get-ChildItem -path $TestDrive -Hidden - $files | Should not be $null - $files.Count | Should be 1 - $files[0].Name | Should Be $item_F + $files | Should -Not -BeNullOrEmpty + $files.Count | Should -Be 1 + $files[0].Name | Should -BeExactly $item_F } It "Should find the hidden file if specified with hidden switch" { $file = Get-ChildItem -Path (Join-Path $TestDrive $item_F) -Hidden - $file | Should Not BeNullOrEmpty - $file.Count | Should be 1 - $file.Name | Should be $item_F + $file | Should -Not -BeNullOrEmpty + $file.Count | Should -Be 1 + $file.Name | Should -BeExactly $item_F } It "Should list items in current directory only with depth set to 0" { - (Get-ChildItem -Path $TestDrive -Depth 0).Count | Should Be 5 - (Get-ChildItem -Path $TestDrive -Depth 0 -Include *).Count | Should Be 5 - (Get-ChildItem -Path $TestDrive -Depth 0 -Exclude IntentionallyNonexistent).Count | Should Be 5 + (Get-ChildItem -Path $TestDrive -Depth 0).Count | Should -Be 5 + (Get-ChildItem -Path $TestDrive -Depth 0 -Include *).Count | Should -Be 5 + (Get-ChildItem -Path $TestDrive -Depth 0 -Exclude IntentionallyNonexistent).Count | Should -Be 5 } It "Should return items recursively when using 'Include' or 'Exclude' parameters" { - (Get-ChildItem -Path $TestDrive -Depth 1).Count | Should Be 6 - (Get-ChildItem -Path $TestDrive -Depth 1 -Include $item_G).Count | Should Be 1 - (Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5 + (Get-ChildItem -Path $TestDrive -Depth 1).Count | Should -Be 6 + (Get-ChildItem -Path $TestDrive -Depth 1 -Include $item_G).Count | Should -Be 1 + (Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should -Be 5 } It "Should return items recursively when using 'Include' or 'Exclude' parameters with -LiteralPath" { @@ -107,18 +107,18 @@ Describe "Get-ChildItem" -Tags "CI" { $null = New-Item $file1 -Force -ItemType File - (Get-ChildItem @Parameters).Count | Should Be $ExpectedCount + (Get-ChildItem @Parameters).Count | Should -Be $ExpectedCount } It "get-childitem with and without file in search root" { $null = New-Item $file2 -Force -ItemType File - (Get-ChildItem -Path $searchRoot -File -Recurse).Count | Should be 2 - (Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should be 1 + (Get-ChildItem -Path $searchRoot -File -Recurse).Count | Should -Be 2 + (Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1 Remove-Item $file2 -ErrorAction SilentlyContinue -Force - (Get-ChildItem -Path $searchRoot -File -Recurse).Count | Should be 1 - (Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should be 1 + (Get-ChildItem -Path $searchRoot -File -Recurse).Count | Should -Be 1 + (Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1 } } @@ -132,7 +132,7 @@ Describe "Get-ChildItem" -Tags "CI" { $foobar = Get-Childitem env: | Where-Object {$_.Name -eq '__foobar'} $count = if ($IsWindows) { 1 } else { 2 } - ($foobar | measure).Count | Should Be $count + ($foobar | measure).Count | Should -Be $count } catch { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 index 3b309f9ac11..f53fb460f64 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 @@ -1008,7 +1008,7 @@ try { It "Verify type returned by Get-ComputerInfo" { $computerInfo = Get-ComputerInfo - $computerInfo | Should BeOfType Microsoft.PowerShell.Commands.ComputerInfo + $computerInfo | Should -BeOfType 'Microsoft.PowerShell.Commands.ComputerInfo' } } @@ -1037,7 +1037,7 @@ try { $ObservedList = $ComputerInformation.$property $ExpectedList = $Expected.$property $SpecialPropertyList = ($ObservedList)[0].psobject.properties.name - Compare-Object $ObservedList $ExpectedList -property $SpecialPropertyList | should BeNullOrEmpty + Compare-Object $ObservedList $ExpectedList -property $SpecialPropertyList | Should -BeNullOrEmpty } else { @@ -1049,7 +1049,7 @@ try { $left = $left -join ":" $right = $right -join ":" } - $left | should be $right + $left | Should -Be $right } } } @@ -1063,9 +1063,9 @@ try { $expectedProperties = @("BiosBIOSVersion") $propertyFilter = "BiosBIOSVersion" $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be 1 - $computerInfoWithProp.$propertyFilter | Should be $expected.$propertyFilter + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be 1 + $computerInfoWithProp.$propertyFilter | Should -Be $expected.$propertyFilter } # @@ -1076,10 +1076,10 @@ try { $expectedProperties = @("BiosBIOSVersion","BiosBuildNumber","BiosCaption") $propertyFilter = @("BiosBIOSVersion","BiosBuildNumber","BiosCaption") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be 3 + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be 3 foreach($property in $propertyFilter) { - $ComputerInfoWithProp.$property | Should Be $Expected.$property + $ComputerInfoWithProp.$property | Should -Be $Expected.$property } } @@ -1091,8 +1091,8 @@ try { $expectedProperties = $null $propertyFilter = @("BiosBIOSVersionXXX") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be 0 + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be 0 } # @@ -1103,8 +1103,8 @@ try { $expectedProperties = $null $propertyFilter = @("BiosBIOSVersionXXX","InvalidProperty1","InvalidProperty2","InvalidProperty3") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be 0 + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be 0 } # @@ -1115,12 +1115,12 @@ try { $expectedProperties = @("BiosCodeSet","BiosCurrentLanguage","BiosDescription") $propertyFilter = @("InvalidProperty1","BiosCodeSet","BiosCurrentLanguage","BiosDescription") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] + $computerInfoWithProp | Should -BeOfType [pscustomobject] $realProperties = $propertyFilter | Where-Object { $_ -notmatch "^InvalidProperty[0-9]+" } - @($computerInfoWithProp.psobject.properties).count | should be $realProperties.Count + @($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count foreach ( $property in $realProperties ) { - $computerInfoWithProp.$property | Should Be $expected.$property + $computerInfoWithProp.$property | Should -Be $expected.$property } } @@ -1132,12 +1132,12 @@ try { $expectedProperties = @("BiosCodeSet","BiosCurrentLanguage","BiosDescription") $propertyFilter = @("BiosCodeSet","InvalidProperty1","BiosCurrentLanguage","BiosDescription","InvalidProperty2") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] + $computerInfoWithProp | Should -BeOfType [pscustomobject] $realProperties = $propertyFilter | Where-Object { $_ -notmatch "^InvalidProperty[0-9]+" } - @($computerInfoWithProp.psobject.properties).count | should be $realProperties.Count + @($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count foreach ( $property in $realProperties ) { - $computerInfoWithProp.$property | Should Be $expected.$property + $computerInfoWithProp.$property | Should -Be $expected.$property } } @@ -1149,11 +1149,11 @@ try { $expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage") $propertyFilter = @("BiosC*") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be $expectedProperties.Count + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count foreach ( $property in $expectedProperties ) { - $computerInfoWithProp.$property | Should Be $expected.$property + $computerInfoWithProp.$property | Should -Be $expected.$property } } @@ -1165,11 +1165,11 @@ try { $expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage","CsCaption") $propertyFilter = @("BiosC*","CsCaption") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be $expectedProperties.Count + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count foreach ( $property in $expectedProperties ) { - $computerInfoWithProp.$property | Should Be $expected.$property + $computerInfoWithProp.$property | Should -Be $expected.$property } } @@ -1181,11 +1181,11 @@ try { $expectedProperties = @("BiosCaption","BiosCharacteristics","BiosCodeSet","BiosCurrentLanguage","CsCaption") $propertyFilter = @("CsCaption","InvalidProperty1","BiosC*") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be $expectedProperties.Count + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count foreach ( $property in $expectedProperties ) { - $computerInfoWithProp.$property | Should Be $expected.$property + $computerInfoWithProp.$property | Should -Be $expected.$property } } @@ -1197,8 +1197,8 @@ try { $expectedProperties = $null $propertyFilter = @("BiosBIOSVersionX*") $computerInfoWithProp = Get-ComputerInfoForTest -properties $propertyFilter - $computerInfoWithProp | should beoftype [pscustomobject] - @($computerInfoWithProp.psobject.properties).count | should be 0 + $computerInfoWithProp | Should -BeOfType [pscustomobject] + @($computerInfoWithProp.psobject.properties).count | Should -Be 0 } } @@ -1274,13 +1274,13 @@ try { It "Test for DeviceGuard properties" -Pending { if (-not (HasDeviceGuardLicense)) { - $observed.DeviceGuardSmartStatus | Should Be 0 - $observed.DeviceGuardRequiredSecurityProperties | Should Be $null - $observed.DeviceGuardAvailableSecurityProperties | Should Be $null - $observed.DeviceGuardSecurityServicesConfigured | Should Be $null - $observed.DeviceGuardSecurityServicesRunning | Should Be $null - $observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should Be $null - $observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should Be $null + $observed.DeviceGuardSmartStatus | Should -Be 0 + $observed.DeviceGuardRequiredSecurityProperties | Should -BeNullOrEmpty + $observed.DeviceGuardAvailableSecurityProperties | Should -BeNullOrEmpty + $observed.DeviceGuardSecurityServicesConfigured | Should -BeNullOrEmpty + $observed.DeviceGuardSecurityServicesRunning | Should -BeNullOrEmpty + $observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should -BeNullOrEmpty + $observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should -BeNullOrEmpty } else { @@ -1304,29 +1304,29 @@ try { "1" = "CredentialGuard" "2" = "HypervisorEnforcedCodeIntegrity" } - $observed.DeviceGuardSmartStatus | Should Be (Get-StringValuesFromValueMap -valuemap $smartStatusValues -values $deviceGuard.SmartStatus) + $observed.DeviceGuardSmartStatus | Should -Be (Get-StringValuesFromValueMap -valuemap $smartStatusValues -values $deviceGuard.SmartStatus) if ($deviceGuard.RequiredSecurityProperties -eq $null) { - $observed.DeviceGuardRequiredSecurityProperties | Should BeNullOrEmpty + $observed.DeviceGuardRequiredSecurityProperties | Should -BeNullOrEmpty } else { - $observed.DeviceGuardRequiredSecurityProperties | Should Not BeNullOrEmpty - [string]::Join(",", $observed.DeviceGuardRequiredSecurityProperties) | Should Be (Get-StringValuesFromValueMap -valuemap $requiredSecurityPropertiesValues -values $deviceGuard.RequiredSecurityProperties) + $observed.DeviceGuardRequiredSecurityProperties | Should -Not -BeNullOrEmpty + [string]::Join(",", $observed.DeviceGuardRequiredSecurityProperties) | Should -Be (Get-StringValuesFromValueMap -valuemap $requiredSecurityPropertiesValues -values $deviceGuard.RequiredSecurityProperties) } - $observed.DeviceGuardAvailableSecurityProperties | Should Be $deviceGuard.AvailableSecurityProperties - $observed.DeviceGuardSecurityServicesConfigured | Should Be $deviceGuard.SecurityServicesConfigured + $observed.DeviceGuardAvailableSecurityProperties | Should -Be $deviceGuard.AvailableSecurityProperties + $observed.DeviceGuardSecurityServicesConfigured | Should -Be $deviceGuard.SecurityServicesConfigured if ($deviceGuard.SecurityServicesRunning -eq $null) { - $observed.DeviceGuardSecurityServicesRunning | Should BeNullOrEmpty + $observed.DeviceGuardSecurityServicesRunning | Should -BeNullOrEmpty } else { - $observed.DeviceGuardSecurityServicesRunning | Should Not BeNullOrEmpty - [string]::Join(",", $observed.DeviceGuardSecurityServicesRunning) | Should Be (Get-StringValuesFromValueMap -valuemap $securityServicesRunningValues -values $deviceGuard.SecurityServicesRunning) + $observed.DeviceGuardSecurityServicesRunning | Should -Not -BeNullOrEmpty + [string]::Join(",", $observed.DeviceGuardSecurityServicesRunning) | Should -Be (Get-StringValuesFromValueMap -valuemap $securityServicesRunningValues -values $deviceGuard.SecurityServicesRunning) } - $observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.CodeIntegrityPolicyEnforcementStatus - $observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.UserModeCodeIntegrityPolicyEnforcementStatus + $observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should -Be $deviceGuard.CodeIntegrityPolicyEnforcementStatus + $observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should -Be $deviceGuard.UserModeCodeIntegrityPolicyEnforcementStatus } } @@ -1335,17 +1335,18 @@ try { # It "(special case) Test for property = OsFreePhysicalMemory" { - ($observed.OsFreePhysicalMemory -gt 0) | Should Be $true + ($observed.OsFreePhysicalMemory -gt 0) | Should -BeTrue } It "(special case) Test for property = OsFreeSpaceInPagingFiles" -Skip:([System.Management.Automation.Platform]::IsIoT -or !$IsWindows) { - ($observed.OsFreeSpaceInPagingFiles -gt 0) | Should Be $true + ($observed.OsFreeSpaceInPagingFiles -gt 0) | Should -BeTrue } It "(special case) Test for property = OsFreeVirtualMemory" { - ($observed.OsFreeVirtualMemory -gt 0) | Should Be $true + ($observed.OsFreeVirtualMemory -gt 0) | Should -BeTrue } + It "(special case) Test for property = OsLocalDateTime" { $computerInfo = Get-ComputerInfoForTest $testEndTime = Get-Date @@ -1354,25 +1355,25 @@ try { } It "(special case) Test for property = OsMaxNumberOfProcesses" { - ($observed.OsMaxNumberOfProcesses -gt 0) | Should Be $true + ($observed.OsMaxNumberOfProcesses -gt 0) | Should -BeTrue } It "(special case) Test for property = OsNumberOfProcesses" { - ($observed.OsNumberOfProcesses -gt 0) | Should Be $true + ($observed.OsNumberOfProcesses -gt 0) | Should -BeTrue } It "(special case) Test for property = OsUptime" { - ($observed.OsUptime.Ticks -gt 0) | Should Be $true + ($observed.OsUptime.Ticks -gt 0) | Should -BeTrue } It "(special case) Test for property = OsInUseVirtualMemory" { - ($observed.OsInUseVirtualMemory -gt 0) | Should Be $true + ($observed.OsInUseVirtualMemory -gt 0) | Should -BeTrue } It "(special case) Test for Filter Property - Property filter with special wild card * and fixed" { $propertyFilter = @("BiosC*","*") $computerInfo = Get-ComputerInfo -Property $propertyFilter - $computerInfo | Should BeOfType Microsoft.PowerShell.Commands.ComputerInfo + $computerInfo | Should -BeOfType Microsoft.PowerShell.Commands.ComputerInfo } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 index 34abbc96390..9ba435313ca 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 @@ -30,64 +30,64 @@ Describe "Get-Content" -Tags "CI" { throw "No Exception!" } catch { - $_.FullyQualifiedErrorId | should be "GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand" + $_.FullyQualifiedErrorId | Should -Be "GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand" } } It "Should return an Object when listing only a single line and the correct information from a file" { $content = (Get-Content -Path $testPath) - $content | Should Be $testString - $content.Count | Should Be 1 - $content | Should BeOfType "System.String" + $content | Should -BeExactly $testString + $content.Count | Should -Be 1 + $content | Should -BeOfType "System.String" } It "Should deliver an array object when listing a file with multiple lines and the correct information from a file" { $content = (Get-Content -Path $testPath2) - @(Compare-Object $content $testString2.Split($nl) -SyncWindow 0).Length | Should Be 0 - ,$content | Should BeOfType "System.Array" + @(Compare-Object $content $testString2.Split($nl) -SyncWindow 0).Length | Should -Be 0 + ,$content | Should -BeOfType "System.Array" } It "Should be able to return a specific line from a file" { - (Get-Content -Path $testPath2)[1] | Should be $secondline + (Get-Content -Path $testPath2)[1] | Should -BeExactly $secondline } It "Should be able to specify the number of lines to get the content of using the TotalCount switch" { $returnArray = (Get-Content -Path $testPath2 -TotalCount 2) - $returnArray[0] | Should Be $firstline - $returnArray[1] | Should Be $secondline + $returnArray[0] | Should -BeExactly $firstline + $returnArray[1] | Should -BeExactly $secondline } It "Should be able to specify the number of lines to get the content of using the Head switch" { $returnArray = (Get-Content -Path $testPath2 -Head 2) - $returnArray[0] | Should Be $firstline - $returnArray[1] | Should Be $secondline + $returnArray[0] | Should -BeExactly $firstline + $returnArray[1] | Should -BeExactly $secondline } It "Should be able to specify the number of lines to get the content of using the First switch" { $returnArray = (Get-Content -Path $testPath2 -First 2) - $returnArray[0] | Should Be $firstline - $returnArray[1] | Should Be $secondline + $returnArray[0] | Should -BeExactly $firstline + $returnArray[1] | Should -BeExactly $secondline } It "Should return the last line of a file using the Tail switch" { - Get-Content -Path $testPath -Tail 1 | Should Be $testString + Get-Content -Path $testPath -Tail 1 | Should -BeExactly $testString } It "Should return the last lines of a file using the Last alias" { - Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline + Get-Content -Path $testPath2 -Last 1 | Should -BeExactly $fifthline } It "Should be able to get content within a different drive" { Push-Location env: $expectedoutput = [Environment]::GetEnvironmentVariable("PATH"); - { Get-Content PATH } | Should Not Throw - Get-Content PATH | Should Be $expectedoutput + { Get-Content PATH } | Should -Not -Throw + Get-Content PATH | Should -BeExactly $expectedoutput Pop-Location } #[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)] It "should throw 'PSNotSupportedException' when you Set-Content to an unsupported provider" -Skip:($IsLinux -Or $IsMacOS) { - {Get-Content -Path HKLM:\\software\\microsoft -EA stop} | Should Throw "IContentCmdletProvider interface is not implemented" + {Get-Content -Path HKLM:\\software\\microsoft -ErrorAction Stop} | Should -Throw "IContentCmdletProvider interface is not implemented" } It 'Verifies -Tail reports a TailNotSupported error for unsupported providers' { @@ -124,9 +124,9 @@ baz $expected = 'foo' $actual = Get-Content -Path $testPath -Tail $tailCount -Encoding $encodingName - $actual.GetType() | Should Be "System.Object[]" - $actual.Length | Should Be $tailCount - $actual[0] | Should Be $expected + $actual | Should -BeOfType [string] + $actual.Length | Should -Be $tailCount + $actual[0] | Should -BeExactly $expected } It "should Get-Content with a variety of -Tail and -ReadCount: " -TestCases @( @@ -164,8 +164,8 @@ baz param($GetContentParams, $expectedLength, $expectedContent) Set-Content -Path $testPath $testContent $result = Get-Content @GetContentParams - $result.Length | Should Be $expectedLength - $result -eq $expectedContent + $result.Length | Should -Be $expectedLength + $result | Should -BeExactly $expectedContent } It "should Get-Content with a variety of -Delimiter and -Tail: " -TestCases @( @@ -183,8 +183,8 @@ baz param($GetContentParams, $expectedLength, $expectedContent) Set-Content -Path $testPath $testDelimiterContent $result = Get-Content @GetContentParams - $result.Length | Should Be $expectedLength - $result | Should BeExactly $expectedContent + $result.Length | Should -Be $expectedLength + $result | Should -BeExactly $expectedContent } It "should Get-Content with a variety of -Tail values and -AsByteStream parameter" -TestCases @( @@ -200,11 +200,11 @@ baz param($GetContentParams, $expectedLength, $expectedWindowsContent, $expectedNotWindowsContent) Set-Content -Path $testPath $testContent $result = Get-Content @GetContentParams - $result.Length | Should Be $expectedLength + $result.Length | Should -Be $expectedLength if ($isWindows) { - $result | Should BeExactly $expectedWindowsContent + $result | Should -BeExactly $expectedWindowsContent } else { - $result | Should BeExactly $expectedNotWindowsContent + $result | Should -BeExactly $expectedNotWindowsContent } } @@ -212,35 +212,35 @@ baz It "should Get-Content that matches the input string"{ Set-Content $testPath "Hello,llllWorlld","Hello2,llllWorlld2" $result=Get-Content $testPath -Delimiter "ll" - $result.Length | Should Be 9 + $result.Length | Should -Be 9 $expected = 'He', 'o,', '', 'Wor', "d${nl}He", 'o2,', '', 'Wor', "d2${nl}" - for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]} + for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should -BeExactly $expected[$i]} } It "Should support NTFS streams using colon syntax" -Skip:(!$IsWindows) { Set-Content "${testPath}:Stream" -Value "Foo" { Test-Path "${testPath}:Stream" | ShouldBeErrorId "ItemExistsNotSupportedError,Microsoft.PowerShell.Commands,TestPathCommand" } - Get-Content "${testPath}:Stream" | Should BeExactly "Foo" - Get-Content $testPath | Should BeExactly $testString + Get-Content "${testPath}:Stream" | Should -BeExactly "Foo" + Get-Content $testPath | Should -BeExactly $testString } It "Should support NTFS streams using -Stream" -Skip:(!$IsWindows) { Set-Content -Path $testPath -Stream hello -Value World - Get-Content -Path $testPath | Should Be $testString - Get-Content -Path $testPath -Stream hello | Should Be "World" + Get-Content -Path $testPath | Should -BeExactly $testString + Get-Content -Path $testPath -Stream hello | Should -BeExactly "World" $item = Get-Item -Path $testPath -Stream hello - $item | Should BeOfType System.Management.Automation.Internal.AlternateStreamData - $item.Stream | Should Be "hello" + $item | Should -BeOfType 'System.Management.Automation.Internal.AlternateStreamData' + $item.Stream | Should -BeExactly "hello" Clear-Content -Path $testPath -Stream hello - Get-Content -Path $testPath -Stream hello | Should BeNullOrEmpty + Get-Content -Path $testPath -Stream hello | Should -BeNullOrEmpty Remove-Item -Path $testPath -Stream hello { Get-Content -Path $testPath -Stream hello | ShouldBeErrorId "GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand" } } It "Should support colons in filename on Linux/Mac" -Skip:($IsWindows) { Set-Content "${testPath}:Stream" -Value "Hello" - "${testPath}:Stream" | Should Exist - Get-Content "${testPath}:Stream" | Should BeExactly "Hello" + "${testPath}:Stream" | Should -Exist + Get-Content "${testPath}:Stream" | Should -BeExactly "Hello" } It "-Stream is not a valid parameter for on Linux/Mac" -Skip:($IsWindows) -TestCases @( @@ -252,15 +252,15 @@ baz @{cmdlet="Remove-Item"} ) { param($cmdlet) - (Get-Command $cmdlet).Parameters["stream"] | Should BeNullOrEmpty + (Get-Command $cmdlet).Parameters["stream"] | Should -BeNullOrEmpty } It "Should return no content when an empty path is used with -Raw switch" { - Get-ChildItem $TestDrive -Filter "*.raw" | Get-Content -Raw | Should Be $null + Get-ChildItem $TestDrive -Filter "*.raw" | Get-Content -Raw | Should -BeNullOrEmpty } It "Should return no content when -TotalCount value is 0" { - Get-Content -Path $testPath -TotalCount 0 | Should Be $null + Get-Content -Path $testPath -TotalCount 0 | Should -BeNullOrEmpty } It "Should throw TailAndHeadCannotCoexist when both -Tail and -TotalCount are used" { @@ -296,51 +296,51 @@ baz } It "Should return all lines when -Tail value is more than number of lines in the file"{ $result = Get-Content -Path $testPath -ReadCount -1 -Tail 5 -Encoding UTF7 - $result.Length | Should Be 4 + $result.Length | Should -Be 4 $expected = $fileContent - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "Should return last three lines at one time for -ReadCount 0 and -Tail 3"{ $result = Get-Content -Path $testPath -ReadCount 0 -Tail 3 -Encoding UTF7 - $result.Length | Should Be 3 + $result.Length | Should -Be 3 $expected = $secondLine,$thirdLine,$fourthLine - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "Should return last three lines reading one at a time for -ReadCount 1 and -Tail 3"{ $result = Get-Content -Path $testPath -ReadCount 1 -Tail 3 -Encoding UTF7 - $result.Length | Should Be 3 + $result.Length | Should -Be 3 $expected = $secondLine,$thirdLine,$fourthLine - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "Should return last three lines at one time for -ReadCount 99999 and -Tail 3"{ $result = Get-Content -Path $testPath -ReadCount 99999 -Tail 3 -Encoding UTF7 - $result.Length | Should Be 3 + $result.Length | Should -Be 3 $expected = $secondLine,$thirdLine,$fourthLine - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "Should return last three lines two lines at a time for -ReadCount 2 and -Tail 3"{ $result = Get-Content -Path $testPath -ReadCount 2 -Tail 3 -Encoding UTF7 - $result.Length | Should Be 2 + $result.Length | Should -Be 2 $expected = New-Object System.Array[] 2 $expected[0] = ($secondLine,$thirdLine) $expected[1] = $fourthLine - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "Should not return any content when -TotalCount 0"{ $result = Get-Content -Path $testPath -TotalCount 0 -ReadCount 1 -Encoding UTF7 - $result.Length | Should Be 0 + $result.Length | Should -Be 0 } It "Should return first three lines two lines at a time for -TotalCount 3 and -ReadCount 2"{ $result = Get-Content -Path $testPath -TotalCount 3 -ReadCount 2 -Encoding UTF7 - $result.Length | Should Be 2 + $result.Length | Should -Be 2 $expected = New-Object System.Array[] 2 $expected[0] = ($firstLine,$secondLine) $expected[1] = $thirdLine - Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should BeNullOrEmpty + Compare-Object -ReferenceObject $expected -DifferenceObject $result | Should -BeNullOrEmpty } It "A warning should be emitted if both -AsByteStream and -Encoding are used together" { [byte[]][char[]]"test" | Set-Content -Encoding Unicode -AsByteStream "${TESTDRIVE}\bfile.txt" -WarningVariable contentWarning *>$null - $contentWarning.Message | Should Match "-AsByteStream" + $contentWarning.Message | Should -Match "-AsByteStream" } } } @@ -355,6 +355,6 @@ Describe "Get-Content -Raw test" -Tags "CI" { ) { param ($character, $filename) Set-Content -Encoding Ascii -NoNewline "$TestDrive\$filename" -Value $character - Get-Content -Raw "$TestDrive\$filename" | Should BeExactly $character + Get-Content -Raw "$TestDrive\$filename" | Should -BeExactly $character } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-EventLog.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-EventLog.Tests.ps1 index 9aa3503ffc9..d69986c1416 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-EventLog.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-EventLog.Tests.ps1 @@ -13,38 +13,36 @@ Describe "Get-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') { #CmdLets are not yet implemented, so these cases are -Pending:($True) for now... It "should return an array of eventlogs objects when called with -AsString parameter" -Pending:($True) { - {$result=Get-EventLog -AsString -ea stop} | Should Not Throw - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType "System.Array" - $result -eq "Application" | Should Be "Application" - $result.Count -ge 3 | Should Be $true + { $result=Get-EventLog -AsString -ErrorAction Stop } | Should -Not -Throw + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType "System.Array" + $result | Should -BeExactly "Application" + $result.Count | Should -BeGreaterThan 3 } It "should return a list of eventlog objects when called with -List parameter" -Pending:($True) { - {$result=Get-EventLog -List -ea stop} | Should Not Throw - $result | Should Not BeNullOrEmpty - ,$result | Should BeOfType "System.Array" - {$logs=$result | Select-Object -ExpandProperty Log} | Should Not Throw - $logs -eq "System" | Should Be "System" - $logs.Count -ge 3 | Should Be $true + { $result=Get-EventLog -List -ErrorAction Stop } | Should -Not -Throw + $result | Should -Not -BeNullOrEmpty + ,$result | Should -BeOfType "System.Array" + {$logs=$result | Select-Object -ExpandProperty Log} | Should -Not -Throw + $logs | Should -BeExactly "System" + $logs.Count | Should -BeGreaterThan 3 } It "should be able to Get-EventLog -LogName Application -Newest 100" -Pending:($True) { - {$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw - $result | Should Not BeNullOrEmpty - $result.Length -le 100 | Should Be $true - $result[0] | Should BeOfType "EventLogEntry" + { $result=get-eventlog -LogName Application -Newest 100 -ErrorAction Stop } | Should -Not -Throw + $result | Should -Not -BeNullOrEmpty + $result.Length | Should -BeLessThan 100 + $result[0] | Should -BeOfType "EventLogEntry" } It "should throw 'AmbiguousParameterSetException' when called with both -LogName and -List parameters" -Pending:($True) { - try {Get-EventLog -LogName System -List -ea stop; Throw "Previous statement unexpectedly succeeded..." - } catch {echo $_.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetEventLogCommand"} + { Get-EventLog -LogName System -List -ErrorAction Stop } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetEventLogCommand" } It "should be able to Get-EventLog -LogName * with multiple matches" -Pending:($True) { - {$result=get-eventlog -LogName * -ea stop} | Should Not Throw - $result | Should Not BeNullOrEmpty - $result -eq "Security" | Should Be "Security" - $result.Count -ge 3 | Should Be $true + { $result=get-eventlog -LogName * -ErrorAction Stop } | Should -Not -Throw + $result | Should -Not -BeNullOrEmpty + $result | Should -BeExactly "Security" + $result.Count | Should -BeGreaterThan 3 } It "should throw 'InvalidOperationException' when asked to get a log that does not exist" -Pending:($True) { - try {Get-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..." - } catch {echo $_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"} + { Get-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 index e34271cc4b9..e5427b0338c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 @@ -11,20 +11,20 @@ Describe "Get-Item" -Tags "CI" { } It "Should list all the items in the current working directory when asterisk is used" { $items = Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*") - ,$items | Should BeOfType 'System.Object[]' + ,$items | Should -BeOfType 'System.Object[]' } It "Should return the name of the current working directory when a dot is used" { $item = Get-Item $PSScriptRoot - $item | Should BeOfType 'System.IO.DirectoryInfo' - $item.Name | Should Be (Split-Path $PSScriptRoot -Leaf) + $item | Should -BeOfType 'System.IO.DirectoryInfo' + $item.Name | Should -BeExactly (Split-Path $PSScriptRoot -Leaf) } It "Should return the proper Name and BaseType for directory objects vs file system objects" { $rootitem = Get-Item $PSScriptRoot - $rootitem | Should BeOfType 'System.IO.DirectoryInfo' + $rootitem | Should -BeOfType 'System.IO.DirectoryInfo' $childitem = (Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1)) - $childitem | Should BeOfType 'System.IO.FileInfo' + $childitem | Should -BeOfType 'System.IO.FileInfo' } It "Using -literalpath should find no additional files" { @@ -32,12 +32,12 @@ Describe "Get-Item" -Tags "CI" { $null = New-Item -type file "$TESTDRIVE/filea.txt" # if literalpath is not correct we would see filea.txt $item = Get-Item -literalpath "$TESTDRIVE/file[abc].txt" - @($item).Count | Should Be 1 - $item.Name | Should Be 'file[abc].txt' + @($item).Count | Should -Be 1 + $item.Name | Should -BeExactly 'file[abc].txt' } It "Should have mode flags set" { - Get-ChildItem $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty } + Get-ChildItem $PSScriptRoot | foreach-object { $_.Mode | Should -Not -BeNullOrEmpty } } It "Should not return the item unless force is used if hidden" { @@ -47,9 +47,9 @@ Describe "Get-Item" -Tags "CI" { attrib +h "$hiddenFile" } ${result} = Get-Item "${hiddenFile}" -ErrorAction SilentlyContinue - ${result} | Should BeNullOrEmpty + ${result} | Should -BeNullOrEmpty ${result} = Get-Item -force "${hiddenFile}" -ErrorAction SilentlyContinue - ${result}.FullName | Should Be ${item}.FullName + ${result}.FullName | Should -BeExactly ${item}.FullName } Context "Test for Include, Exclude, and Filter" { @@ -61,23 +61,23 @@ Describe "Get-Item" -Tags "CI" { } It "Should respect -Exclude" { $result = Get-Item "${testBaseDir}/*" -Exclude "file2.txt" - ($result).Count | Should Be 1 - $result.Name | should be "file1.txt" + ($result).Count | Should -Be 1 + $result.Name | Should -BeExactly "file1.txt" } It "Should respect -Include" { $result = Get-Item "${testBaseDir}/*" -Include "file2.txt" - ($result).Count | Should Be 1 - $result.Name | should be "file2.txt" + ($result).Count | Should -Be 1 + $result.Name | Should -BeExactly "file2.txt" } It "Should respect -Filter" { $result = Get-Item "${testBaseDir}/*" -Filter "*2*" - ($result).Count | Should Be 1 - $result.Name | should be "file2.txt" + ($result).Count | Should -Be 1 + $result.Name | Should -BeExactly "file2.txt" } It "Should respect combinations of filter, include, and exclude" { $result = get-item "${testBaseDir}/*" -filter *.txt -include "file[12].txt" -exclude file2.txt - ($result).Count | Should Be 1 - $result.Name | should be "file1.txt" + ($result).Count | Should -Be 1 + $result.Name | Should -BeExactly "file1.txt" } } @@ -105,15 +105,15 @@ Describe "Get-Item" -Tags "CI" { } It "Should find an alternate stream if present" -skip:$skipNotWindows { $result = Get-Item $altStreamPath -Stream $streamName - $result.Length | Should Be ($stringData.Length + [Environment]::NewLine.Length) - $result.Stream | Should Be $streamName + $result.Length | Should -Be ($stringData.Length + [Environment]::NewLine.Length) + $result.Stream | Should -Be $streamName } } Context "Registry Provider" { It "Can retrieve an item from registry" -skip:$skipNotWindows { ${result} = Get-Item HKLM:/Software - ${result} | Should BeOfType "Microsoft.Win32.RegistryKey" + ${result} | Should -BeOfType "Microsoft.Win32.RegistryKey" } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1 index bcf6c2f1c1a..40fb81d0f6c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1 @@ -11,44 +11,44 @@ Describe "Get-ItemProperty" -Tags "CI" { New-Item $testfile -ItemType file -Force It "Should be able to be called on in the current directory" { - $(Get-ItemProperty $PSScriptRoot).Name | Should Be $currentDirectory + $(Get-ItemProperty $PSScriptRoot).Name | Should -BeExactly $currentDirectory } It "Should be able to be called on a parent directory" { - (Get-ItemProperty $PSScriptRoot/..).Name | Should Be $parentDirectory + (Get-ItemProperty $PSScriptRoot/..).Name | Should -BeExactly $parentDirectory } It "Should be able to be called on a directory using the path switch" { - { Get-ItemProperty -Path $tempDirectory } | Should Not Throw + { Get-ItemProperty -Path $tempDirectory } | Should -Not -Throw } It "Should be able to be called on a file using the path switch" { - { Get-ItemProperty -Path $testfile } | Should Not Throw + { Get-ItemProperty -Path $testfile } | Should -Not -Throw } It "Should be able to access a property using the Path and name switches" { - { Get-ItemProperty -Path $testfile -Name fullname } | Should Not Throw + { Get-ItemProperty -Path $testfile -Name fullname } | Should -Not -Throw $output = Get-ItemProperty -Path $testfile -Name fullname - $output.PSPath | Should Not BeNullOrEmpty + $output.PSPath | Should -Not -BeNullOrEmpty - $output.PSDrive | Should Be $testprovider + $output.PSDrive | Should -Be $testprovider - $output.PSProvider.Name | Should Be "FileSystem" + $output.PSProvider.Name | Should -Be "FileSystem" } It "Should be able to use the gp alias without error" { - { gp . } | Should Not Throw - { gp .. } | Should Not Throw + { gp . } | Should -Not -Throw + { gp .. } | Should -Not -Throw } It "Should have the same results between alias and cmdlet" { $alias = gp -Path $testfile -Name fullname $cmdlet = Get-ItemProperty -Path $testfile -Name fullname - $alias.PSPath | Should Be $cmdlet.PSPath - $alias.PSDrive | Should Be $cmdlet.PSDrive - $alias.PSProvider.Name | Should Be $cmdlet.PSProvider.Name + $alias.PSPath | Should -Be $cmdlet.PSPath + $alias.PSDrive | Should -Be $cmdlet.PSDrive + $alias.PSProvider.Name | Should -Be $cmdlet.PSProvider.Name } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Location.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Location.Tests.ps1 index b1c46df8281..c5d07f03718 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Location.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Location.Tests.ps1 @@ -12,10 +12,10 @@ Describe "Get-Location" -Tags "CI" { It "Should list the output of the current working directory" { - (Get-Location).Path | Should Be $currentDirectory + (Get-Location).Path | Should -BeExactly $currentDirectory } It "Should do exactly the same thing as its alias" { - (pwd).Path | Should Be (Get-Location).Path + (pwd).Path | Should -BeExactly (Get-Location).Path } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 index 095d6466c9a..2f00722b16c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 @@ -3,56 +3,57 @@ Describe "Get-PSDrive" -Tags "CI" { It "Should not throw" { - Get-PSDrive | Should Not BeNullOrEmpty + Get-PSDrive | Should -Not -BeNullOrEmpty } It "Should have a name and a length property" { - (Get-PSDrive).Name | Should Not BeNullOrEmpty - (Get-PSDrive).Root.Length | Should Not BeLessThan 1 + (Get-PSDrive).Name | Should -Not -BeNullOrEmpty + (Get-PSDrive).Root.Length | Should -Not -BeLessThan 1 } It "Should be able to be called with the gdr alias" { - { gdr } | Should Not Throw + { gdr } | Should -Not -Throw - gdr | Should Not BeNullOrEmpty + gdr | Should -Not -BeNullOrEmpty } It "Should be the same output between Get-PSDrive and gdr" { $alias = gdr $actual = Get-PSDrive - $alias | Should Be $actual + + $alias | Should -BeExactly $actual } It "Should return drive info"{ - (Get-PSDrive Env).Name | Should Be Env - (Get-PSDrive Alias).Name | Should Be Alias + (Get-PSDrive Env).Name | Should -BeExactly Env + (Get-PSDrive Alias).Name | Should -BeExactly Alias if ($IsWindows) { - (Get-PSDrive Cert).Root | Should Be \ - (Get-PSDrive C).Provider.Name | Should Be FileSystem + (Get-PSDrive Cert).Root | Should -Be \ + (Get-PSDrive C).Provider.Name | Should -BeExactly FileSystem } else { - (Get-PSDrive /).Provider.Name | Should Be FileSystem + (Get-PSDrive /).Provider.Name | Should -BeExactly FileSystem } } It "Should be able to access a drive using the PSProvider switch" { - (Get-PSDrive -PSProvider FileSystem).Name.Length | Should BeGreaterThan 0 + (Get-PSDrive -PSProvider FileSystem).Name.Length | Should -BeGreaterThan 0 } It "Should return true that a drive that does not exist"{ - !(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True - Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty + !(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should -BeTrue + Get-PSDrive fake -ErrorAction SilentlyContinue | Should -BeNullOrEmpty } It "Should be able to determine the amount of free space of a drive" { $dInfo = Get-PSDrive TESTDRIVE - $dInfo.Free -ge 0 | Should be $true + $dInfo.Free -ge 0 | Should -BeTrue } It "Should be able to determine the amount of Used space of a drive" { $dInfo = Get-PSDrive TESTDRIVE - $dInfo.Used -ge 0 | Should be $true + $dInfo.Used -ge 0 | Should -BeTrue } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSProvider.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSProvider.Tests.ps1 index be7548a1028..f339f38c153 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSProvider.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSProvider.Tests.ps1 @@ -2,26 +2,26 @@ # Licensed under the MIT License. Describe "Get-PSProvider" -Tags "CI" { It "Should be able to call with no parameters without error" { - { Get-PSProvider } | Should Not Throw + { Get-PSProvider } | Should -Not -Throw } It "Should be able to call the filesystem provider" { - { Get-PSProvider FileSystem } | Should Not Throw + { Get-PSProvider FileSystem } | Should -Not -Throw $actual = Get-PSProvider FileSystem - $actual.Name | Should Be "FileSystem" + $actual.Name | Should -BeExactly "FileSystem" - $actual.Capabilities | Should Be "Filter, ShouldProcess, Credentials" + $actual.Capabilities | Should -BeExactly "Filter, ShouldProcess, Credentials" } It "Should be able to call a provider with a wildcard expression" { - { Get-PSProvider File*m } | Should Not Throw + { Get-PSProvider File*m } | Should -Not -Throw } It "Should be able to pipe the output" { $actual = Get-PSProvider - { $actual | Format-List } | Should Not Throw + { $actual | Format-List } | Should -Not -Throw } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index b6328317875..2852b79ecf9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -2,7 +2,7 @@ # Licensed under the MIT License. Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { It "Should support -IncludeUserName" { - (Get-Process -Id $pid -IncludeUserName).UserName | Should Match $env:USERNAME + (Get-Process -Id $pid -IncludeUserName).UserName | Should -Match $env:USERNAME } It "Should support -Module" -Pending:$IsMacOS { @@ -26,11 +26,11 @@ Describe "Get-Process" -Tags "CI" { $idleProcessPid = 0 } It "Should return a type of Object[] for Get-Process cmdlet" -Pending:$IsMacOS { - ,$ps | Should BeOfType "System.Object[]" + ,$ps | Should -BeOfType "System.Object[]" } It "Should have not empty Name flags set for Get-Process object" -Pending:$IsMacOS { - $ps | foreach-object { $_.Name | Should Not BeNullOrEmpty } + $ps | foreach-object { $_.Name | Should -Not -BeNullOrEmpty } } It "Should throw an error for non existing process id." { @@ -79,9 +79,9 @@ Describe "Get-Process Formatting" -Tags "Feature" { $formatData = Get-FormatData -TypeName $type -PowerShellVersion $PSVersionTable.PSVersion $tableControls = $formatData.FormatViewDefinition | Where-Object {$_.Control -is "System.Management.Automation.TableControl"} foreach ($tableControl in $tableControls) { - $tableControl.Control.Headers.Label -match "Handle*" | Should BeNullOrEmpty + $tableControl.Control.Headers.Label -match "Handle*" | Should -BeNullOrEmpty # verify that rows without headers isn't the handlecount (as PowerShell will create a header that matches the property name) - $tableControl.Control.Rows.Columns.DisplayEntry.Value -eq "HandleCount" | Should BeNullOrEmpty + $tableControl.Control.Rows.Columns.DisplayEntry.Value -eq "HandleCount" | Should -BeNullOrEmpty } } } @@ -90,12 +90,12 @@ Describe "Get-Process Formatting" -Tags "Feature" { Describe "Process Parent property" -Tags "CI" { It "Has Parent process property" { $powershellexe = (get-process -id $PID).mainmodule.filename - & $powershellexe -noprofile -command '(Get-Process -Id $pid).Parent' | Should Not be $null + & $powershellexe -noprofile -command '(Get-Process -Id $pid).Parent' | Should -Not -BeNullOrEmpty } It "Has valid parent process ID property" { $powershellexe = (get-process -id $PID).mainmodule.filename - & $powershellexe -noprofile -command '(Get-Process -Id $pid).Parent.Id' | Should Be $pid + & $powershellexe -noprofile -command '(Get-Process -Id $pid).Parent.Id' | Should -Be $pid } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1 index c5c2beb16f6..11cdf70e23b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1 @@ -26,7 +26,7 @@ Describe "Get-Service cmdlet tests" -Tags "CI" { throw 'Expected error on previous command' } catch { - $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' + $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' } } } @@ -39,7 +39,7 @@ Describe "Get-Service cmdlet tests" -Tags "CI" { throw 'Expected error on previous command' } catch { - $_.FullyQualifiedErrorId | Should Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' + $_.FullyQualifiedErrorId | Should -Be 'ParameterArgumentValidationError,Microsoft.Powershell.Commands.GetServiceCommand' } } } @@ -58,7 +58,7 @@ Describe "Get-Service cmdlet tests" -Tags "CI" { $getservicecmd = [Microsoft.PowerShell.Commands.GetServiceCommand]::new() $getservicecmd.$parameter = $value - $getservicecmd.$parameter | Should Be $value + $getservicecmd.$parameter | Should -BeExactly $value } It "Get-Service filtering works for '