コード例 #1
0
ファイル: MemberArrayTests.cs プロジェクト: amacal/collector
        public void ShouldDeserializeValueToSubstitute()
        {
            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);
            Serializer <Item> serializer = new Serializer <Item>(member);

            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
            });

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

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

            Assert.That(item.AsDynamic().Entries[0].Value.ToString(), Is.EqualTo("abc"));
            Assert.That(item.AsDynamic().Entries[1].Value.ToString(), Is.EqualTo("cde"));
        }
コード例 #2
0
        public void ShouldAccessRegisteredProperty()
        {
            Reflector         reflector  = new Reflector();
            Serializer <Item> serializer = reflector.GetSerializer <Item>();

            Addressable       source = new MemoryMock();
            Substitute <Item> data   = new Substitute <Item>(serializer, source);

            data.Add("Value", () => 10);
            Assert.That(data.AsDynamic().Value, Is.EqualTo(10));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
ファイル: MemberStringTests.cs プロジェクト: amacal/collector
        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);
        }
コード例 #7
0
        public void ShouldDeserializeNullToSubstitute()
        {
            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);

            Serializer <Item> serializer = new Serializer <Item>(nullable);
            MemoryMock        memory     = new MemoryMock(new byte[] { 0x00 });
            Substitute <Item> item       = new Substitute <Item>(serializer, memory);

            Assert.That(nullable.Transfer(memory, 0, item), Is.EqualTo(1));
            Assert.That(item.AsDynamic().Value, Is.Null);
        }
コード例 #8
0
        public void ShouldCastToAnotherObject()
        {
            Reflector         reflector  = new Reflector();
            Serializer <Item> serializer = reflector.GetSerializer <Item>();

            Addressable source = new MemoryMock(new byte[]
            {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a
            });

            Substitute <Item> data = new Substitute <Item>(serializer, source);

            Item item = data.AsDynamic();

            Assert.That(item.Value, Is.EqualTo(10));
        }
コード例 #9
0
        public void ShouldTransferMemoryToSubstitute()
        {
            Serializer <Item> serializer = new Serializer <Item>(
                new MemberMock(7), new MemberMock(13));

            MemoryMock mock = new MemoryMock(new byte[]
            {
                70, 70, 70, 70, 70, 70, 70, 130, 130, 130,
                130, 130, 130, 130, 130, 130, 130, 130, 130, 130
            });

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

            serializer.Transfer(mock, item);

            Assert.That(item.AsDynamic().Value, Is.EqualTo(10));
        }
コード例 #10
0
ファイル: MemberInt64Tests.cs プロジェクト: amacal/collector
        public void ShouldDeserializeValueToSubstitute()
        {
            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(item.AsDynamic().Value, Is.EqualTo(0x0102030405060708));
        }
コード例 #11
0
        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")));
        }
コード例 #12
0
ファイル: MemberStringTests.cs プロジェクト: amacal/collector
        public void ShouldDeserializeOnlySizeEvenIfSizeAccessed()
        {
            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(item.AsDynamic().Value.Size, Is.EqualTo(3));
            Assert.That(memory.Accessed, Is.EqualTo(new[] { 0, 1, 2, 3 }));
        }
コード例 #13
0
ファイル: MemberArrayTests.cs プロジェクト: amacal/collector
        public void ShouldDeserializeNullToSubstitute()
        {
            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);
            Serializer <Item> serializer = new Serializer <Item>(member);

            MemoryMock memory = new MemoryMock(new byte[]
            {
                0x00, 0x00, 0x00, 0x08, 0xff, 0xff, 0xff, 0xff
            });

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

            Assert.That(member.Transfer(memory, 0, item), Is.EqualTo(8));
            Assert.That(item.AsDynamic().Entries, Is.Null);
        }