2016-04-06 08:24:00 +00:00
|
|
|
Describe "New-Alias DRT Unit Tests" -Tags DRT{
|
2016-04-19 09:46:36 +00:00
|
|
|
It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{
|
2016-04-06 08:24:00 +00:00
|
|
|
try {
|
|
|
|
New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true
|
2016-04-19 09:46:36 +00:00
|
|
|
New-Alias -Name "ABCD" -Value "foo" -Force:$true -ErrorAction Stop
|
2016-04-06 08:24:00 +00:00
|
|
|
Throw "Execution OK"
|
|
|
|
}
|
|
|
|
catch {
|
2016-04-19 09:46:36 +00:00
|
|
|
$_.CategoryInfo| Should Match "SessionStateUnauthorizedAccessException"
|
2016-04-06 08:24:00 +00:00
|
|
|
$_.FullyQualifiedErrorId | Should be "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
It "New-Alias NamePositional And Value Valid" {
|
|
|
|
New-Alias ABCD -Value "MyCommand" -Scope "0"
|
|
|
|
$result=Get-Alias -Name ABCD -Scope "0"
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "MyCommand"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
|
|
|
|
It "New-Alias NamePositional And ValuePositional Valid" {
|
|
|
|
New-Alias ABCD "MyCommand" -Scope "0"
|
|
|
|
$result=Get-Alias -Name ABCD -Scope "0"
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "MyCommand"
|
|
|
|
$result.Description| Should Be ""
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
|
|
|
|
It "New-Alias Description Valid" {
|
|
|
|
New-Alias -Name ABCD -Value "MyCommand" -Description "test description" -Scope "0"
|
|
|
|
$result=Get-Alias -Name ABCD -Scope "0"
|
|
|
|
$result.Name| Should Be "ABCD"
|
|
|
|
$result.Definition| Should Be "MyCommand"
|
|
|
|
$result.Description| Should Be "test description"
|
|
|
|
$result.Options| Should Be "None"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:48:30 +00:00
|
|
|
Describe "New-Alias" {
|
2015-10-22 17:55:58 +00:00
|
|
|
It "Should be able to be called using the name and value parameters without error" {
|
2016-03-04 22:52:27 +00:00
|
|
|
{ New-Alias -Name testAlias -Value 100 } | Should Not Throw
|
2015-10-22 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output between the alias and the original cmdlet" {
|
2016-04-25 21:41:17 +00:00
|
|
|
New-Alias -Name testAlias -Value Get-Command
|
2015-10-22 17:55:58 +00:00
|
|
|
|
2016-03-04 22:52:27 +00:00
|
|
|
$aliasId = $(testAlias).Id
|
2016-04-25 21:41:17 +00:00
|
|
|
$cmdletId = $(Get-Command).Id
|
2016-03-04 22:52:27 +00:00
|
|
|
foreach ($IdNumber in $aliasId)
|
|
|
|
{
|
|
|
|
$aliasId[$IdNumber] | Should Be $cmdletId[$IdNumber]
|
|
|
|
}
|
2015-10-22 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to call the New-Alias cmdlet using the nal alias without error" {
|
2016-03-04 22:52:27 +00:00
|
|
|
{ nal -Name testAlias -Value 100 } | Should Not Throw
|
2015-10-22 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output between the nal alias and the New-Alias cmdlet" {
|
2016-04-25 21:41:17 +00:00
|
|
|
nal -Name testAlias -Value Get-Command
|
2015-10-22 17:55:58 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
New-Alias -Name testalias2 -Value Get-Command
|
2015-10-22 17:55:58 +00:00
|
|
|
|
2016-03-04 22:52:27 +00:00
|
|
|
$aliasData = $(testAlias).Id
|
|
|
|
$cmdletData = $(testAlias2).Id
|
|
|
|
|
|
|
|
foreach ($IdNumber in $aliasData)
|
|
|
|
{
|
|
|
|
$aliasData[$IdNumber] | Should Be $cmdletData[$IdNumber]
|
|
|
|
}
|
2015-10-22 17:55:58 +00:00
|
|
|
}
|
2016-03-04 22:48:30 +00:00
|
|
|
}
|