Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Move-Item.Tests.ps1114 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Move-Item tests" -Tag "CI" {4    BeforeAll {5        $content = "This is content"6        Setup -f originalfile.txt -Content "This is content"7        $source = "$TESTDRIVE/originalfile.txt"8        $target = "$TESTDRIVE/ItemWhichHasBeenMoved.txt"9        Setup -f [orig-file].txt -Content "This is not content"10        $sourceSp = "$TestDrive/``[orig-file``].txt"11        $targetSpName = "$TestDrive/ItemWhichHasBeen[Moved].txt"12        $targetSp = "$TestDrive/ItemWhichHasBeen``[Moved``].txt"13    }14    It "Move-Item will move a file" {15        Move-Item $source $target16        $source | Should -Not -Exist17        $target | Should -Exist18        "$target" | Should -FileContentMatchExactly "This is content"19    }20    It "Move-Item will move a file when path contains special char" {21        Move-Item $sourceSp $targetSpName22        $sourceSp | Should -Not -Exist23        $targetSp | Should -Exist24        $targetSp | Should -FileContentMatchExactly "This is not content"25    }26 27    Context "Move-Item with filters" {28        BeforeAll {29            $filterPath = "$TESTDRIVE/filterTests"30            $moveToPath = "$TESTDRIVE/dest-dir"31            $renameToPath = Join-Path $filterPath "move.txt"32            $filePath = Join-Path $filterPath "*"33            $fooFile = "foo.txt"34            $barFile = "bar.txt"35            $booFile = "boo.txt"36            $fooPath = Join-Path $filterPath $fooFile37            $barPath = Join-Path $filterPath $barFile38            $booPath = Join-Path $filterPath $booFile39            $newFooPath = Join-Path $moveToPath $fooFile40            $newBarPath = Join-Path $moveToPath $barFile41            $newBooPath = Join-Path $moveToPath $booFile42            $fooContent = "foo content"43            $barContent = "bar content"44            $booContent = "boo content"45        }46        BeforeEach {47            New-Item -ItemType Directory -Path $filterPath | Out-Null48            New-Item -ItemType Directory -Path $moveToPath | Out-Null49            New-Item -ItemType File -Path $fooPath -Value $fooContent | Out-Null50            New-Item -ItemType File -Path $barPath -Value $barContent | Out-Null51            New-Item -ItemType File -Path $booPath -Value $booContent | Out-Null52        }53        AfterEach {54            Remove-Item $filterPath -Recurse -Force -ErrorAction SilentlyContinue55            Remove-Item $moveToPath -Recurse -Force -ErrorAction SilentlyContinue56        }57        It "Can move to different directory, filtered with -Include" {58            Move-Item -Path $filePath -Destination $moveToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue59            $e | Should -BeNullOrEmpty60            $barPath | Should -Not -Exist61            $newBarPath | Should -Exist62            $booPath | Should -Exist63            $fooPath | Should -Exist64            $newBarPath | Should -FileContentMatchExactly $barContent65        }66        It "Can move to different directory, filtered with -Exclude" {67            Move-Item -Path $filePath -Destination $moveToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue68            $e | Should -BeNullOrEmpty69            $fooPath | Should -Not -Exist70            $newFooPath | Should -Exist71            $booPath | Should -Exist72            $barPath | Should -Exist73            $newFooPath | Should -FileContentMatchExactly $fooContent74        }75        It "Can move to different directory, filtered with -Filter" {76            Move-Item -Path $filePath -Destination $moveToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue77            $e | Should -BeNullOrEmpty78            $booPath | Should -Not -Exist79            $newBooPath | Should -Exist80            $barPath | Should -Exist81            $fooPath | Should -Exist82            $newBooPath | Should -FileContentMatchExactly $booContent83        }84 85        It "Can rename via move, filtered with -Include" {86            Move-Item -Path $filePath -Destination $renameToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue87            $e | Should -BeNullOrEmpty88            $renameToPath | Should -Exist89            $barPath | Should -Not -Exist90            $booPath | Should -Exist91            $fooPath | Should -Exist92            $renameToPath | Should -FileContentMatchExactly $barContent93        }94        It "Can rename via move, filtered with -Exclude" {95            Move-Item -Path $filePath -Destination $renameToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue96            $e | Should -BeNullOrEmpty97            $renameToPath | Should -Exist98            $fooPath | Should -Not -Exist99            $booPath | Should -Exist100            $barPath | Should -Exist101            $renameToPath | Should -FileContentMatchExactly $fooContent102        }103        It "Can rename via move, filtered with -Filter" {104            Move-Item -Path $filePath -Destination $renameToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue105            $e | Should -BeNullOrEmpty106            $renameToPath | Should -Exist107            $booPath | Should -Not -Exist108            $fooPath | Should -Exist109            $barPath | Should -Exist110            $renameToPath | Should -FileContentMatchExactly $booContent111        }112    }113}114