Last active
March 11, 2016 20:31
-
-
Save Xainey/518cbf12dd99be176076 to your computer and use it in GitHub Desktop.
Resolving paths in Pester TestDrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-Shortcut | |
{ | |
[CmdletBinding()] | |
param ( | |
[string] $ShortcutPath, | |
[string] $TargetPath | |
) | |
$WshShell = New-Object -ComObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($PSCmdlet.GetUnresolvedProviderPathFromPSPath($ShortcutPath)) | |
$Shortcut.TargetPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($TargetPath) | |
$Shortcut.Save() | |
} | |
function Get-Target | |
{ | |
[CmdletBinding()] | |
param ( | |
[string] $ShortcutPath | |
) | |
$WshShell = New-Object -ComObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($PSCmdlet.GetUnresolvedProviderPathFromPSPath($ShortcutPath)) | |
return $Shortcut.TargetPath | |
} | |
Describe 'TargetPath' { | |
BeforeAll { | |
$ShortcutPath = 'TestDrive:\Notepad.lnk' | |
$TargetPath = 'C:\Windows\System32\notepad.exe' | |
Set-Shortcut -ShortcutPath $ShortcutPath -TargetPath $TargetPath | |
} | |
Context 'ProviderPath' { | |
It 'Exists' { | |
$ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk' | |
$ShortcutPath | Should Exist | |
} | |
It 'Has the correct targetPath' { | |
$ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk' | |
$TargetPath = 'C:\Windows\System32\notepad.exe' | |
Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath | |
} | |
} | |
Context 'TestDrive' { | |
It 'Exists' { | |
$ShortcutPath = 'TestDrive:\Notepad.lnk' | |
$ShortcutPath | Should Exist | |
} | |
It 'Has the correct targetPath' { | |
$ShortcutPath = 'TestDrive:\Notepad.lnk' | |
$TargetPath = 'C:\Windows\System32\notepad.exe' | |
Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment