Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Basic Alias Provider Tests" -Tags "CI" {4    BeforeAll {5        $testAliasName = "TestAlias"6        $testAliasValue = "Get-Date"7    }8 9    BeforeEach {10        New-Item -Path "Alias:\" -Name $testAliasName -Value $testAliasValue > $null11    }12 13    AfterEach {14        Remove-Item -Path "Alias:\${testAliasName}" -Force -ErrorAction SilentlyContinue15    }16 17    It "Test number of alias not Zero" {18        $aliases = @(Get-ChildItem "Alias:\")19        $aliases.Count | Should -Not -Be 020    }21 22    It "Test alias dir" {23        $dirAlias = Get-Item "Alias:\dir"24        $dirAlias.CommandType | Should -BeExactly "Alias"25        $dirAlias.Name | Should -BeExactly "dir"26        $dirAlias.Definition | Should -BeExactly "Get-ChildItem"27    }28 29    It "Test creating new alias" {30        try {31            $newAlias = New-Item -Path "Alias:\" -Name "NewTestAlias" -Value $testAliasValue32            $newAlias.CommandType | Should -BeExactly "Alias"33            $newAlias.Name | Should -BeExactly "NewTestAlias"34            $newAlias.Definition | Should -BeExactly $testAliasValue35        }36        finally {37            Remove-Item -Path "Alias:\NewTestAlias" -Force -ErrorAction SilentlyContinue38        }39    }40 41    It "Test Get-Item on alias provider" {42        $alias = Get-Item -Path "Alias:\${testAliasName}"43        $alias.CommandType | Should -BeExactly "Alias"44        $alias.Name | Should -BeExactly $testAliasName45        $alias.Definition | Should -BeExactly $testAliasValue46    }47 48    It "Test Test-Path on alias provider" {49        $aliasExists = Test-Path "Alias:\testAlias"50        $aliasExists | Should -BeTrue51    }52 53    It "Test executing the new alias" {54        $result = Invoke-Expression $testAliasName55        $result | Should -BeOfType DateTime56    }57}58 59Describe "Extended Alias Provider Tests" -Tags "Feature" {60    Context "Valdiation of Set-Item parameters for the Alias Provider" {61        BeforeAll {62            $testAliasName = "TestAlias"63            $testAliasName2 = "TestAlias2"64            $testAliasValue = "Get-Date"65        }66 67        BeforeEach {68            New-Item -Path Alias:\ -Name $testAliasName -Value $testAliasValue > $null69            New-Item -Path Alias:\ -Name $testAliasName2 -Value $testAliasValue > $null70        }71 72        AfterEach {73            Remove-Item -Path "Alias:\${testAliasName}" -Force -ErrorAction SilentlyContinue74            Remove-Item -Path "Alias:\${testAliasName2}" -Force -ErrorAction SilentlyContinue75        }76 77        It "Verifying Whatif" {78            $before = (Get-Item -Path "Alias:\${testAliasName}").Definition79            Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -WhatIf80            $after = (Get-Item -Path "Alias:\${testAliasName}").Definition81            $after | Should -BeExactly $before # Definition should not have changed82        }83 84        It "Verifying Confirm can be bypassed" {85            Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Confirm:$false86            $result = Get-Item -Path "Alias:\${testAliasName}"87            $result.Definition | Should -BeExactly "Get-Location"88        }89 90        It "Verifying Force" {91            Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Force92            $result =  Get-Item -Path "Alias:\${testAliasName}"93            $result.Definition | Should -BeExactly "Get-Location"94        }95 96        It "Verifying Include" {97            Set-Item -Path "Alias:\*" -Value "Get-Location" -Include "TestAlias*"98            $alias1 = Get-Item -Path "Alias:\${testAliasName}"99            $alias2 = Get-Item -Path "Alias:\${testAliasName2}"100            $alias1.Definition | Should -BeExactly "Get-Location"101            $alias2.Definition | Should -BeExactly "Get-Location"102        }103 104        It "Verifying Exclude" {105            Set-Item -Path "Alias:\TestAlias*" -Value "Get-Location" -Exclude "*2"106            $alias1 = Get-Item -Path "Alias:\${testAliasName}"107            $alias2 = Get-Item -Path "Alias:\${testAliasName2}"108            $alias1.Definition | Should -BeExactly "Get-Location"109            $alias2.Definition | Should -BeExactly "Get-Date"110        }111    }112}113