Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1
T
Klaudia Algiz 2df9aac811 Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests (#6682)
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
2018-05-17 14:42:04 -07:00

66 lines
3.3 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Remove-Alias" -Tags "CI" {
BeforeAll {
$testAliasName = (New-Guid).Guid
}
It "Remove-Alias should remove a non-readonly alias"{
{
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
Remove-Alias -Name $testAliasName -ErrorAction Stop
Get-Alias -Name $testAliasName -ErrorAction Stop
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
}
It "Remove-Alias should throw on a readonly alias"{
{
Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop
Remove-Alias -Name $testAliasName -ErrorAction Stop
} | Should -Throw -ErrorId 'AliasNotRemovable,Microsoft.PowerShell.Commands.RemoveAliasCommand'
}
It "Remove-Alias should remove a non-readonly alias with force"{
{
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
Remove-Alias -Name $testAliasName -Force -ErrorAction Stop
Get-Alias -Name $testAliasName -ErrorAction Stop
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
}
It "Remove-Alias should remove a readonly alias with force"{
{
Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop
Remove-Alias -Name $testAliasName -Force -ErrorAction Stop
Get-Alias -Name $testAliasName -ErrorAction Stop
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
}
It "Remove-Alias should throw if alias does not exist"{
{
Get-Alias -Name $testAliasName -ErrorAction SilentlyContinue | Should -BeNullorEmpty
Remove-Alias -Name $testAliasName -ErrorAction Stop
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.RemoveAliasCommand'
}
It "Remove-Alias should remove multiple alias at once"{
{
Set-Alias -Name "$testAliasName" -Value "Remove-Alias" -ErrorAction Stop
Set-Alias -Name "$testAliasName-2" -Value "Remove-Alias" -ErrorAction Stop
Set-Alias -Name "$testAliasName-3" -Value "Remove-Alias" -ErrorAction Stop
Remove-Alias -Name "$testAliasName","$testAliasName-2","$testAliasName-3" -ErrorAction Stop
Get-Alias -Name "$testAliasName" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
Get-Alias -Name "$testAliasName-2" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
Get-Alias -Name "$testAliasName-3" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
}
}
It "Remove-Alias should throw on out-of-range scope"{
{
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
Remove-Alias -Name $testAliasName -Scope 99999 -ErrorAction Stop
} | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.RemoveAliasCommand"
}
}