File size: 2,417 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Rename-Item tests" -Tag "CI" {
BeforeAll {
Setup -f originalFile.txt -Content "This is content"
$source = "$TESTDRIVE/originalFile.txt"
$target = "$TESTDRIVE/ItemWhichHasBeenRenamed.txt"
Setup -f [orig-file].txt -Content "This is not content"
$sourceSp = "$TestDrive/``[orig-file``].txt"
$targetSpName = "ItemWhichHasBeen[Renamed].txt"
$targetSp = "$TestDrive/ItemWhichHasBeen``[Renamed``].txt"
Setup -Dir [test-dir]
$wdSp = "$TestDrive/``[test-dir``]"
}
It "Rename-Item will rename a file" {
Rename-Item $source $target
Test-Path $source | Should -BeFalse
Test-Path $target | Should -BeTrue
"$target" | Should -FileContentMatchExactly "This is content"
}
It "Rename-Item will rename a file when path contains special char" {
Rename-Item $sourceSp $targetSpName
$sourceSp | Should -Not -Exist
$targetSp | Should -Exist
$targetSp | Should -FileContentMatchExactly "This is not content"
}
It "Rename-Item will rename a file when -Path and CWD contains special char" {
$content = "This is content"
$oldSpName = "[orig]file.txt"
$oldSpBName = "``[orig``]file.txt"
$oldSp = "$wdSp/$oldSpBName"
$newSpName = "[renamed]file.txt"
$newSp = "$wdSp/``[renamed``]file.txt"
In $wdSp -execute {
$null = New-Item -Name $oldSpName -ItemType File -Value $content -Force
Rename-Item -Path $oldSpBName $newSpName
}
$oldSp | Should -Not -Exist
$newSp | Should -Exist
$newSp | Should -FileContentMatchExactly $content
}
It "Rename-Item will rename a file when -LiteralPath and CWD contains special char" {
$content = "This is not content"
$oldSpName = "[orig]file2.txt"
$oldSpBName = "``[orig``]file2.txt"
$oldSp = "$wdSp/$oldSpBName"
$newSpName = "[renamed]file2.txt"
$newSp = "$wdSp/``[renamed``]file2.txt"
In $wdSp -execute {
$null = New-Item -Name $oldSpName -ItemType File -Value $content -Force
Rename-Item -LiteralPath $oldSpName $newSpName
}
$oldSp | Should -Not -Exist
$newSp | Should -Exist
$newSp | Should -FileContentMatchExactly $content
}
}
|