diff --git a/Test/public/CsvFile.test.ps1 b/Test/public/CsvFile.test.ps1 index 8e55fbc..dc7a421 100644 --- a/Test/public/CsvFile.test.ps1 +++ b/Test/public/CsvFile.test.ps1 @@ -47,3 +47,23 @@ function Test_GetCsvFile_Default_Id{ Assert-AreEqual -Expected "Value3_$i" -Presented $record2.Column3 } +function Test_GetCsvFile_Integration{ + + Assert-SkipTest -Message "Integration test not implemented" + + Mock_Database -resetDatabase + $databaseRoot = Get-Mock_DatabaseStore + $csvPath = "~/Downloads/data.csv" + + Assert-IsTrue -Condition (Test-Path -Path $csvPath) + + $result = Import-CsvFile -Path $csvPath -KeyColumn "Account Id" + + Assert-AreEqual -Expected "2F84A5E1110A1AC840178DF2FDFEF080" -Presented $result + + $dbPath = Invoke-CsvHelperGetDbRootPath + + Assert-ItemExist -Path $($dbPath | Join-Path -ChildPath $result.json) + +} + diff --git a/public/CsvDatabase.ps1 b/public/CsvDatabase.ps1 index 508881b..cb7416c 100644 --- a/public/CsvDatabase.ps1 +++ b/public/CsvDatabase.ps1 @@ -70,6 +70,10 @@ function Save-CsvDatabase{ foreach ($row in $Data) { $keyValue = $row.$KeyColumn + if (-not $keyValue) { + throw "Key column '$KeyColumn' not found in row: $row" + } + if (-not $CsvDatabase.ContainsKey($keyValue)) { $CsvDatabase[$keyValue] = @{} } diff --git a/public/CsvRecord.ps1 b/public/CsvRecord.ps1 index 35892b8..bef0d57 100644 --- a/public/CsvRecord.ps1 +++ b/public/CsvRecord.ps1 @@ -51,15 +51,8 @@ function Get-CsvRecord{ $record = $db.$Id if (-Not $record) { - Write-Error "Record not found for ID: $Id in Csv $Path" - return - } - - $record = $db.$Id - - if (-Not $record) { - Write-Error "Record not found for ID: $Id in Csv $Path" - return + # Write-Error "Record not found for ID: $Id in Csv $Path" + return $null } return $record diff --git a/Test/private/NewCsvTestFile.ps1 b/public/NewCsvTestFile.ps1 similarity index 72% rename from Test/private/NewCsvTestFile.ps1 rename to public/NewCsvTestFile.ps1 index 9baad43..b3b1adf 100644 --- a/Test/private/NewCsvTestFile.ps1 +++ b/public/NewCsvTestFile.ps1 @@ -1,7 +1,7 @@ function New-TestCsvFile { param ( - [int]$NumRows = 10, - [string]$Path = "test.csv" + [Parameter()][int]$NumRows = 10, + [Parameter()][string]$Path = "test.csv" ) $data = @() @@ -18,4 +18,4 @@ function New-TestCsvFile { $data | Export-Csv -Path $Path -NoTypeInformation return $Path -} \ No newline at end of file +} Export-ModuleMember -Function New-TestCsvFile \ No newline at end of file