Beispiel #1
0
        public void TestVisitPrimitive()
        {
            var simpleObject = new SimpleObject(1, 2, 3, 4)
            {
                Name = "Test", MemberToIgnore = int.MaxValue, SubObject = new SimpleObject(5, 6, 7, 8)
            };
            var primitiveGrabber = new PrimitiveGrabber();

            primitiveGrabber.Visit(simpleObject);
            Assert.AreEqual(new List <object>()
            {
                1,
                2,
                3,
                4,
                "Test",
                1234,  // SimpleObject.ReadOnlyValue
                5,     // simpleObject.SubObject
                6,
                7,
                8,
                null,    // simpleObject.SubObject.Name
                1234,    // SimpleObject.ReadOnlyValue
                null     // simpleObject.SubObject.SubObject
            }, primitiveGrabber.Collected);

            simpleObject.Collection.Add("Item1");
            simpleObject.Collection.Add("Item2");

            simpleObject.Dictionary.Add("Key1", "Value1");
            simpleObject.Dictionary.Add("Key2", "Value2");

            primitiveGrabber.Reset();
            primitiveGrabber.Visit(simpleObject);
            Assert.AreEqual(new List <object>()
            {
                1,
                2,
                3,
                4,
                "Test",
                "Item1", "Item2",                   // simpleObject.Collection
                "Key1", "Value1", "Key2", "Value2", // simpleObject.Dictionary
                1234,                               // SimpleObject.ReadOnlyValue
                5,                                  // simpleObject.SubObject
                6,
                7,
                8,
                null,    // simpleObject.SubObject.Name
                1234,    // SimpleObject.ReadOnlyValue
                null     // simpleObject.SubObject.SubObject
            }, primitiveGrabber.Collected);
        }
        public void TestArray()
        {
            var customArray      = new[] { 1, 2, 3, 4 };
            var primitiveGrabber = new PrimitiveGrabber();

            primitiveGrabber.Visit(customArray);
            Assert.AreEqual(new List <object>
            {
                1, 2, 3, 4
            }, primitiveGrabber.Collected);
        }
        public void TestDictionary()
        {
            var customDict = new CustomDictionary()
            {
                { "Key1", "Value1" }, { "Key2", "Value2" }
            };

            customDict.CustomId = 10;
            customDict.Name     = "Test";
            var primitiveGrabber = new PrimitiveGrabber();

            primitiveGrabber.Visit(customDict);
            Assert.AreEqual(new List <object>()
            {
                10,     // customList.CustomId
                "Test", // customList.Name
                "Key1", "Value1",
                "Key2", "Value2",
            }, primitiveGrabber.Collected);
        }
        public void TestCollection()
        {
            var customList = new CustomList()
            {
                1, 2, 3, 4
            };

            customList.CustomId = 10;
            customList.Name     = "Test";
            var primitiveGrabber = new PrimitiveGrabber();

            primitiveGrabber.Visit(customList);
            Assert.AreEqual(new List <object>()
            {
                10,     // customList.CustomId
                "Test", // customList.Name
                1,
                2,
                3,
                4,
            }, primitiveGrabber.Collected);
        }