public void ShouldDeserializeNullFlag() { 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); MemoryMock memory = new MemoryMock(new byte[] { 0x00 }); Serializer <Item> serializer = new Serializer <Item>(nullable); Substitute <Item> item = new Substitute <Item>(serializer, memory); Assert.That(nullable.Transfer(memory, 0, item), Is.EqualTo(1)); Assert.That(memory.Accessed, Is.EqualTo(new[] { 0 })); }
public void ShouldDeserializeNullToInstance() { 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 = 12 }; MemoryMock memory = new MemoryMock(new byte[] { 0x00 }); Assert.That(nullable.Transfer(memory, 0, item), Is.EqualTo(1)); Assert.That(item.Value, Is.Null); }
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 })); }
public void ShouldDeserializeValueToInstance() { PropertyInfo info = typeof(Item).GetProperty("Value"); ReflectorProperty <Item, DateTime> property = new ReflectorProperty <Item, DateTime>(info); Item item = new Item(); Member <Item> member = new MemberDateTime <Item>(property); MemoryMock memory = new MemoryMock(new byte[] { 0x08, 0xd0, 0x46, 0xc9, 0x7f, 0x75, 0x3b, 0x00 }); Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(8)); Assert.That(item.Value, Is.EqualTo(DateTime.Parse("2013-07-04 12:31:10"))); }
public void ShouldDeserializeValueToSubstitute() { 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); MemoryMock memory = new MemoryMock(new byte[] { 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }); Serializer <Item> serializer = new Serializer <Item>(nullable); Substitute <Item> item = new Substitute <Item>(serializer, memory); Assert.That(nullable.Transfer(memory, 0, item), Is.EqualTo(9)); Assert.That(item.AsDynamic().Value, Is.EqualTo(0x0102030405060708)); }
public void ShouldNotDeserializeData() { PropertyInfo info = typeof(Item).GetProperty("Value"); ReflectorProperty <Item, DateTime> property = new ReflectorProperty <Item, DateTime>(info); Member <Item> member = new MemberDateTime <Item>(property); Serializer <Item> serializer = new Serializer <Item>(member); Addressable source = new MemoryMock(); Substitute <Item> item = new Substitute <Item>(serializer, source); MemoryMock memory = new MemoryMock(new byte[] { 0x08, 0xd0, 0x46, 0xc9, 0x7f, 0x75, 0x3b, 0x00 }); Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(8)); Assert.That(memory.Accessed, Is.Empty); }
public void ShouldDeserializeValueToSubstitute() { PropertyInfo info = typeof(Item).GetProperty("Value"); ReflectorProperty <Item, DateTime> property = new ReflectorProperty <Item, DateTime>(info); Member <Item> member = new MemberDateTime <Item>(property); Serializer <Item> serializer = new Serializer <Item>(member); Addressable source = new MemoryMock(); Substitute <Item> item = new Substitute <Item>(serializer, source); MemoryMock memory = new MemoryMock(new byte[] { 0x08, 0xd0, 0x46, 0xc9, 0x7f, 0x75, 0x3b, 0x00 }); Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(8)); Assert.That(item.AsDynamic().Value, Is.EqualTo(DateTime.Parse("2013-07-04 12:31:10"))); }
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 })); }