From b5a1775bb054cccccaa1340dbc199dcea982d88d Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Tue, 27 Jun 2017 14:11:27 -0700 Subject: [PATCH] Archive: Added handling for directory archive entries that end in a foward slash --- .gitignore | 1 + DscResources/MSFT_Archive/MSFT_Archive.psm1 | 33 +- README.md | 3 + Tests/Unit/MSFT_Archive.Tests.ps1 | 546 +++++++++++++++++--- 4 files changed, 512 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index b03606a..5f4aabe 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ DSCResource.Tests +*.vscode diff --git a/DscResources/MSFT_Archive/MSFT_Archive.psm1 b/DscResources/MSFT_Archive/MSFT_Archive.psm1 index 257b186..51049ea 100644 --- a/DscResources/MSFT_Archive/MSFT_Archive.psm1 +++ b/DscResources/MSFT_Archive/MSFT_Archive.psm1 @@ -12,6 +12,9 @@ $script:dscResourcesFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonResourceHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'CommonResourceHelper.psm1' Import-Module -Name $script:commonResourceHelperFilePath +# Import Microsoft.PowerShell.Utility for Get-FileHash +Import-Module -Name 'Microsoft.PowerShell.Utility' + # Localized messages for verbose and error statements in this resource $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_Archive' @@ -1083,6 +1086,28 @@ function Test-FileMatchesArchiveEntryByChecksum return $fileMatchesArchiveEntry } +<# + .SYNOPSIS + Tests if the given archive entry name represents a directory. + + .PARAMETER ArchiveEntryName + The archive entry name to test. +#> +function Test-ArchiveEntryIsDirectory +{ + [OutputType([Boolean])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [String] + $ArchiveEntryName + ) + + return $ArchiveEntryName.EndsWith('\') -or $ArchiveEntryName.EndsWith('/') +} + <# .SYNOPSIS Tests if the specified archive exists in its expanded form at the destination. @@ -1150,7 +1175,7 @@ function Test-ArchiveExistsAtDestination { Write-Verbose -Message ($script:localizedData.ItemWithArchiveEntryNameExists -f $archiveEntryPathAtDestination) - if ($archiveEntryFullName.EndsWith('\')) + if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName) { if (-not ($archiveEntryItemAtDestination -is [System.IO.DirectoryInfo])) { @@ -1261,7 +1286,7 @@ function Copy-ArchiveEntryToDestination $archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $ArchiveEntry - if ($archiveEntryFullName.EndsWith('\')) + if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName) { $null = New-Item -Path $DestinationPath -ItemType 'Directory' } @@ -1361,7 +1386,7 @@ function Expand-ArchiveToDestination $archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $archiveEntry $archiveEntryPathAtDestination = Join-Path -Path $Destination -ChildPath $archiveEntryFullName - $archiveEntryIsDirectory = $archiveEntryFullName.EndsWith('\') + $archiveEntryIsDirectory = Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName $archiveEntryItemAtDestination = Get-Item -LiteralPath $archiveEntryPathAtDestination -ErrorAction 'SilentlyContinue' @@ -1533,7 +1558,7 @@ function Remove-ArchiveFromDestination $archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $archiveEntry $archiveEntryPathAtDestination = Join-Path -Path $Destination -ChildPath $archiveEntryFullName - $archiveEntryIsDirectory = $archiveEntryFullName.EndsWith('\') + $archiveEntryIsDirectory = Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName $itemAtDestination = Get-Item -LiteralPath $archiveEntryPathAtDestination -ErrorAction 'SilentlyContinue' diff --git a/README.md b/README.md index 15d73fe..154acbc 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,9 @@ The following parameters will be the same for each process in the set: ### Unreleased +* Archive: + * Added handling of directory archive entries that end with a foward slash + ### 2.7.0.0 * MsiPackage diff --git a/Tests/Unit/MSFT_Archive.Tests.ps1 b/Tests/Unit/MSFT_Archive.Tests.ps1 index 001e6f6..266ef98 100644 --- a/Tests/Unit/MSFT_Archive.Tests.ps1 +++ b/Tests/Unit/MSFT_Archive.Tests.ps1 @@ -1585,7 +1585,7 @@ Describe 'Archive Unit Tests' { } } - Mock -CommandName 'Test-Path' -MockWith { return $false } + Mock -CommandName 'Test-Path' -MockWith {return $false } Context 'Specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation fails' { $mountPSDriveWithCredentialParameters = @{ @@ -2407,9 +2407,80 @@ Describe 'Archive Unit Tests' { } } + Describe 'Test-ArchiveEntryIsDirectory' { + Context 'Archive entry name does not contain a backslash or a foward slash' { + $testArchiveEntryNameIsDirectoryPathParameters = @{ + ArchiveEntryName = 'TestArchiveEntryName' + } + + It 'Should not throw' { + { $null = Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters } | Should Not Throw + } + + It 'Should return false' { + Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $false + } + } + + Context 'Archive entry name contains a backslash but does not end with a backslash' { + $testArchiveEntryNameIsDirectoryPathParameters = @{ + ArchiveEntryName = 'TestArchive\EntryName' + } + + It 'Should not throw' { + { $null = Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters } | Should Not Throw + } + + It 'Should return false' { + Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $false + } + } + + Context 'Archive entry name contains a foward slash but does not end with a foward slash' { + $testArchiveEntryNameIsDirectoryPathParameters = @{ + ArchiveEntryName = 'TestArchive/EntryName' + } + + It 'Should not throw' { + { $null = Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters } | Should Not Throw + } + + It 'Should return false' { + Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $false + } + } + + Context 'Archive entry name ends with a backslash' { + $testArchiveEntryNameIsDirectoryPathParameters = @{ + ArchiveEntryName = 'TestArchiveEntryName\' + } + + It 'Should not throw' { + { $null = Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters } | Should Not Throw + } + + It 'Should return true' { + Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $true + } + } + + Context 'Archive entry name ends with a forward slash' { + $testArchiveEntryNameIsDirectoryPathParameters = @{ + ArchiveEntryName = 'TestArchiveEntryName/' + } + + It 'Should not throw' { + { $null = Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters } | Should Not Throw + } + + It 'Should return true' { + Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $true + } + } + } + Describe 'Test-ArchiveExistsAtDestination' { - $testArchiveEntryFullNameWithBackslash = 'TestArchiveEntryFullName\' - $testArchiveEntryFullNameNoBackslash = 'TestArchiveEntryFullName' + $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testItemPathAtDestination = 'TestItemPathAtDestination' $testParentDirectoryPath = 'TestParentDirectoryPath' @@ -2420,9 +2491,10 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameWithBackslash } + Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } Mock -CommandName 'Join-Path' -MockWith { return $testItemPathAtDestination } Mock -CommandName 'Get-Item' -MockWith { return $null } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $true } Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $false } Mock -CommandName 'Close-Archive' -MockWith { } @@ -2466,7 +2538,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2483,6 +2555,10 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should not attempt to test if the archive entry is a directory' { + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -Exactly 0 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2543,7 +2619,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2560,6 +2636,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2620,7 +2705,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2637,6 +2722,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2702,7 +2796,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2719,6 +2813,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2737,7 +2840,7 @@ Describe 'Archive Unit Tests' { } } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameNoBackslash } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } Mock -CommandName 'Get-Item' -MockWith { return $null } Context 'Archive entry is a file and does not exist at destination' { @@ -2780,7 +2883,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2797,6 +2900,10 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should not attempt to test if the archive entry is a directory' { + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -Exactly 0 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2857,7 +2964,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2874,6 +2981,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -2934,7 +3050,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2951,6 +3067,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -3011,7 +3136,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3028,6 +3153,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 0 -Scope 'Context' } @@ -3087,7 +3221,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3104,6 +3238,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { $testFileMatchesArchiveEntryByChecksumParameterFilter = { $fileParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockFile -DifferenceObject $File) @@ -3173,7 +3316,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3190,6 +3333,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-Item' -ParameterFilter $getItemParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should test if the file at the desired path of the archive entry at the destination matches the archive entry by the specified checksum method' { $testFileMatchesArchiveEntryByChecksumParameterFilter = { $fileParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockFile -DifferenceObject $File) @@ -3218,7 +3370,7 @@ Describe 'Archive Unit Tests' { } Describe 'Copy-ArchiveEntryToDestination' { - $testArchiveEntryFullNameWithBackslash = 'TestArchiveEntryFullName\' + $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testArchiveEntryLastWriteTime = Get-Date $testCopyFromStreamToStreamError = 'Test copy from stream to stream error' @@ -3226,7 +3378,8 @@ Describe 'Archive Unit Tests' { $mockArchiveEntry = New-MockObject -Type 'System.IO.Compression.ZipArchiveEntry' $mockFileStream = New-MockObject -Type 'System.IO.FileStream' - Mock -CommandName 'Get-ArchiveEntryFullName' { return $testArchiveEntryFullNameWithBackslash } + Mock -CommandName 'Get-ArchiveEntryFullName' { return $testArchiveEntryFullName } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $true } Mock -CommandName 'New-Item' -MockWith { } Mock -CommandName 'Open-ArchiveEntry' -MockWith { return $mockFileStream } Mock -CommandName 'New-Object' -MockWith { @@ -3244,7 +3397,7 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-ArchiveEntryLastWriteTime' -MockWith { return $testArchiveEntryLastWriteTime } Mock -CommandName 'Set-ItemProperty' -MockWith { } - Context 'Archive entry name ends in a backslash (directory)' { + Context 'Archive entry is a directory' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' @@ -3263,6 +3416,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-ArchiveEntryFullName' -ParameterFilter $getArchiveEntryFullNameParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should create a new directory at the specified destination' { $newItemParameterFilter = { $pathParameterCorrect = $Path -eq $copyArchiveEntryToDestinationParameters.DestinationPath @@ -3340,10 +3502,9 @@ Describe 'Archive Unit Tests' { } } - $testArchiveEntryFullNameNoBackslash = 'TestArchiveEntryFullName' - Mock -CommandName 'Get-ArchiveEntryFullName' { return $testArchiveEntryFullNameNoBackslash } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } - Context 'Archive entry name does not end in a backslash and copying from stream to stream fails' { + Context 'Archive entry is not a directory and copying from stream to stream fails' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' @@ -3357,7 +3518,7 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Copy-FromStreamToStream' -MockWith { } - Context 'Archive entry name does not end in a backslash and copying from stream to stream succeeds' { + Context 'Archive entry is not a directory and copying from stream to stream succeeds' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' @@ -3376,6 +3537,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-ArchiveEntryFullName' -ParameterFilter $getArchiveEntryFullNameParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to create a new directory at the specified destination' { Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } @@ -3486,9 +3656,8 @@ Describe 'Archive Unit Tests' { } } - Describe 'Expand-ArchiveToDestination' { - $testArchiveEntryFullNameWithBackslash = 'TestArchiveEntryFullName\' - $testArchiveEntryFullNameNoBackslash = 'TestArchiveEntryFullName' + Describe 'Expand-ArchiveToDestination' { + $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testItemPathAtDestination = 'TestItemPathAtDestination' $testParentDirectoryPath = 'TestParentDirectoryPath' @@ -3499,8 +3668,9 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameWithBackslash } + Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } Mock -CommandName 'Join-Path' -MockWith { return $testItemPathAtDestination } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $true } Mock -CommandName 'Get-Item' -MockWith { return $null } Mock -CommandName 'Split-Path' -MockWith { return $testParentDirectoryPath } Mock -CommandName 'Test-Path' -MockWith { return $false } @@ -3550,7 +3720,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3558,6 +3728,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -3621,7 +3800,7 @@ Describe 'Archive Unit Tests' { } It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { - $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullNameWithBackslash + $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage } } @@ -3667,7 +3846,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3675,6 +3854,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -3743,7 +3931,7 @@ Describe 'Archive Unit Tests' { } It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { - $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullNameWithBackslash + $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage } } @@ -3789,7 +3977,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3797,6 +3985,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -3898,7 +4095,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3906,6 +4103,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -3953,8 +4159,7 @@ Describe 'Archive Unit Tests' { } } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameNoBackslash } - + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } Mock -CommandName 'Get-Item' -MockWith { return $null } Context 'Archive entry is a file and does not exist at destination and the parent directory of the file does not exist' { @@ -3997,7 +4202,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4005,6 +4210,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4120,7 +4334,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4128,6 +4342,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4203,7 +4426,7 @@ Describe 'Archive Unit Tests' { } It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { - $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullNameNoBackslash + $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage } } @@ -4249,7 +4472,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4257,6 +4480,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4325,7 +4557,7 @@ Describe 'Archive Unit Tests' { } It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { - $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullNameNoBackslash + $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage } } @@ -4371,7 +4603,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4379,6 +4611,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4480,7 +4721,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4488,6 +4729,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4543,7 +4793,7 @@ Describe 'Archive Unit Tests' { } It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { - $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullNameNoBackslash + $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage } } @@ -4590,7 +4840,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4598,6 +4848,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4708,7 +4967,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4716,6 +4975,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -4969,8 +5237,7 @@ Describe 'Archive Unit Tests' { } Describe 'Remove-ArchiveFromDestination' { - $testArchiveEntryFullNameWithBackslash = 'TestArchiveEntryFullName\' - $testArchiveEntryFullNameNoBackslash = 'TestArchiveEntryFullName' + $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testItemPathAtDestination = 'TestItemPathAtDestination' $testParentDirectoryPath = 'TestParentDirectoryPath' @@ -4981,8 +5248,9 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameWithBackslash } + Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } Mock -CommandName 'Join-Path' -MockWith { return $testItemPathAtDestination } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $true } Mock -CommandName 'Get-Item' -MockWith { return $null } Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $false } Mock -CommandName 'Remove-Item' -MockWith { } @@ -5030,7 +5298,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5038,6 +5306,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5119,7 +5396,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5127,6 +5404,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5208,7 +5494,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5216,6 +5502,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5297,7 +5592,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5305,6 +5600,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5324,7 +5628,7 @@ Describe 'Archive Unit Tests' { It 'Should attempt to find the parent directory of the desired path of the archive entry at the destination' { $splitPathParameterFilter = { - $pathParameterCorrect = $Path -eq $testArchiveEntryFullNameWithBackslash + $pathParameterCorrect = $Path -eq $testArchiveEntryFullName $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } @@ -5332,9 +5636,18 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should remove the specified directory from the destination' { $removeDirectoryFromDestinationParameterFilter = { - $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testArchiveEntryFullNameWithBackslash ) -DifferenceObject $Directory) + $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testArchiveEntryFullName ) -DifferenceObject $Directory) $destinationParameterCorrect = $Destination -eq $removeArchiveFromDestinationParameters.Destination return $directoryParameterCorrect -and $destinationParameterCorrect } @@ -5403,7 +5716,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameWithBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5411,6 +5724,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5430,7 +5752,7 @@ Describe 'Archive Unit Tests' { It 'Should attempt to find the parent directory of the desired path of the archive entry at the destination' { $splitPathParameterFilter = { - $pathParameterCorrect = $Path -eq $testArchiveEntryFullNameWithBackslash + $pathParameterCorrect = $Path -eq $testArchiveEntryFullName $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } @@ -5440,7 +5762,7 @@ Describe 'Archive Unit Tests' { It 'Should remove the specified directory and its parent directory from the destination' { $removeDirectoryFromDestinationParameterFilter = { - $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testArchiveEntryFullNameWithBackslash, $testParentDirectoryPath ) -DifferenceObject $Directory) + $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testArchiveEntryFullName, $testParentDirectoryPath ) -DifferenceObject $Directory) $destinationParameterCorrect = $Destination -eq $removeArchiveFromDestinationParameters.Destination return $directoryParameterCorrect -and $destinationParameterCorrect } @@ -5462,7 +5784,7 @@ Describe 'Archive Unit Tests' { } } - Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullNameNoBackslash } + Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } Mock -CommandName 'Get-Item' -MockWith { return $null } Mock -CommandName 'Split-Path' -MockWith { return $null } @@ -5506,7 +5828,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5514,6 +5836,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5595,7 +5926,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5603,6 +5934,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5684,7 +6024,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5692,6 +6032,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5773,7 +6122,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5781,6 +6130,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5805,7 +6163,7 @@ Describe 'Archive Unit Tests' { It 'Should attempt to find the parent directory of the desired path of the archive entry at the destination' { $splitPathParameterFilter = { - $pathParameterCorrect = $Path -eq $testArchiveEntryFullNameNoBackslash + $pathParameterCorrect = $Path -eq $testArchiveEntryFullName $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } @@ -5813,6 +6171,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should not attempt to remove any directories from the destination' { Assert-MockCalled -CommandName 'Remove-DirectoryFromDestination' -Exactly 0 -Scope 'Context' } @@ -5878,7 +6245,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5886,6 +6253,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -5910,7 +6286,7 @@ Describe 'Archive Unit Tests' { It 'Should attempt to find the parent directory of the desired path of the archive entry at the destination' { $splitPathParameterFilter = { - $pathParameterCorrect = $Path -eq $testArchiveEntryFullNameNoBackslash + $pathParameterCorrect = $Path -eq $testArchiveEntryFullName $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } @@ -5918,6 +6294,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should remove the parent directory from the destination' { $removeDirectoryFromDestinationParameterFilter = { $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testParentDirectoryPath ) -DifferenceObject $Directory) @@ -5983,7 +6368,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5991,6 +6376,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -6081,7 +6475,7 @@ Describe 'Archive Unit Tests' { It 'Should find the desired path of the archive entry at the destination' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination - $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullNameNoBackslash + $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6089,6 +6483,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should retrieve the item at the desired path of the archive entry at the destination' { $getItemParameterFilter = { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination @@ -6121,7 +6524,7 @@ Describe 'Archive Unit Tests' { It 'Should attempt to find the parent directory of the desired path of the archive entry at the destination' { $splitPathParameterFilter = { - $pathParameterCorrect = $Path -eq $testArchiveEntryFullNameNoBackslash + $pathParameterCorrect = $Path -eq $testArchiveEntryFullName $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } @@ -6129,6 +6532,15 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } + It 'Should test if the archive entry is a directory' { + $testArchiveEntryIsDirectoryParameterFilter = { + $archiveEntryNameParameterCorrect = $ArchiveEntryName -eq $testArchiveEntryFullName + return $archiveEntryNameParameterCorrect + } + + Assert-MockCalled -CommandName 'Test-ArchiveEntryIsDirectory' -ParameterFilter $testArchiveEntryIsDirectoryParameterFilter -Exactly 1 -Scope 'Context' + } + It 'Should remove the parent directory from the destination' { $removeDirectoryFromDestinationParameterFilter = { $directoryParameterCorrect = $null -eq (Compare-Object -ReferenceObject @( $testParentDirectoryPath ) -DifferenceObject $Directory)