Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
Remove-Alias.Tests.ps166 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Remove-Alias" -Tags "CI" {4 5    BeforeAll {6        $testAliasName = (New-Guid).Guid7    }8 9    It "Remove-Alias should remove a non-readonly alias"{10        {11            Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop12            Remove-Alias -Name $testAliasName -ErrorAction Stop13            Get-Alias -Name $testAliasName -ErrorAction Stop14        } | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'15    }16 17    It "Remove-Alias should throw on a readonly alias"{18        {19            Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop20            Remove-Alias -Name $testAliasName -ErrorAction Stop21        } | Should -Throw -ErrorId 'AliasNotRemovable,Microsoft.PowerShell.Commands.RemoveAliasCommand'22    }23 24    It "Remove-Alias should remove a non-readonly alias with force"{25        {26            Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop27            Remove-Alias -Name $testAliasName -Force -ErrorAction Stop28            Get-Alias -Name $testAliasName -ErrorAction Stop29        } | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'30    }31 32    It "Remove-Alias should remove a readonly alias with force"{33        {34            Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop35            Remove-Alias -Name $testAliasName -Force -ErrorAction Stop36            Get-Alias -Name $testAliasName -ErrorAction Stop37        } | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'38    }39 40    It "Remove-Alias should throw if alias does not exist"{41        {42            Get-Alias -Name $testAliasName -ErrorAction SilentlyContinue | Should -BeNullOrEmpty43            Remove-Alias -Name $testAliasName -ErrorAction Stop44        } | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.RemoveAliasCommand'45    }46 47    It "Remove-Alias should remove multiple alias at once"{48        {49            Set-Alias -Name "$testAliasName" -Value "Remove-Alias" -ErrorAction Stop50            Set-Alias -Name "$testAliasName-2" -Value "Remove-Alias" -ErrorAction Stop51            Set-Alias -Name "$testAliasName-3" -Value "Remove-Alias" -ErrorAction Stop52            Remove-Alias -Name "$testAliasName","$testAliasName-2","$testAliasName-3" -ErrorAction Stop53            Get-Alias -Name "$testAliasName" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'54            Get-Alias -Name "$testAliasName-2" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'55            Get-Alias -Name "$testAliasName-3" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'56        }57    }58 59    It "Remove-Alias should throw on out-of-range scope"{60        {61            Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop62            Remove-Alias -Name $testAliasName -Scope 99999 -ErrorAction Stop63        } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.RemoveAliasCommand"64    }65}66