MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "New-Alias DRT Unit Tests" -Tags "CI" {4 It "New-Alias Constant should throw SessionStateUnauthorizedAccessException"{5 New-Alias -Name "ABCD" -Value "foo" -Option "Constant" -Force:$true6 $e = { New-Alias -Name "ABCD" -Value "foo" -Force:$true -Scope 1 -ErrorAction Stop } |7 Should -Throw -ErrorId "AliasNotWritable,Microsoft.PowerShell.Commands.NewAliasCommand" -PassThru8 $e.CategoryInfo | Should -Match "SessionStateUnauthorizedAccessException"9 }10 11 It "New-Alias NamePositional And Value Valid" {12 New-Alias ABCD -Value "MyCommand" -Scope "0"13 $result=Get-Alias -Name ABCD -Scope "0"14 $result.Name | Should -BeExactly "ABCD"15 $result.Definition | Should -BeExactly "MyCommand"16 $result.Description | Should -BeNullOrEmpty17 $result.Options | Should -BeExactly "None"18 }19 20 It "New-Alias NamePositional And ValuePositional Valid" {21 New-Alias ABCD "MyCommand" -Scope "0"22 $result=Get-Alias -Name ABCD -Scope "0"23 $result.Name | Should -BeExactly "ABCD"24 $result.Definition | Should -BeExactly "MyCommand"25 $result.Description | Should -BeNullOrEmpty26 $result.Options | Should -BeExactly "None"27 }28 29 It "New-Alias Description Valid" {30 New-Alias -Name ABCD -Value "MyCommand" -Description "test description" -Scope "0"31 $result=Get-Alias -Name ABCD -Scope "0"32 $result.Name | Should -BeExactly "ABCD"33 $result.Definition | Should -BeExactly "MyCommand"34 $result.Description | Should -BeExactly "test description"35 $result.Options | Should -BeExactly "None"36 }37}38 39Describe "New-Alias" -Tags "CI" {40 It "Should be able to be called using the name and value parameters without error" {41 { New-Alias -Name testAlias -Value 100 } | Should -Not -Throw42 }43 44 It "Should have the same output between the alias and the original cmdlet" {45 New-Alias -Name testAlias -Value Get-Command46 47 $aliasId = $(testAlias).Id48 $cmdletId = $(Get-Command).Id49 foreach ($IdNumber in $aliasId)50 {51 $aliasId[$IdNumber] | Should -Be $cmdletId[$IdNumber]52 }53 }54 55 It "Should be able to call the New-Alias cmdlet using the nal alias without error" {56 { nal -Name testAlias -Value 100 } | Should -Not -Throw57 }58 59 It "Should have the same output between the nal alias and the New-Alias cmdlet" {60 nal -Name testAlias -Value Get-Command61 62 New-Alias -Name testalias2 -Value Get-Command63 64 $aliasData = $(testAlias).Id65 $cmdletData = $(testAlias2).Id66 67 foreach ($IdNumber in $aliasData)68 {69 $aliasData[$IdNumber] | Should -Be $cmdletData[$IdNumber]70 }71 }72}73 