@@ -11,4 +11,91 @@ Describe "Move-Item tests" -Tag "CI" { |
11 | 11 | test-path $target | Should be $true |
12 | 12 | "$target" | Should ContainExactly "This is content" |
13 | 13 | } |
| 14 | + |
| 15 | + Context "Move-Item with filters" { |
| 16 | + BeforeAll { |
| 17 | + $filterPath = "$TESTDRIVE/filterTests" |
| 18 | + $moveToPath = "$TESTDRIVE/dest-dir" |
| 19 | + $renameToPath = Join-Path $filterPath "move.txt" |
| 20 | + $filePath = Join-Path $filterPath "*" |
| 21 | + $fooFile = "foo.txt" |
| 22 | + $barFile = "bar.txt" |
| 23 | + $booFile = "boo.txt" |
| 24 | + $fooPath = Join-Path $filterPath $fooFile |
| 25 | + $barPath = Join-Path $filterPath $barFile |
| 26 | + $booPath = Join-Path $filterPath $booFile |
| 27 | + $newFooPath = Join-Path $moveToPath $fooFile |
| 28 | + $newBarPath = Join-Path $moveToPath $barFile |
| 29 | + $newBooPath = Join-Path $moveToPath $booFile |
| 30 | + $fooContent = "foo content" |
| 31 | + $barContent = "bar content" |
| 32 | + $booContent = "boo content" |
| 33 | + } |
| 34 | + BeforeEach { |
| 35 | + New-Item -ItemType Directory -Path $filterPath | Out-Null |
| 36 | + New-Item -ItemType Directory -Path $moveToPath | Out-Null |
| 37 | + New-Item -ItemType File -Path $fooPath -Value $fooContent | Out-Null |
| 38 | + New-Item -ItemType File -Path $barPath -Value $barContent | Out-Null |
| 39 | + New-Item -ItemType File -Path $booPath -Value $booContent | Out-Null |
| 40 | + } |
| 41 | + AfterEach { |
| 42 | + Remove-Item $filterPath -Recurse -Force -ErrorAction SilentlyContinue |
| 43 | + Remove-Item $moveToPath -Recurse -Force -ErrorAction SilentlyContinue |
| 44 | + } |
| 45 | + It "Can move to different directory, filtered with -Include" { |
| 46 | + Move-Item -Path $filePath -Destination $moveToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 47 | + $e | Should BeNullOrEmpty |
| 48 | + $barPath | Should Not Exist |
| 49 | + $newBarPath | Should Exist |
| 50 | + $booPath | Should Exist |
| 51 | + $fooPath | Should Exist |
| 52 | + $newBarPath | Should ContainExactly $barContent |
| 53 | + } |
| 54 | + It "Can move to different directory, filtered with -Exclude" { |
| 55 | + Move-Item -Path $filePath -Destination $moveToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 56 | + $e | Should BeNullOrEmpty |
| 57 | + $fooPath | Should Not Exist |
| 58 | + $newFooPath | Should Exist |
| 59 | + $booPath | Should Exist |
| 60 | + $barPath | Should Exist |
| 61 | + $newFooPath | Should ContainExactly $fooContent |
| 62 | + } |
| 63 | + It "Can move to different directory, filtered with -Filter" { |
| 64 | + Move-Item -Path $filePath -Destination $moveToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 65 | + $e | Should BeNullOrEmpty |
| 66 | + $booPath | Should Not Exist |
| 67 | + $newBooPath | Should Exist |
| 68 | + $barPath | Should Exist |
| 69 | + $fooPath | Should Exist |
| 70 | + $newBooPath | Should ContainExactly $booContent |
| 71 | + } |
| 72 | + |
| 73 | + It "Can rename via move, filtered with -Include" { |
| 74 | + Move-Item -Path $filePath -Destination $renameToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 75 | + $e | Should BeNullOrEmpty |
| 76 | + $renameToPath | Should Exist |
| 77 | + $barPath | Should Not Exist |
| 78 | + $booPath | Should Exist |
| 79 | + $fooPath | Should Exist |
| 80 | + $renameToPath | Should ContainExactly $barContent |
| 81 | + } |
| 82 | + It "Can rename via move, filtered with -Exclude" { |
| 83 | + Move-Item -Path $filePath -Destination $renameToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 84 | + $e | Should BeNullOrEmpty |
| 85 | + $renameToPath | Should Exist |
| 86 | + $fooPath | Should Not Exist |
| 87 | + $booPath | Should Exist |
| 88 | + $barPath | Should Exist |
| 89 | + $renameToPath | Should ContainExactly $fooContent |
| 90 | + } |
| 91 | + It "Can rename via move, filtered with -Filter" { |
| 92 | + Move-Item -Path $filePath -Destination $renameToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue |
| 93 | + $e | Should BeNullOrEmpty |
| 94 | + $renameToPath | Should Exist |
| 95 | + $booPath | Should Not Exist |
| 96 | + $fooPath | Should Exist |
| 97 | + $barPath | Should Exist |
| 98 | + $renameToPath | Should ContainExactly $booContent |
| 99 | + } |
| 100 | + } |
14 | 101 | } |