-
|
I want to create a PowerShell script that can delete a bunch of file in given paths following a particular match (in the following example all the files that contain TMP). This is the function: Now, I want to create the test for this function. I mock the The problems I'm facing are:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
Hi. You can display If they should be equal, you can compare ex filenames using: $expected.Name | Sort-Object | Should -Be ($list.Name | Sort-Object)`
# sorting to avoid order-issueTip: For a simple filename-filter I'd recommend For the future, it helps with a valid repro. This code won't run as-is due to wrong types in Mock (won't work with List.AddRange() |
Beta Was this translation helpful? Give feedback.
-
|
Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
Is it possible to check the If I try I got this error
Thank you so much in advance. |
Beta Was this translation helpful? Give feedback.
BeforeAll { function CheckFilesToDelete([string[]]$fList) { $fileList = [System.Collections.Generic.List[System.IO.FileInfo]]::new() foreach ($folderName in $fList) { $path = "$folderName" # Using -Filter for improved performance for filename filter # Convert to typed array so .AddRange() doesn't complain about object[] parameter $list = [System.IO.FileInfo[]]@(Get-ChildItem -Path $path -File -Recurse -Filter '*TMP*') if ($list.Count -gt 0) { $fileList.AddRange($list) } } return $fileList } } Describe 'Validate files to delete' { Context 'validate files' { It 'should return …