Esempio n. 1
0
        public void TestWrongIndexType()
        {
            var        typeToken = new TypeToken(typeof(SuperNestedType));
            Expression root      = Expression.Variable(typeof(SuperNestedType));
            var        idx       = 9;
            var        member    = typeToken.GetMemberByIndex(ref idx, ref root, TypeTokenType.Property);

            var dummyFile = new DummyFile <SuperNestedType>(3);

            var instance = new SuperNestedType
            {
                _1 = 3.14159265f,
                _2 = new FlatType[] {
                    new FlatType {
                        _1 = 210,
                        _2 = 2.20f,
                        _3 = "choo choo",
                        _4 = 240
                    },
                    new FlatType {
                        _1 = 211,
                        _2 = 2.21f,
                        _3 = "choo choo choo",
                        _4 = 241
                    }
                },
                _3 = new NestedType
                {
                    _1 = new FlatType
                    {
                        _1 = 311,
                        _2 = 31.2f,
                        _3 = "choo",
                        _4 = 314,
                    },
                    _2 = 3.2f,
                    _3 = "mother",
                    _4 = 34,
                },
                _4 = 4,
                _5 = "f****r",
                _6 = 6
            };

            var serializer = new SerializerMock <SuperNestedType>();
            var assertion  = Assert.ThrowsException <InvalidOperationException>(() => serializer.Initialize(dummyFile));

            Assert.IsTrue(assertion.Message.StartsWith("Invalid structure:"));
        }
Esempio n. 2
0
        public void TestNestedOnceIndexLookup()
        {
            var dummyFile = new DummyFile <SuperNestedType>(8);

            var instance = new SuperNestedType
            {
                _1 = 3.14159265f,
                _2 = new FlatType[] {
                    new FlatType {
                        _1 = 210,
                        _2 = 2.20f,
                        _3 = "choo choo",
                        _4 = 240
                    },
                    new FlatType {
                        _1 = 211,
                        _2 = 2.21f,
                        _3 = "choo choo choo",
                        _4 = 241
                    }
                },
                _3 = new NestedType
                {
                    _1 = new FlatType
                    {
                        _1 = 311,
                        _2 = 31.2f,
                        _3 = "choo",
                        _4 = 314,
                    },
                    _2 = 3.2f,
                    _3 = "mother",
                    _4 = 34,
                },
                _4 = 4,
                _5 = "f****r",
                _6 = 6
            };

            var serializer = new SerializerMock <SuperNestedType>();

            serializer.Initialize(dummyFile);

            var extractedKey = serializer.GetKey(instance);

            Assert.AreEqual(240, extractedKey);
        }