Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Variable.Tests.ps199 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Validate basic Variable provider cmdlets" -Tags "CI" {4    BeforeAll {5        $testVarName = "MyTestVarThatWontConflict"6        $testVarValue = 12347        $testVarDescription = "This is a test variable for provider test purposes."8    }9 10    BeforeEach {11        New-Variable -Name $testVarName -Value $testVarValue -Description $testVarDescription12    }13 14    AfterEach {15        Remove-Variable -Name $testVarName -ErrorAction SilentlyContinue16    }17 18    It "Verify Get-Item" {19        $result = Get-Item "Variable:${testVarName}"20        $result.Name | Should -Be $testVarName21        $result.Value | Should -Be $testVarValue22    }23 24    It "Verify New-Item" {25        $result = New-Item -Name "MyTestVariable" -Value 5 -Path "Variable:"26        $result.Name | Should -Be "MyTestVariable"27        $result.Value | Should -Be 528    }29 30    It "Verify Clear-Item" {31        $valueBefore = (Get-Item "Variable:${testVarName}").Value32        Clear-Item "Variable:${testVarName}"33        $valueAfter = (Get-Item "Variable:${testVarName}").Value34        $valueBefore | Should -Be $testVarValue35        $valueAfter | Should -BeNullOrEmpty36    }37 38    It "Verify Copy-Item" {39        Copy-Item -Path "Variable:${testVarName}" -Destination "Variable:${testVarName}_Copy"40        $original = Get-Item "Variable:${testVarName}"41        $copy = Get-Item "Variable:${testVarName}_Copy"42        $original.Name | Should -Be $testVarName43        $copy.Name | Should -Be "${testVarName}_Copy"44        $original.Value | Should -Be $copy.Value45    }46 47    It "Verify Remove-Item" {48        $existsBefore = Test-Path "Variable:${testVarName}"49        Remove-Item -Path "Variable:${testVarName}"50        $existsAfter = Test-Path "Variable:${testVarName}"51        $existsBefore | Should -BeTrue52        $existsAfter | Should -BeFalse53    }54 55    It "Verify Rename-Item" {56        $existsBefore = Test-Path "Variable:${testVarName}"57        Rename-Item -Path "Variable:${testVarName}" -NewName "${testVarName}_Rename"58        $existsAfter = Test-Path "Variable:${testVarName}"59        $result = Get-Item "Variable:${testVarName}_Rename"60        $existsBefore | Should -BeTrue61        $existsAfter | Should -BeFalse62        $result.Name | Should -Be "${testVarName}_Rename"63        $result.Value | Should -Be $testVarValue64    }65}66 67Describe "Validate basic negative test cases for Variable provider cmdlets" -Tags "Feature" {68    BeforeAll {69        $testVarName = "MyTestVarThatWontConflict"70        $testVarValue = 123471        $testVarDescription = "This is a test variable for provider test purposes."72    }73 74    BeforeEach {75        New-Variable -Name $testVarName -Value $testVarValue -Description $testVarDescription76    }77 78    AfterEach {79        Remove-Variable -Name $testVarName -ErrorAction SilentlyContinue80    }81 82    It "Verify Negative New-Item" {83        { New-Item -Name $testVarName -Value 5 -Path "Variable:" -ErrorAction Stop } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.NewItemCommand"84    }85 86    It "Verify Negative Move-Item" {87        $alreadyExistsVar = 288        { Move-Item -Path "Variable:${testVarName}" -Destination "Variable:alreadyExistsVar" -ErrorAction Stop } | Should -Throw -ErrorId "GetDynamicParametersException,Microsoft.PowerShell.Commands.MoveItemCommand"89    }90 91    It "Verify Negative Invoke-Item" {92        { Invoke-Item -Path "Variable:${testVarName}" -ErrorAction Stop } | Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.InvokeItemCommand"93    }94 95    It "Verify Negative Get-ItemPropertyValue" {96        { Get-ItemPropertyValue -Path "Variable:" -Name $testVarName -ErrorAction Stop } | Should -Throw -ErrorId "NotSupported,Microsoft.PowerShell.Commands.GetItemPropertyValueCommand"97    }98}99