public async Task BasicReflectiveSerialization() { byte[] serializedStream; var basicPoco = new BasicPoco() { NullStringValue = null, IntValues = new List <int>() { 56, 57, 58 }, IntValue = 238, UintValue = 543, ShortValue = 12, UShortValue = 42, LongValue = 400002340000000L, ULongValue = 600000964000000UL, ByteValue = 0xF3, BoolValue = true, FloatValue = 921523.129521f, DoubleValue = 192510921421.012351298d, StringValue = "testString", StringValues = new List <string>() { "first", "second", "third" }, DoubleValues = new [] { 24521.523d, 12451251.9957d } }; using (var stream = new MemoryStream()) using (var serializer = new BigObjectSerializer(stream)) { serializer.PushObject(basicPoco); serializer.Flush(); serializedStream = stream.ToArray(); } using (var stream = new MemoryStream(serializedStream)) using (var deserializer = new BigObjectDeserializer(stream)) { var deserializedBasicPoco = deserializer.PopObject <BasicPoco>(); Assert.Equal(basicPoco.NullStringValue, deserializedBasicPoco.NullStringValue); Assert.True(basicPoco.IntValues.SequenceEqual(deserializedBasicPoco.IntValues)); Assert.Equal(basicPoco.IntValue, deserializedBasicPoco.IntValue); Assert.Equal(basicPoco.UintValue, deserializedBasicPoco.UintValue); Assert.Equal(basicPoco.ShortValue, deserializedBasicPoco.ShortValue); Assert.Equal(basicPoco.UShortValue, deserializedBasicPoco.UShortValue); Assert.Equal(basicPoco.LongValue, deserializedBasicPoco.LongValue); Assert.Equal(basicPoco.ULongValue, deserializedBasicPoco.ULongValue); Assert.Equal(basicPoco.ByteValue, deserializedBasicPoco.ByteValue); Assert.Equal(basicPoco.FloatValue, deserializedBasicPoco.FloatValue); Assert.Equal(basicPoco.DoubleValue, deserializedBasicPoco.DoubleValue); Assert.Equal(basicPoco.StringValue, deserializedBasicPoco.StringValue); Assert.True(basicPoco.StringValues.SequenceEqual(deserializedBasicPoco.StringValues)); Assert.True(basicPoco.DoubleValues.SequenceEqual(deserializedBasicPoco.DoubleValues)); } }
public async Task BasicFileStreamReflectiveSerialization() { var basicPoco = new BasicPoco() { NullStringValue = null, IntValues = new List <int>() { 56, 57, 58 }, IntValue = 238, UintValue = 543, ShortValue = 12, UShortValue = 42, LongValue = 400002340000000L, ULongValue = 600000964000000UL, ByteValue = 0xF3, BoolValue = true, FloatValue = 921523.129521f, DoubleValue = 192510921421.012351298d, StringValue = "testString", StringValues = new List <string>() { "first", "second", "third" }, DoubleValues = new[] { 24521.523d, 12451251.9957d } }; using (var stream = File.Open("test.bin", FileMode.Create)) using (var serializer = new BigObjectSerializer(stream)) { serializer.PushObject(basicPoco); serializer.Flush(); } await Task.Delay(1000); // Give time to release control of file using (var stream = File.Open("test.bin", FileMode.Open)) using (var deserializer = new BigObjectDeserializer(stream)) { var deserializedBasicPoco = deserializer.PopObject <BasicPoco>(); Assert.Equal(basicPoco.NullStringValue, deserializedBasicPoco.NullStringValue); Assert.True(basicPoco.IntValues.SequenceEqual(deserializedBasicPoco.IntValues)); Assert.Equal(basicPoco.IntValue, deserializedBasicPoco.IntValue); Assert.Equal(basicPoco.UintValue, deserializedBasicPoco.UintValue); Assert.Equal(basicPoco.ShortValue, deserializedBasicPoco.ShortValue); Assert.Equal(basicPoco.UShortValue, deserializedBasicPoco.UShortValue); Assert.Equal(basicPoco.LongValue, deserializedBasicPoco.LongValue); Assert.Equal(basicPoco.ULongValue, deserializedBasicPoco.ULongValue); Assert.Equal(basicPoco.ByteValue, deserializedBasicPoco.ByteValue); Assert.Equal(basicPoco.FloatValue, deserializedBasicPoco.FloatValue); Assert.Equal(basicPoco.DoubleValue, deserializedBasicPoco.DoubleValue); Assert.Equal(basicPoco.StringValue, deserializedBasicPoco.StringValue); Assert.True(basicPoco.StringValues.SequenceEqual(deserializedBasicPoco.StringValues)); Assert.True(basicPoco.DoubleValues.SequenceEqual(deserializedBasicPoco.DoubleValues)); } }