Exemple #1
0
        public void InspectObject_With_IEnumerableProperty()
        {
            var @object = new ClassWithSimpleClassList();

            @object.Id      = 1;
            @object.Objects = new List <SimpleClass>
            {
                new SimpleClass {
                    Id = 1, Name = "object 1"
                },
                new SimpleClass {
                    Id = 2, Name = "object 2"
                },
                new SimpleClass {
                    Id = 3, Name = "object 3"
                },
            };
            var childrenFouded = 0;

            _objectInspector.InspectObject(@object, (value) =>
            {
                if (typeof(SimpleClass) == value.GetType())
                {
                    childrenFouded++;
                }
            });

            Assert.AreEqual(3, childrenFouded);
        }
Exemple #2
0
        public void LoadObject_With_IEnumerableProperty()
        {
            var @object = new ClassWithSimpleClassList();

            @object.Id      = 1;
            @object.Objects = new List <SimpleClass>
            {
                new SimpleClass {
                    Id = 1, Name = "object 1"
                },
                new SimpleClass {
                    Id = 2, Name = "object 2"
                },
                new SimpleClass {
                    Id = 3, Name = "object 3"
                },
            };

            var newList = new List <SimpleClass>
            {
                new SimpleClass {
                    Id = 1, Name = "object 1 new"
                },
                new SimpleClass {
                    Id = 2, Name = "object 2 new"
                },
                new SimpleClass {
                    Id = 3, Name = "object 3 new"
                },
            };

            _objectInspector.LoadObject(@object, (value) =>
            {
                var result = value;
                var item   = value as SimpleClass;
                if (item != null)
                {
                    result = newList.FirstOrDefault(p => p.Id == item.Id);
                }

                return(result);
            });

            Assert.AreSame(newList[0], @object.Objects[0]);
            Assert.AreSame(newList[1], @object.Objects[1]);
            Assert.AreSame(newList[2], @object.Objects[2]);
        }
        public void InspectObject_With_IEnumerableProperty()
        {
            var @object = new ClassWithSimpleClassList();
            @object.Id = 1;
            @object.Objects = new List<SimpleClass>
            {
                new SimpleClass { Id = 1, Name = "object 1" },
                new SimpleClass { Id = 2, Name = "object 2" },
                new SimpleClass { Id = 3, Name = "object 3" },
            };
            var childrenFouded = 0;

            _objectInspector.InspectObject(@object, (value) =>
            {
                if (typeof(SimpleClass) == value.GetType())
                    childrenFouded++;
            });

            Assert.AreEqual(3, childrenFouded);
        }
        public void LoadObject_With_IEnumerableProperty()
        {
            var @object = new ClassWithSimpleClassList();
            @object.Id = 1;
            @object.Objects = new List<SimpleClass>
            {
                new SimpleClass { Id = 1, Name = "object 1" },
                new SimpleClass { Id = 2, Name = "object 2" },
                new SimpleClass { Id = 3, Name = "object 3" },
            };

            var newList = new List<SimpleClass>
            {
                new SimpleClass { Id = 1, Name = "object 1 new" },
                new SimpleClass { Id = 2, Name = "object 2 new" },
                new SimpleClass { Id = 3, Name = "object 3 new" },
            };

            _objectInspector.LoadObject(@object, (value) =>
            {
                var result = value;
                var item = value as SimpleClass;
                if (item != null)
                {
                    result = newList.FirstOrDefault(p => p.Id == item.Id);
                }

                return result;
            });

            Assert.AreSame(newList[0], @object.Objects[0]);
            Assert.AreSame(newList[1], @object.Objects[1]);
            Assert.AreSame(newList[2], @object.Objects[2]);
        }