Example #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
            }));
        }
        public void ShouldHavePropertName()
        {
            PropertyInfo info = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            Assert.That(property.Name, Is.EqualTo("Value"));
        }
Example #3
0
        public void ShouldDeserializeValueToInstance()
        {
            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);

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

            MemoryMock memory = new MemoryMock(new byte[]
            {
                0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63,
                0x00, 0x00, 0x00, 0x03, 0x63, 0x64, 0x65
            });

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(22));
            Assert.That(item.Entries[0].Value, Is.EqualTo("abc"));
            Assert.That(item.Entries[1].Value, Is.EqualTo("cde"));
        }
        public void ShouldSetNullableValueInInstance()
        {
            Nullable     nullable = new Nullable();
            PropertyInfo info     = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            property.SetValue(nullable, 123);
            Assert.That(nullable.Value, Is.EqualTo(123));
        }
        public void ShouldSetValueInInstance()
        {
            Regular      regular = new Regular();
            PropertyInfo info    = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            property.SetValue(regular, "cde");
            Assert.That(regular.Value, Is.EqualTo("cde"));
        }
        public void ShouldStillHavePropertNameAfterCasting()
        {
            PropertyInfo info = typeof(Regular).GetProperty("Value");

            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);
            ReflectorProperty <Regular, string> casted   = property.Cast(x => x.ToLower(), x => x.ToUpper());

            Assert.That(casted.Name, Is.EqualTo("Value"));
        }
        public void ShouldSetNullInNullablePrimitiveInInstance()
        {
            Nullable     nullable = new Nullable();
            PropertyInfo info     = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            property.SetNull(nullable);
            Assert.That(nullable.Value, Is.Null);
        }
        public void ShouldGetNullableValue()
        {
            Nullable nullable = new Nullable {
                Value = 123
            };
            PropertyInfo info = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            Assert.That(property.GetValue(nullable), Is.EqualTo(123));
        }
        public void ShouldGetValue()
        {
            Regular regular = new Regular {
                Value = "abc"
            };
            PropertyInfo info = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            Assert.That(property.GetValue(regular), Is.EqualTo("abc"));
        }
        public void ShouldFindNullInNullableString()
        {
            Regular regular = new Regular {
                Value = null
            };
            PropertyInfo info = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            Assert.That(property.IsNull(regular), Is.True);
        }
        public void ShouldFindNullInNullablePrimitive()
        {
            Nullable nullable = new Nullable {
                Value = null
            };
            PropertyInfo info = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            Assert.That(property.IsNull(nullable), Is.True);
        }
        public void ShouldHandleCastedSetConversionInInstance()
        {
            Regular      regular = new Regular();
            PropertyInfo info    = typeof(Regular).GetProperty("Value");

            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);
            ReflectorProperty <Regular, string> casted   = property.Cast(x => x.ToLower(), x => x.ToUpper());

            casted.SetValue(regular, "cDe");
            Assert.That(regular.Value, Is.EqualTo("CDE"));
        }
        public void ShouldSetNullInNullableStringInInstance()
        {
            Regular regular = new Regular {
                Value = "abc"
            };
            PropertyInfo info = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            property.SetNull(regular);
            Assert.That(regular.Value, Is.Null);
        }
        public void ShouldSetNullableValueToNullInInstance()
        {
            Nullable nullable = new Nullable {
                Value = 10
            };
            PropertyInfo info = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            property.SetValue(nullable, null);
            Assert.That(nullable.Value, Is.Null);
        }
        public void ShouldSetNullableValueToNullInSubstitute()
        {
            Addressable           source     = new MemoryMock();
            Serializer <Nullable> serializer = new Serializer <Nullable>();
            Substitute <Nullable> nullable   = new Substitute <Nullable>(serializer, source);

            PropertyInfo info = typeof(Nullable).GetProperty("Value");
            ReflectorProperty <Nullable, long?> property = new ReflectorProperty <Nullable, long?>(info);

            property.SetValue(nullable, () => null);
            Assert.That(nullable.AsDynamic().Value, Is.Null);
        }
        public void ShouldSetNullInNullableStringInSubstitute()
        {
            Addressable          source     = new MemoryMock();
            Serializer <Regular> serializer = new Serializer <Regular>();
            Substitute <Regular> regular    = new Substitute <Regular>(serializer, source);

            PropertyInfo info = typeof(Regular).GetProperty("Value");
            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);

            property.SetNull(regular);
            Assert.That(regular.AsDynamic().Value, Is.Null);
        }
        public void ShouldHandleCastedGetConversion()
        {
            Regular item = new Regular {
                Value = "aBc"
            };
            PropertyInfo info = typeof(Regular).GetProperty("Value");

            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);
            ReflectorProperty <Regular, string> casted   = property.Cast(x => x.ToLower(), x => x.ToUpper());

            Assert.That(casted.GetValue(item), Is.EqualTo("abc"));
        }
Example #18
0
        public void ShouldDeserializeNullToSubstitute()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Member <Item> member = new MemberString <Item>(property);
            MemoryMock    memory = new MemoryMock(new byte[] { 0xff, 0xff, 0xff, 0xff });

            Serializer <Item> serializer = new Serializer <Item>(member);
            Substitute <Item> item       = new Substitute <Item>(serializer, memory);

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(4));
            Assert.That(item.AsDynamic().Value, Is.Null);
        }
Example #19
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 }));
        }
        public void ShouldHandleCastedSetConversionInSubstitute()
        {
            Addressable          source     = new MemoryMock();
            Serializer <Regular> serializer = new Serializer <Regular>();

            PropertyInfo         info    = typeof(Regular).GetProperty("Value");
            Substitute <Regular> regular = new Substitute <Regular>(serializer, source);

            ReflectorProperty <Regular, string> property = new ReflectorProperty <Regular, string>(info);
            ReflectorProperty <Regular, string> casted   = property.Cast(x => x.ToLower(), x => x.ToUpper());

            casted.SetValue(regular, () => "cDe");
            Assert.That(regular.AsDynamic().Value, Is.EqualTo("CDE"));
        }
Example #21
0
        public void ShouldDeserializeNullToInstance()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Member <Item> member = new MemberString <Item>(property);
            MemoryMock    memory = new MemoryMock(new byte[] { 0xff, 0xff, 0xff, 0xff });
            Item          item   = new Item {
                Value = "abc"
            };

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(4));
            Assert.That(item.Value, Is.Null);
        }
Example #22
0
        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 }));
        }
Example #23
0
        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")));
        }
Example #24
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 }));
        }
Example #25
0
        public void ShouldDeserializeValueToInstance()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, Int64> property = new ReflectorProperty <Item, long>(info);

            Item          item   = new Item();
            Member <Item> member = new MemberInt64 <Item>(property);

            MemoryMock memory = new MemoryMock(new byte[]
            {
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
            });

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(8));
            Assert.That(item.Value, Is.EqualTo(0x0102030405060708));
        }
Example #26
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);
        }
Example #27
0
        public void ShouldDeserializeValueToInstance()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Item          item   = new Item();
            Member <Item> member = new MemberString <Item>(property);

            MemoryMock memory = new MemoryMock(new byte[]
            {
                0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63
            });

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(7));
            Assert.That(item.Value, Is.EqualTo("abc"));
        }
Example #28
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
            }));
        }
Example #29
0
        public void ShouldDeserializeOnlySize()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, String> property = new ReflectorProperty <Item, String>(info);

            Member <Item>     member     = new MemberString <Item>(property);
            Serializer <Item> serializer = new Serializer <Item>(member);

            MemoryMock memory = new MemoryMock(new byte[]
            {
                0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63
            });

            Substitute <Item> item = new Substitute <Item>(serializer, memory);

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(7));
            Assert.That(memory.Accessed, Is.EqualTo(new[] { 0, 1, 2, 3 }));
        }
Example #30
0
        public void ShouldNotDeserializeData()
        {
            PropertyInfo info = typeof(Item).GetProperty("Value");
            ReflectorProperty <Item, Int64> property = new ReflectorProperty <Item, long>(info);

            Member <Item>     member     = new MemberInt64 <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[]
            {
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
            });

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