2016-04-01 09:50:10 +02:00
|
|
|
|
|
|
|
Describe "Set-Alias DRT Unit Tests" -Tags DRT{
|
|
|
|
It "Set-Alias Invalid Scope Name should throw PSArgumentException"{
|
|
|
|
try {
|
|
|
|
Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus"
|
|
|
|
Throw "Execution OK"
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.SetAliasCommand"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Set-Alias ReadOnly Force"{
|
2016-04-06 10:24:00 +02:00
|
|
|
Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true
|
2016-04-01 09:50:10 +02:00
|
|
|
$result=Get-Alias -Name ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "foo"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "ReadOnly"
|
|
|
|
|
2016-04-06 10:24:00 +02:00
|
|
|
Set-Alias -Name ABCD -Value "foo" -Force:$true
|
2016-04-01 09:50:10 +02:00
|
|
|
$result=Get-Alias -Name ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "foo"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Set-Alias Name And Value Valid"{
|
|
|
|
Set-Alias -Name ABCD -Value "MyCommand"
|
|
|
|
$result=Get-Alias -Name ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "MyCommand"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
It "Set-Alias Name And Value Positional Valid"{
|
|
|
|
Set-Alias -Name ABCD "foo"
|
|
|
|
$result=Get-Alias ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "foo"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
It "Set-Alias Description Valid"{
|
|
|
|
Set-Alias -Name ABCD -Value "MyCommand" -Description "test description"
|
|
|
|
$result=Get-Alias -Name ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "MyCommand"
|
|
|
|
$result.Description| Should Be "test description"
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
It "Set-Alias Scope Valid"{
|
2016-04-06 10:24:00 +02:00
|
|
|
Set-Alias -Name ABCD -Value "localfoo" -scope local -Force:$true
|
|
|
|
Set-Alias -Name ABCD -Value "foo1" -scope "1" -Force:$true
|
2016-04-01 09:50:10 +02:00
|
|
|
|
|
|
|
$result=Get-Alias -Name ABCD
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "localfoo"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
|
|
|
|
$result=Get-Alias -Name ABCD -scope local
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "localfoo"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
|
|
|
|
$result=Get-Alias -Name ABCD -scope "1"
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "foo1"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
It "Set-Alias Expose Bug 1062958, BugId:905449"{
|
|
|
|
try {
|
|
|
|
Set-Alias -Name "ABCD" -Value "foo" -Scope "-1"
|
|
|
|
Throw "Execution OK"
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$_.FullyQualifiedErrorId | Should be "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:48:30 +01:00
|
|
|
Describe "Set-Alias" {
|
|
|
|
Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" }
|
|
|
|
It "Should be able to set alias without error" {
|
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
{ set-alias -Name gd -Value Get-Date } | Should Not Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to have the same output between set-alias and the output of the function being aliased" {
|
2016-03-04 23:52:27 +01:00
|
|
|
set-alias -Name gd -Value Get-Date
|
|
|
|
gd | Should Be $(Get-Date)
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to use the sal alias" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ sal gd Get-Date } | Should Not Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output between the sal alias and the original set-alias cmdlet" {
|
2016-03-04 23:52:27 +01:00
|
|
|
sal -Name gd -Value Get-Date
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
Set-Alias -Name gd2 -Value Get-Date
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
gd2 | Should Be $(gd)
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
}
|