Tests/Private/Get-ParentDirectoryPath.Tests.ps1
# Module: TeamsFunctions # Function: Test # Author: David Eberhardt # Updated: 24-JUL-2022 InModuleScope TeamsFunctions { BeforeAll { # } Describe -Tags ('Unit', 'Acceptance') "Function 'Get-ParentDirectoryPath'" { It 'should return the correct Parent Directory Path given a DirectoryName' { $DirectoryName = 'C:\Temp\Test\Subfolder\Level2\Test' $TargetParentDirectory = 'Test' Get-ParentDirectoryPath -DirectoryName $DirectoryName -TargetParentDirectory $TargetParentDirectory | Should -Be 'C:\Temp\Test' } It 'should return the correct Parent Directory Path' { # If DirectoryName is not provided,Get-ParentDirectoryPath will use Get-Location to determine the current directory # This requires manual digging from the current directory path (which may be unknown) $DirectoryName = Get-Location $Parent = Split-Path $DirectoryName -Parent $TargetParentDirectory = Split-Path $Parent -Leaf Get-ParentDirectoryPath -DirectoryName $DirectoryName -TargetParentDirectory $TargetParentDirectory | Should -Be $Parent Get-ParentDirectoryPath -TargetParentDirectory $TargetParentDirectory | Should -Be $Parent } It 'should throw an Error if not found' { # triggering: No directory found in the Folder Path with the Name $DirectoryName = 'C:\' $TargetParentDirectory = 'Test' { Get-ParentDirectoryPath -DirectoryName $DirectoryName -TargetParentDirectory $TargetParentDirectory } | Should -Throw } It 'should throw an Error if not found' { # triggering: Error encountered when splitting paths $DirectoryName = 'C:\Temp\Testing\Subfolder\Level2\Test' $TargetParentDirectory = 'Test' { Get-ParentDirectoryPath -DirectoryName $DirectoryName -TargetParentDirectory $TargetParentDirectory } | Should -Throw } It 'should throw an Error if it cannot split the path' { # triggering: Error encountered when splitting paths $DirectoryName = 'C:\Test' $TargetParentDirectory = 'Test' { Get-ParentDirectoryPath -DirectoryName $DirectoryName -TargetParentDirectory $TargetParentDirectory } | Should -Throw } } } |