Skip to content

Instantly share code, notes, and snippets.

@Xainey
Last active March 11, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xainey/518cbf12dd99be176076 to your computer and use it in GitHub Desktop.
Save Xainey/518cbf12dd99be176076 to your computer and use it in GitHub Desktop.
Resolving paths in Pester TestDrive
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