Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Set-Alias.Tests.ps1100 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Set-Alias DRT Unit Tests" -Tags "CI" {5	It "Set-Alias Invalid Scope Name should throw PSArgumentException"{6			{ Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus" } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand"7	}8 9	It "Set-Alias ReadOnly Force"{10			Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true11			$result=Get-Alias -Name ABCD12			$result.Name | Should -BeExactly "ABCD"13			$result.Definition | Should -BeExactly "foo"14			$result.Description | Should -BeNullOrEmpty15			$result.Options | Should -BeExactly "ReadOnly"16 17			Set-Alias -Name ABCD -Value "foo" -Force:$true18			$result=Get-Alias -Name ABCD19			$result.Name | Should -BeExactly "ABCD"20			$result.Definition | Should -BeExactly "foo"21			$result.Description | Should -BeNullOrEmpty22			$result.Options | Should -BeExactly "None"23	}24 25	It "Set-Alias Name And Value Valid"{26			Set-Alias -Name ABCD -Value "MyCommand"27			$result=Get-Alias -Name ABCD28			$result.Name | Should -BeExactly "ABCD"29			$result.Definition | Should -BeExactly "MyCommand"30			$result.Description | Should -BeNullOrEmpty31			$result.Options | Should -BeExactly "None"32	}33	It "Set-Alias Name And Value Positional Valid"{34			Set-Alias -Name ABCD "foo"35			$result=Get-Alias ABCD36			$result.Name | Should -BeExactly "ABCD"37			$result.Definition | Should -BeExactly "foo"38			$result.Description | Should -BeNullOrEmpty39			$result.Options | Should -BeExactly "None"40	}41	It "Set-Alias Description Valid"{42			Set-Alias -Name ABCD -Value "MyCommand" -Description "test description"43			$result=Get-Alias -Name ABCD44			$result.Name | Should -BeExactly "ABCD"45			$result.Definition | Should -BeExactly "MyCommand"46			$result.Description | Should -BeExactly "test description"47			$result.Options | Should -BeExactly "None"48	}49	It "Set-Alias Scope Valid"{50			Set-Alias -Name ABCD -Value "localfoo" -Scope local -Force:$true51			Set-Alias -Name ABCD -Value "foo1" -Scope "1" -Force:$true52 53			$result=Get-Alias -Name ABCD54			$result.Name | Should -BeExactly "ABCD"55			$result.Definition | Should -BeExactly "localfoo"56			$result.Description | Should -BeNullOrEmpty57			$result.Options | Should -BeExactly "None"58 59			$result=Get-Alias -Name ABCD -Scope local60			$result.Name | Should -BeExactly "ABCD"61			$result.Definition | Should -BeExactly "localfoo"62			$result.Description | Should -BeNullOrEmpty63			$result.Options | Should -BeExactly "None"64 65			$result=Get-Alias -Name ABCD -Scope "1"66			$result.Name | Should -BeExactly "ABCD"67			$result.Definition | Should -BeExactly "foo1"68			$result.Description | Should -BeNullOrEmpty69			$result.Options | Should -BeExactly "None"70	}71	It "Set-Alias Expose Bug 1062958, BugId:905449"{72			{ Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand"73	}74}75 76Describe "Set-Alias" -Tags "CI" {77    Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" }78    It "Should be able to set alias without error" {79 80	{ Set-Alias -Name gd -Value Get-Date } | Should -Not -Throw81    }82 83    It "Should be able to have the same output between set-alias and the output of the function being aliased" {84	Set-Alias -Name gd -Value Get-Date85	gd | Should -Be $(Get-Date)86    }87 88    It "Should be able to use the sal alias" {89	{ sal gd Get-Date } | Should -Not -Throw90    }91 92    It "Should have the same output between the sal alias and the original set-alias cmdlet" {93	sal -Name gd -Value Get-Date94 95	Set-Alias -Name gd2 -Value Get-Date96 97	gd2 | Should -Be $(gd)98    }99}100