Пример #1
0
        public void ShouldSerializeValue()
        {
            PropertyInfo valueInfo = typeof(Item).GetProperty("Entries");
            ReflectorProperty <Item, Entry[]> valueProperty = new ReflectorProperty <Item, Entry[]>(valueInfo);

            PropertyInfo nestedInfo = typeof(Entry).GetProperty("Value");
            ReflectorProperty <Entry, String> nestedProperty = new ReflectorProperty <Entry, string>(nestedInfo);

            Member <Entry>     nestedMember = new MemberString <Entry>(nestedProperty);
            Serializer <Entry> nested       = new Serializer <Entry>(nestedMember);

            Member <Item> member = new MemberArray <Item, Entry>(valueProperty, nested);
            Item          item   = new Item {
                Entries = new[] { new Entry {
                                      Value = "abc"
                                  }, new Entry {
                                      Value = "cde"
                                  } }
            };

            MemoryMock memory = new MemoryMock(30);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(22));
            Assert.That(memory.GetData(22), Is.EqualTo(new[]
            {
                0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63,
                0x00, 0x00, 0x00, 0x03, 0x63, 0x64, 0x65
            }));
        }
Пример #2
0
        public void ShouldSerializeNull()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Member <Item> member = new MemberString <Item>(property);
            Item          item   = new Item {
                Value = null
            };
            MemoryMock memory = new MemoryMock(20);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(4));
            Assert.That(memory.GetData(4), Is.EqualTo(new[] { 0xff, 0xff, 0xff, 0xff }));
        }
Пример #3
0
        public void ShouldSerializeNull()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, Int64?> property = new ReflectorProperty <Item, Int64?>(info);

            Member <Item> member   = new MemberInt64 <Item>(property);
            Member <Item> nullable = new MemberNullable <Item, Int64?>(member, property);

            Item item = new Item {
                Value = null
            };
            MemoryMock memory = new MemoryMock(20);

            Assert.That(nullable.Transfer(item, memory, 0), Is.EqualTo(1));
            Assert.That(memory.GetData(1), Is.EqualTo(new[] { 0x00 }));
        }
Пример #4
0
        public void ShouldTransferItemToMemory()
        {
            Serializer <Item> serializer = new Serializer <Item>(
                new MemberMock(7), new MemberMock(13));

            MemoryMock mock = new MemoryMock(100);

            serializer.Transfer(new Item {
                Value = 10
            }, mock);

            Assert.That(mock.GetData(20), Is.EqualTo(new[]
            {
                70, 70, 70, 70, 70, 70, 70, 130, 130, 130,
                130, 130, 130, 130, 130, 130, 130, 130, 130, 130
            }));
        }
Пример #5
0
        public void ShouldSerializeValue()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Member <Item> member = new MemberString <Item>(property);
            Item          item   = new Item {
                Value = "abc"
            };
            MemoryMock memory = new MemoryMock(20);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(7));
            Assert.That(memory.GetData(7), Is.EqualTo(new[]
            {
                0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63
            }));
        }
Пример #6
0
        public void ShouldSerializeValue()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, Int64> property = new ReflectorProperty <Item, long>(info);

            Member <Item> member = new MemberInt64 <Item>(property);
            Item          item   = new Item {
                Value = 0x0102030405060708
            };

            MemoryMock memory = new MemoryMock(20);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(8));

            Assert.That(memory.GetData(8), Is.EqualTo(new[]
            {
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
            }));
        }
Пример #7
0
        public void ShouldSerializeValue()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, DateTime> property = new ReflectorProperty <Item, DateTime>(info);

            Member <Item> member = new MemberDateTime <Item>(property);
            Item          item   = new Item {
                Value = DateTime.Parse("2013-07-04 12:31:10")
            };

            MemoryMock memory = new MemoryMock(20);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(8));

            Assert.That(memory.GetData(8), Is.EqualTo(new[]
            {
                0x08, 0xd0, 0x46, 0xc9, 0x7f, 0x75, 0x3b, 0x00
            }));
        }
Пример #8
0
        public void ShouldSerializeNull()
        {
            PropertyInfo valueInfo = typeof(Item).GetProperty("Entries");
            ReflectorProperty <Item, Entry[]> valueProperty = new ReflectorProperty <Item, Entry[]>(valueInfo);

            PropertyInfo nestedInfo = typeof(Entry).GetProperty("Value");
            ReflectorProperty <Entry, String> nestedProperty = new ReflectorProperty <Entry, string>(nestedInfo);

            Member <Entry>     nestedMember = new MemberString <Entry>(nestedProperty);
            Serializer <Entry> nested       = new Serializer <Entry>(nestedMember);

            Member <Item> member = new MemberArray <Item, Entry>(valueProperty, nested);
            Item          item   = new Item {
                Entries = null
            };

            MemoryMock memory = new MemoryMock(20);

            Assert.That(member.Transfer(item, memory, 0), Is.EqualTo(8));
            Assert.That(memory.GetData(8), Is.EqualTo(new[]
            {
                0x00, 0x00, 0x00, 0x08, 0xff, 0xff, 0xff, 0xff
            }));
        }