/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/powershell/Modules/Microsoft.PowerShell.Utility/Remove-Alias.Tests.ps1
65 строк
3 KB
Steve Lee
Update copyright notice to latest guidance (#12190)
24 мар 2020, 21:08
Не верифицирован
24 мар 2020, 21:08
b7cb335
Код
Авторство
О чём код?
# Copyright (c) Microsoft Corporation. # 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" } }