コード例 #1
0
        public void CollectionArrayTest()
        {
            var value = new CollectionSourceData {
                Items = new List <string> {
                    "A", "B", "C"
                }
            };
            var manager = new SerializationManager(new BuiltInTypesSerializer(), new CollectionSerializer <string>());

            using (var ms = new MemoryStream())
            {
                var s = new ObjectSerializer <ICollectionData, CollectionArrayData>();
                Assert.True(s.CanSerialize(value, manager));
                using (var bw = new BinaryWriter(ms, Encoding.UTF8, true))
                    s.Serialize(value, bw, manager);
                ms.Position = 0;
                using (var br = new BinaryReader(ms, Encoding.UTF8, true))
                {
                    var res = s.Deserialize(br, manager) as ICollectionData;
                    Assert.NotNull(res);
                    Assert.NotNull(res.Items);
                    Assert.Empty(res.Items);
                }
            }
        }
コード例 #2
0
        public void EnumTest()
        {
            var value = new EnumData {
                Enum = TestEnum.B
            };
            var manager = new SerializationManager(new BuiltInTypesSerializer(), new EnumSerializer <TestEnum>());

            using (var ms = new MemoryStream())
            {
                var s = new ObjectSerializer <EnumData>();
                Assert.True(s.CanSerialize(value, manager));
                using (var bw = new BinaryWriter(ms, Encoding.UTF8, true))
                    s.Serialize(value, bw, manager);
                ms.Position = 0;
                using (var br = new BinaryReader(ms, Encoding.UTF8, true))
                {
                    var res = s.Deserialize(br, manager) as EnumData;
                    Assert.NotNull(res);
                    Assert.Equal(value.Enum, res.Enum);
                }
            }
        }