111 lines
5.8 KiB
PowerShell
111 lines
5.8 KiB
PowerShell
|
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||
|
. "$here.ps1"
|
||
|
|
||
|
Describe "Process" {
|
||
|
Mock -CommandName Get-EnvironmentVariable -MockWith { throw 'Asked for non-Process paths' }
|
||
|
Mock -CommandName Set-EnvironmentVariable -MockWith { throw 'Should not set non-Process paths' }
|
||
|
|
||
|
Context "Append 1 Remove 1" {
|
||
|
Mock -CommandName Get-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith { return "path1;path2" }
|
||
|
Mock -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith {
|
||
|
$Value | Should -Be "path2;path3"
|
||
|
}
|
||
|
|
||
|
It 'Does not throw' {
|
||
|
{ Set-PathVariable -StoreName 'Machine' -Append 'path3' -Remove 'path1' } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'User' } -Times 0
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -Times 1
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Process' } -Times 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Prepend 1 Remove 1" {
|
||
|
Mock -CommandName Get-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith { return "path1;path2" }
|
||
|
Mock -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith {
|
||
|
$Value | Should -Be "path3;path2"
|
||
|
}
|
||
|
|
||
|
It 'Does not throw' {
|
||
|
{ Set-PathVariable -StoreName 'Machine' -Prepend 'path3' -Remove 'path1' } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'User' } -Times 0
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -Times 1
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Process' } -Times 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Append 5 Remove 5 with strings that don't exist in the first path" {
|
||
|
Mock -CommandName Get-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith { return "path1;path2" }
|
||
|
Mock -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith {
|
||
|
# remove then add, so any adds should be there even if the remove says to remove them
|
||
|
$Value | Should -Be "path10;path11;path12;path13;path14"
|
||
|
}
|
||
|
|
||
|
It 'Does not throw' {
|
||
|
{ Set-PathVariable -StoreName 'Machine' -Append 'path10','path11','path12','path13','path14' -Remove 'path1','path2','path10','path11','path14' } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'User' } -Times 0
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -Times 1
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Process' } -Times 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Append 3 Remove 5 with a weird collection" {
|
||
|
Mock -CommandName Get-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith { return "path14;path13;path10;path11;path12;path1;path2" }
|
||
|
Mock -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -MockWith {
|
||
|
# remove then add, so any adds should be there even if the remove says to remove them
|
||
|
$Value | Should -Be "path13;path12;path10;path11;path14"
|
||
|
}
|
||
|
|
||
|
It 'Does not throw' {
|
||
|
{ Set-PathVariable -StoreName 'Machine' -Append 'path10','path11','path14' -Remove 'path1','path2','path10','path11','path14' } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'User' } -Times 0
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Machine' } -Times 1
|
||
|
}
|
||
|
|
||
|
It 'Called the Set-EnvironmentVariable correctly' {
|
||
|
Assert-MockCalled -CommandName Set-EnvironmentVariable -ParameterFilter { $Name -eq 'Path' -and $StoreName -eq 'Process' } -Times 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context 'It is gonna throw!' {
|
||
|
It 'Throws for User!' {
|
||
|
{ Set-PathVariable -StoreName 'User' -Append 'path10','path11','path14' -Remove 'path1','path2','path10','path11','path14' } | Should -Throw
|
||
|
}
|
||
|
|
||
|
It 'Throws for Process!' {
|
||
|
{ Set-PathVariable -StoreName 'Process' -Append 'path10','path11','path14' -Remove 'path1','path2','path10','path11','path14' } | Should -Throw
|
||
|
}
|
||
|
}
|
||
|
}
|