Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1336,10 +1336,6 @@ private string
{
type = null;
}
else
{
type = ImportExportCSVHelper.CSVTypePrefix + type;
}
}
}
return type;
Expand Down Expand Up @@ -1606,11 +1602,6 @@ private Collection<string>
PSObject result = new PSObject();
char delimiterlocal = delimiter;
int unspecifiedNameIndex = 1;
if (type != null && type.Length > 0)
{
result.TypeNames.Clear();
result.TypeNames.Add(type);
}
for (int i = 0; i <= names.Count - 1; i++)
{
string name = names[i];
Expand Down Expand Up @@ -1638,6 +1629,13 @@ private Collection<string>
_alreadyWarnedUnspecifiedName = true;
}

if (type != null && type.Length > 0)
{
result.TypeNames.Clear();
result.TypeNames.Add(type);
result.TypeNames.Add(ImportExportCSVHelper.CSVTypePrefix + type);
}

return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Describe "ConvertFrom-Csv" -Tags "CI" {
$testColumns = @"
a,b,c
1,2,3
"@
$testTypeData = @"
#TYPE My.Custom.Object
a,b,c
1,2,3
"@
}

Expand Down Expand Up @@ -53,6 +58,13 @@ a,b,c

$actualLength | Should Be 3
}

It "Should Contain the Imported Type data" {
$actualData = $testTypeData | ConvertFrom-Csv
$actualData.PSObject.TypeNames.Count | Should Be 2
$actualData.PSObject.TypeNames[0] | Should Be "My.Custom.Object"
$actualData.PSObject.TypeNames[1] | Should Be "CSV:My.Custom.Object"
}
}

Describe "ConvertFrom-Csv DRT Unit Tests" -Tags "CI" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ Describe "Import-Csv #Type Tests" -Tags "CI" {
Remove-Item -Path $testfile -Force -ErrorAction SilentlyContinue
$processlist = (Get-Process)[0..1]
$processlist | Export-Csv -Path $testfile -Force -IncludeTypeInformation
# Import-Csv add "CSV:" before actual type
$expectedProcessType = "CSV:System.Diagnostics.Process"
$expectedProcessTypes = "System.Diagnostics.Process","CSV:System.Diagnostics.Process"
}

It "Test import-csv import Object" {
$importObjectList = Import-Csv -Path $testfile
$processlist.Count | Should Be $importObjectList.Count

$importType = $importObjectList[0].psobject.TypeNames[0]
$importType | Should Be $expectedProcessType
$importTypes = $importObjectList[0].psobject.TypeNames
$importTypes.Count | Should Be $expectedProcessTypes.Count
$importTypes[0] | Should Be $expectedProcessTypes[0]
$importTypes[1] | Should Be $expectedProcessTypes[1]
}
}

Expand Down