From 655d9a5c9a19d5bc4bac66263cf7b4908404b29b Mon Sep 17 00:00:00 2001 From: IG Date: Thu, 30 May 2024 15:23:28 +0100 Subject: [PATCH] check that interface serialization/deserialization works (#513) --- .../Serialisation/ParquetSerializerTest.cs | 25 +++++++++++++++++++ .../Serialisation/SchemaReflectorTest.cs | 16 ++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs index 725dd1a2..5b06ac04 100644 --- a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs +++ b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs @@ -826,6 +826,31 @@ public async Task List_Struct_WithAlias_Serde() { await Compare(data); } + interface IInterface { + int Id { get; set; } + } + + class InterfaceImpl : IInterface { + public int Id { get; set; } + } + + [Fact] + public async Task Interface_Serialize() { + var data = new IInterface[] { + new InterfaceImpl { Id = 1 }, + new InterfaceImpl { Id = 2 }, + }; + + using var ms = new MemoryStream(); + await ParquetSerializer.SerializeAsync(data, ms); + + ms.Position = 0; + IList data2 = await ParquetSerializer.DeserializeAllAsync(ms).ToArrayAsync(); + + Assert.Equivalent(data, data2); + + } + #if NET6_0_OR_GREATER record RecordContainingDateAndtimeOnly { diff --git a/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs b/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs index 97172fd4..6ac2c558 100644 --- a/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs +++ b/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs @@ -537,5 +537,21 @@ public void Strings_OptionalAndRequired() { Assert.True(s.DataFields[1].IsNullable); Assert.True(s.DataFields[2].IsNullable); } + + public interface IInterface { + int Id { get; set; } + } + + [Fact] + public void InterfaceIsSupported() { + ParquetSchema s = typeof(IInterface).GetParquetSchema(true); + + Assert.NotNull(s); + DataField df = s.FindDataField(nameof(IInterface.Id)); + Assert.True(df.GetType() == typeof(DataField)); + Assert.Equal(SchemaType.Data, df.SchemaType); + Assert.Equal(typeof(int), df.ClrType); + Assert.False(df.IsNullable); + } } } \ No newline at end of file