Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1
T
Raphael c9f83fecfc Add Remove-Alias Command (#5143)
* Add Remove-Alias Command. Add Remove-Alias Test. Add Remove-Alias to .psd1.

* Fix code-formatting. Fix ErrorAction on Remove-Alias instead of preference variable. Remove unnecessary Get-Alias calls. Switch Force parameter to auto property. Add ValueFromPipeline to Remove-Alias Name parameter.

* Remove empty lines. Add Remove-Alias to Unix Module .psd1. Add Remove-Alias to approved Commands test. Remove Try/Catch for SessionstateException. Add WriteError for aliasnotfound exception.

* Add ErrorAction Stop to all Get-Alias and Set-Alias Cmdlets in all tests for consistency. Add Should BeNullOrEmpty to "should throw if alias does not exist" test to verify that foo alias really is not there before removing it.

* Changed Remove-Alias parameter Name to String-Array. Changed Cmdlet Process Logic to work with String Array. Added Alias named "ral". Added test case for Alias "ral". Added "ral" Alias to list of approved Aliases. Replaced foo and bar values in all tests with better names.

* Remove "ral"-alias test as this is covered in DefaultCommands.Tests.ps1. Add test for removing multiple alias at once. Fix wrong curly braces positioning.

* Remove $FullCLR in DefaultCommands.Tests.ps1 for Remove-Alias and "ral" alias.

* Add Alias "ral" to Remove-Alias Cmdlet.

* Remove "ral" alias as this is handled by using the [Alias()] attribute on the Remove-Alias Cmdlet.

* Replace alias names used in Remove-Alias Cmdlet tests with GUIDs to avoid collisions
2017-11-03 12:08:37 +04:00

64 lines
3.1 KiB
PowerShell

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
} | ShouldBeErrorId '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
} | ShouldBeErrorId '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
} | ShouldBeErrorId '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
} | ShouldBeErrorId '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
} | ShouldBeErrorId '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 | ShouldBeErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
Get-Alias -Name "$testAliasName-2" -ErrorAction Stop | ShouldBeErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
Get-Alias -Name "$testAliasName-3" -ErrorAction Stop | ShouldBeErrorId '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
} | ShouldBeErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.RemoveAliasCommand"
}
}