Tests/Environment/Set-EnvironmentVariable.Tests.ps1
|
BeforeAll { Set-StrictMode -Version "Latest" . "$PSScriptRoot\..\..\Source\Environment\Set-EnvironmentVariable.ps1" } Describe "Set-EnvironmentVariable" { AfterEach { [Environment]::SetEnvironmentVariable("ToolboxTestVariable", $null, "Process") } It "Sets the value of a Process-scoped variable" { Set-EnvironmentVariable -Name "ToolboxTestVariable" -Value "ToolboxTestValue" -Scope "Process" [Environment]::GetEnvironmentVariable("ToolboxTestVariable", "Process") | Should -Be "ToolboxTestValue" } It "Does nothing under -WhatIf" { Set-EnvironmentVariable -Name "ToolboxTestVariable" -Value "ToolboxTestValue" -Scope "Process" -WhatIf [Environment]::GetEnvironmentVariable("ToolboxTestVariable", "Process") | Should -BeNullOrEmpty } It "Accepts Name and Value from the pipeline by property name" { [pscustomobject]@{ Name = "ToolboxTestVariable"; Value = "ToolboxTestValue" } | Set-EnvironmentVariable -Scope "Process" [Environment]::GetEnvironmentVariable("ToolboxTestVariable", "Process") | Should -Be "ToolboxTestValue" } } |