Tests/Expand-TemplatesInDirectoryNames.Tests.ps1

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
. "$PSScriptRoot\CommonTestUtil.ps1"

Describe 'Expand-TemplatesInDirectoryNames' {
    Context 'When a directory has static tokens to replace in the path name' {
        . $setup
        Expand-TemplatesInDirectoryNames -SearchDirectory $testDataBasePath -StaticReplacements $replacements -TotalReplacements ([ref]$totalReplacements)
        
        It 'expands all static template tokens in the name and renames the directory properly ' {
            "$testDataBasePath\3_$($config.'DYNAMICTOKEN')" | Should Exist 
            "$testDataBasePath\2_TokenIsStaticReplaced_StaticReplaced" | Should Exist 
            "$testDataBasePath\1_TokenIsStaticReplaced_StaticReplaced" | Should Exist 
        }
        
        It 'does not leave old folders behind' {
            "$testDataBasePath\1 _STATICTOKEN" | Should Not Exist
            "$testDataBasePath\2_STATICTOKEN" | Should Not Exist
            "$testDataBasePath\3_[[`$DYNAMICTOKEN]]" | Should Not Exist
        }
        
        It 'returns the actual number of replacements performed' {
            $totalReplacements | Should Be 3
        }
    }
    
    Context 'When replacing directory names, and another directory already exists with the new name' {
        . $setup
        Expand-TemplatesInDirectoryNames -SearchDirectory $testDataBasePath -StaticReplacements $replacements -TotalReplacements ([ref]$totalReplacements)
        . $setup
        Expand-TemplatesInDirectoryNames -SearchDirectory $testDataBasePath -StaticReplacements $replacements -TotalReplacements ([ref]$totalReplacements)
        It 'does not create nested folders' {
            "$testDataBasePath\3_$($config.'DYNAMICTOKEN')\3_$($config.'DYNAMICTOKEN')" | Should Not Exist 
            "$testDataBasePath\2_TokenIsStaticReplaced_StaticReplaced\2_TokenIsStaticReplaced_StaticReplaced" | Should Not Exist 
            "$testDataBasePath\1_TokenIsStaticReplaced_StaticReplaced\1_TokenIsStaticReplaced_StaticReplaced" | Should Not Exist       
        }
    }
    
    Context 'When replacing directory names, and no static content replacments are specified' {
        . $setup
        Expand-TemplatesInDirectoryNames -SearchDirectory $testDataBasePath -TotalReplacements ([ref]$totalReplacements)
         
        It 'it only performs dynamic replacements' {
           "$testDataBasePath\3_$($config.'DYNAMICTOKEN')" | Should Exist 
            "$testDataBasePath\2_TokenIsStaticReplaced_StaticReplaced" | Should Not Exist 
            "$testDataBasePath\1_TokenIsStaticReplaced_StaticReplaced" | Should Not Exist
        }
    }

}