Skip to content

Commit

Permalink
Add test for reading list of numeric values as other numeric list
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Nov 10, 2023
1 parent e3f952d commit 7ff03ca
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions DuckDB.NET.Test/DuckDBDataReaderListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,49 @@ public void ReadListWithDapper()
person.Mood.Should().Be(DuckDBDataReaderEnumTests.Mood.Happy);
}

[Fact]
public void ReadListAsEveryNumericType()
{
Command.CommandText = "SELECT [1, 2, 3];";
using var reader = Command.ExecuteReader();
reader.Read();

TestReadValueAs<byte>();
TestReadValueAs<sbyte>();
TestReadValueAs<ushort>();
TestReadValueAs<short>();
TestReadValueAs<uint>();
TestReadValueAs<int>();
TestReadValueAs<ulong>();
TestReadValueAs<long>();

void TestReadValueAs<T>()
{
var list = reader.GetFieldValue<List<T>>(0);
list.Should().BeEquivalentTo(new List<long> { 1, 2, 3 });
}
}

[Fact]
public void ReadListWithLargeValuesAsEveryNumericTypeThrowsException()
{
Command.CommandText = $"SELECT [{long.MaxValue - 1}, {long.MaxValue}];";
using var reader = Command.ExecuteReader();
reader.Read();

TestReadValueAs<byte>();
TestReadValueAs<sbyte>();
TestReadValueAs<ushort>();
TestReadValueAs<short>();
TestReadValueAs<uint>();
TestReadValueAs<int>();

void TestReadValueAs<T>()
{
reader.Invoking(dataReader => dataReader.GetFieldValue<List<T>>(0)).Should().Throw<InvalidCastException>();
}
}

class Person
{
public List<int> Ids { get; set; }
Expand Down

0 comments on commit 7ff03ca

Please sign in to comment.