add: Function to remove test rows with no results
This commit is contained in:
34
source/Public/Remove-RowsWithEmptyCSVStatus.ps1
Normal file
34
source/Public/Remove-RowsWithEmptyCSVStatus.ps1
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
function Remove-RowsWithEmptyCSVStatus {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$FilePath,
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$WorksheetName
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import the Excel file
|
||||||
|
$ExcelData = Import-Excel -Path $FilePath -WorksheetName $WorksheetName
|
||||||
|
|
||||||
|
# Check if CSV_Status column exists
|
||||||
|
if (-not $ExcelData.PSObject.Properties.Match("CSV_Status")) {
|
||||||
|
throw "CSV_Status column not found in the worksheet."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Filter rows where CSV_Status is not empty
|
||||||
|
$FilteredData = $ExcelData | Where-Object { $null -ne $_.CSV_Status -and $_.CSV_Status -ne '' }
|
||||||
|
|
||||||
|
# Get the original file name and directory
|
||||||
|
$OriginalFileName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath)
|
||||||
|
$Directory = [System.IO.Path]::GetDirectoryName($FilePath)
|
||||||
|
|
||||||
|
# Create a new file name for the filtered data
|
||||||
|
$NewFileName = "$OriginalFileName-Filtered.xlsx"
|
||||||
|
$NewFilePath = Join-Path -Path $Directory -ChildPath $NewFileName
|
||||||
|
|
||||||
|
# Export the filtered data to a new Excel file
|
||||||
|
$FilteredData | Export-Excel -Path $NewFilePath -WorksheetName $WorksheetName -Show
|
||||||
|
|
||||||
|
Write-Output "Filtered Excel file created at $NewFilePath"
|
||||||
|
}
|
71
tests/Unit/Public/Remove-RowsWithEmptyCSVStatus.tests.ps1
Normal file
71
tests/Unit/Public/Remove-RowsWithEmptyCSVStatus.tests.ps1
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
BeforeAll {
|
||||||
|
$script:moduleName = '<% $PLASTER_PARAM_ModuleName %>'
|
||||||
|
|
||||||
|
# If the module is not found, run the build task 'noop'.
|
||||||
|
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
|
||||||
|
{
|
||||||
|
# Redirect all streams to $null, except the error stream (stream 2)
|
||||||
|
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Re-import the module using force to get any code changes between runs.
|
||||||
|
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
|
||||||
|
|
||||||
|
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
|
||||||
|
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
|
||||||
|
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
$PSDefaultParameterValues.Remove('Mock:ModuleName')
|
||||||
|
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
|
||||||
|
$PSDefaultParameterValues.Remove('Should:ModuleName')
|
||||||
|
|
||||||
|
Remove-Module -Name $script:moduleName
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe Get-Something {
|
||||||
|
|
||||||
|
Context 'Return values' {
|
||||||
|
BeforeEach {
|
||||||
|
$return = Get-Something -Data 'value'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Returns a single object' {
|
||||||
|
($return | Measure-Object).Count | Should -Be 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Context 'Pipeline' {
|
||||||
|
It 'Accepts values from the pipeline by value' {
|
||||||
|
$return = 'value1', 'value2' | Get-Something
|
||||||
|
|
||||||
|
$return[0] | Should -Be 'value1'
|
||||||
|
$return[1] | Should -Be 'value2'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Accepts value from the pipeline by property name' {
|
||||||
|
$return = 'value1', 'value2' | ForEach-Object {
|
||||||
|
[PSCustomObject]@{
|
||||||
|
Data = $_
|
||||||
|
OtherProperty = 'other'
|
||||||
|
}
|
||||||
|
} | Get-Something
|
||||||
|
|
||||||
|
|
||||||
|
$return[0] | Should -Be 'value1'
|
||||||
|
$return[1] | Should -Be 'value2'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context 'ShouldProcess' {
|
||||||
|
It 'Supports WhatIf' {
|
||||||
|
(Get-Command Get-Something).Parameters.ContainsKey('WhatIf') | Should -Be $true
|
||||||
|
{ Get-Something -Data 'value' -WhatIf } | Should -Not -Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user