Skip to content

Commit

Permalink
array weirdness ? (do ConvertTo-DbaDataTable)
Browse files Browse the repository at this point in the history
  • Loading branch information
niphlod committed Jun 5, 2024
1 parent 6181733 commit 99a8e8a
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions tests/ConvertTo-DbaDataTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ Describe "Testing data table output when using a complex object" {

Add-Member -Force -InputObject $obj -MemberType NoteProperty -Name myObject -Value $innedobj
$result = ConvertTo-DbaDataTable -InputObject $obj


$firstRow = $result[0].Rows[0]
Context "Property: guid" {
It 'Has a column called "guid"' {
$result.Columns.ColumnName | Should -Contain 'guid'
}
It 'Has a [guid] data type on the column "guid"' {
$result.guid | Should -BeOfType [System.guid]
$firstRow.guid | Should -BeOfType [System.guid]
}
It 'Has the following guid: "32ccd4c4-282a-4c0d-997c-7b5deb97f9e0"' {
$result.guid | Should Be '32ccd4c4-282a-4c0d-997c-7b5deb97f9e0'
$firstRow.guid | Should Be '32ccd4c4-282a-4c0d-997c-7b5deb97f9e0'
}
}

Expand All @@ -52,11 +53,11 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'timespan'
}
It 'Has a [long] data type on the column "timespan"' {
$result.timespan | Should -BeOfType [System.Int64]
$firstRow.timespan | Should -BeOfType [System.Int64]

}
It "Has the following timespan: 15724800000" {
$result.timespan | Should Be 15724800000
$firstRow.timespan | Should Be 15724800000
}
}

Expand All @@ -65,11 +66,11 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'datetime'
}
It 'Has a [datetime] data type on the column "datetime"' {
$result.datetime | Should -BeOfType [System.DateTime]
$firstRow.datetime | Should -BeOfType [System.DateTime]
}
It "Has the following datetime: 2016-10-30 05:52:00.000" {
$date = Get-Date -Year 2016 -Month 10 -Day 30 -Hour 5 -Minute 52 -Second 0 -Millisecond 0
$result.datetime -eq $date | Should Be $true
$firstRow.datetime -eq $date | Should Be $true
}
}

Expand All @@ -78,10 +79,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'char'
}
It 'Has a [char] data type on the column "char"' {
$result.char | Should -BeOfType [System.Char]
$firstRow.char | Should -BeOfType [System.Char]
}
It "Has the following char: T" {
$result.char | Should Be "T"
$firstRow.char | Should Be "T"
}
}

Expand All @@ -90,10 +91,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'true'
}
It 'Has a [bool] data type on the column "true"' {
$result.true | Should -BeOfType [System.Boolean]
$firstRow.true | Should -BeOfType [System.Boolean]
}
It "Has the following bool: true" {
$result.true | Should Be $true
$firstRow.true | Should Be $true
}
}

Expand All @@ -102,10 +103,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'false'
}
It 'Has a [bool] data type on the column "false"' {
$result.false | Should -BeOfType [System.Boolean]
$firstRow.false | Should -BeOfType [System.Boolean]
}
It "Has the following bool: false" {
$result.false | Should Be $false
$firstRow.false | Should Be $false
}
}

Expand All @@ -114,10 +115,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'null'
}
It 'Has a [null] data type on the column "null"' {
$result.null | Should -BeOfType [System.DBNull]
$firstRow.null | Should -BeOfType [System.DBNull]
}
It "Has no value" {
$result.null | Should -BeNullOrEmpty
$firstRow.null | Should -BeNullOrEmpty
}
}

Expand All @@ -126,10 +127,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'string'
}
It 'Has a [string] data type on the column "string"' {
$result.string | Should -BeOfType [System.String]
$firstRow.string | Should -BeOfType [System.String]
}
It "Has the following string: it's a boy." {
$result.string | Should Be "it's a boy."
$firstRow.string | Should Be "it's a boy."
}
}

Expand All @@ -138,10 +139,10 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'UInt64'
}
It 'Has a [UInt64] data type on the column "UInt64"' {
$result.UInt64 | Should -BeOfType [System.UInt64]
$firstRow.UInt64 | Should -BeOfType [System.UInt64]
}
It "Has the following number: 123456" {
$result.UInt64 | Should Be 123456
$firstRow.UInt64 | Should Be 123456
}
}

Expand All @@ -151,8 +152,10 @@ Describe "Testing data table output when using a complex object" {
}
It 'Has a [string] data type on the column "myObject"' {
Write-Host -Fore Magenta "type dump $($result.myObject.GetType() | Format-Table | Out-String)"
Write-Host -Fore Magenta "obj dump $($result.myObject | ConvertTo-Json | Out-String)"
$result.myObject | Should -BeOfType [System.String]
Write-Host -Fore Magenta "type dump2 $($firstRow.myObject.GetType() | Format-Table | Out-String)"
Write-Host -Fore Magenta "obj dump $($firstRow.myObject | ConvertTo-Json | Out-String)"
Write-Host -Fore Magenta "row dump $($firstRow | ConvertTo-Json | Out-String)"
$firstRow.myObject | Should -BeOfType [System.String]
}
}

Expand All @@ -161,7 +164,7 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'dbadatetime'
}
It 'Has a [dbadatetime] data type on the column "myObject"' {
$result.dbadatetime | Should -BeOfType [System.String]
$firstRow.dbadatetime | Should -BeOfType [System.String]
}
It "Has the following dbadatetime: 2024-05-19 05:52:00.000" {
$date = Get-Date -Year 2024 -Month 5 -Day 19 -Hour 5 -Minute 52 -Second 0 -Millisecond 0
Expand All @@ -174,11 +177,11 @@ Describe "Testing data table output when using a complex object" {
$result.Columns.ColumnName | Should -Contain 'dbadatetimeArray'
}
It 'Has a [dbadatetimeArray] data type on the column "myObject"' {
$result.dbadatetimeArray | Should -BeOfType [System.String]
$firstRow.dbadatetimeArray | Should -BeOfType [System.String]
}
It "Has the following dbadatetimeArray converted to strings: 2024-05-19 05:52:00.000, 2024-05-19 06:52:00.000" {
$string = '2024-05-19 05:52:00.000, 2024-05-19 06:52:00.000'
$result.dbadatetimeArray -eq $string | Should Be $true
$firstRow.dbadatetimeArray -eq $string | Should Be $true
}
}
}
Expand Down

0 comments on commit 99a8e8a

Please sign in to comment.