Files

99 lines
3.5 KiB
PowerShell
Raw Permalink Normal View History

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
2016-04-01 00:50:10 -07:00
2016-07-25 14:01:41 -07:00
Describe "Set-Alias DRT Unit Tests" -Tags "CI" {
2017-01-16 13:31:14 -08:00
It "Set-Alias Invalid Scope Name should throw PSArgumentException"{
{ Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus" } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand"
2016-04-01 00:50:10 -07:00
}
2017-01-16 13:31:14 -08:00
2016-04-01 00:50:10 -07:00
It "Set-Alias ReadOnly Force"{
Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true
2016-04-01 00:50:10 -07:00
$result=Get-Alias -Name ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "foo"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "ReadOnly"
2017-01-16 13:31:14 -08:00
Set-Alias -Name ABCD -Value "foo" -Force:$true
2016-04-01 00:50:10 -07:00
$result=Get-Alias -Name ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "foo"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2016-04-01 00:50:10 -07:00
}
2017-01-16 13:31:14 -08:00
2016-04-01 00:50:10 -07:00
It "Set-Alias Name And Value Valid"{
2017-01-16 13:31:14 -08:00
Set-Alias -Name ABCD -Value "MyCommand"
2016-04-01 00:50:10 -07:00
$result=Get-Alias -Name ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "MyCommand"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2016-04-01 00:50:10 -07:00
}
It "Set-Alias Name And Value Positional Valid"{
2017-01-16 13:31:14 -08:00
Set-Alias -Name ABCD "foo"
2016-04-01 00:50:10 -07:00
$result=Get-Alias ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "foo"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2016-04-01 00:50:10 -07:00
}
It "Set-Alias Description Valid"{
2017-01-16 13:31:14 -08:00
Set-Alias -Name ABCD -Value "MyCommand" -Description "test description"
2016-04-01 00:50:10 -07:00
$result=Get-Alias -Name ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "MyCommand"
$result.Description | Should -BeExactly "test description"
$result.Options | Should -BeExactly "None"
2016-04-01 00:50:10 -07:00
}
It "Set-Alias Scope Valid"{
Set-Alias -Name ABCD -Value "localfoo" -Scope local -Force:$true
Set-Alias -Name ABCD -Value "foo1" -Scope "1" -Force:$true
2017-01-16 13:31:14 -08:00
2016-04-01 00:50:10 -07:00
$result=Get-Alias -Name ABCD
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "localfoo"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2017-01-16 13:31:14 -08:00
$result=Get-Alias -Name ABCD -Scope local
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "localfoo"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2017-01-16 13:31:14 -08:00
$result=Get-Alias -Name ABCD -Scope "1"
2020-01-11 15:41:59 +00:00
$result.Name | Should -BeExactly "ABCD"
$result.Definition | Should -BeExactly "foo1"
$result.Description | Should -BeNullOrEmpty
$result.Options | Should -BeExactly "None"
2016-04-01 00:50:10 -07:00
}
It "Set-Alias Expose Bug 1062958, BugId:905449"{
{ Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand"
2016-04-01 00:50:10 -07:00
}
}
2016-07-25 14:01:41 -07:00
Describe "Set-Alias" -Tags "CI" {
2016-03-04 14:48:30 -08:00
Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" }
It "Should be able to set alias without error" {
{ Set-Alias -Name gd -Value Get-Date } | Should -Not -Throw
2016-03-04 14:48:30 -08:00
}
It "Should be able to have the same output between set-alias and the output of the function being aliased" {
Set-Alias -Name gd -Value Get-Date
gd | Should -Be $(Get-Date)
2016-03-04 14:48:30 -08:00
}
It "Should be able to use the sal alias" {
{ sal gd Get-Date } | Should -Not -Throw
2016-03-04 14:48:30 -08:00
}
It "Should have the same output between the sal alias and the original set-alias cmdlet" {
sal -Name gd -Value Get-Date
2016-03-04 14:48:30 -08:00
Set-Alias -Name gd2 -Value Get-Date
2016-03-04 14:48:30 -08:00
gd2 | Should -Be $(gd)
2016-03-04 14:48:30 -08:00
}
}