1
+ Import-Module .\WindowsDiskCleanup\WindowsDiskCleanup.psm1 - Force
2
+
3
+ Describe ' Get-ItemSize.Tests' {
4
+ BeforeAll {
5
+ $testFolder = " $PSScriptRoot \TestFolder"
6
+ $nestedFolder = " $testFolder \Nested"
7
+ $testFile1 = " $testFolder \File1.txt"
8
+ $testFile2 = " $nestedFolder \File2.txt"
9
+ }
10
+
11
+ BeforeEach {
12
+ if (-not (Test-Path $testFolder )) {
13
+ New-Item - Path $testFolder - ItemType Directory - Force | Out-Null
14
+ }
15
+ if (-not (Test-Path $nestedFolder )) {
16
+ New-Item - Path $nestedFolder - ItemType Directory - Force | Out-Null
17
+ }
18
+ Set-Content - Path $testFile1 - Value (' A' * 1024 ) - NoNewline # 1 KB
19
+ Set-Content - Path $testFile2 - Value (' B' * 2048 ) - NoNewline # 2 KB
20
+ }
21
+
22
+ AfterEach {
23
+ if (Test-Path $testFolder ) {
24
+ Remove-Item - Path $testFolder - Recurse - Force
25
+ }
26
+ }
27
+
28
+ It ' should calculate the correct size of a folder with files' {
29
+ $result = Get-ItemSize - Path $testFolder
30
+ $result | Should - Be 3072 # 1 KB + 2 KB
31
+ }
32
+
33
+ It ' should return 0 for an empty folder' {
34
+ Remove-Item - Path $testFile1 , $testFile2 - Force
35
+ $result = Get-ItemSize - Path $testFolder
36
+ $result | Should - Be 0
37
+ }
38
+
39
+ It ' should calculate the correct size for nested folders' {
40
+ $result = Get-ItemSize - Path $testFolder
41
+ $result | Should - Be 3072 # 1 KB + 2 KB
42
+ }
43
+
44
+ It " shouldn't throw an error for an invalid path" {
45
+ $result = Get-ItemSize - Path " $PSScriptRoot \InvalidPath"
46
+ $result | Should - Be 0
47
+ }
48
+
49
+ It ' should calculate the correct size of a single file' {
50
+ $fileInfo = Get-Item - Path $testFile1
51
+ $result = Get-ItemSize - File $fileInfo
52
+ $result | Should - Be 1024 # 1 KB
53
+ }
54
+
55
+ It ' should return 0 for a non-existent file' {
56
+ $fileInfo = [System.IO.FileInfo ]::new(" $PSScriptRoot \NonExistentFile.txt" )
57
+ $result = Get-ItemSize - File $fileInfo
58
+ $result | Should - Be 0
59
+ }
60
+ }
0 commit comments