Skip to content

Commit

Permalink
check that interface serialization/deserialization works (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed May 30, 2024
1 parent 52f5ac2 commit 655d9a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Parquet.Test/Serialisation/ParquetSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InterfaceImpl> data2 = await ParquetSerializer.DeserializeAllAsync<InterfaceImpl>(ms).ToArrayAsync();

Assert.Equivalent(data, data2);

}

#if NET6_0_OR_GREATER

record RecordContainingDateAndtimeOnly {
Expand Down
16 changes: 16 additions & 0 deletions src/Parquet.Test/Serialisation/SchemaReflectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 655d9a5

Please sign in to comment.