Пример #1
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            foreach (var guid in container.Guids)
            {
                var node = container.GetModelNode(guid);
                if (model != node)
                {
                    Console.WriteLine(node.PrintHierarchy());
                }
            }

            Assert.That(model.GetChild("IntList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("IntList").Content.Value, Is.SameAs(obj.IntList));
            Assert.That(model.GetChild("IntList").Content.IsReference, Is.False);
            Assert.That(model.GetChild("ClassList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ClassList").Content.Value, Is.SameAs(obj.ClassList));
            Assert.That(model.GetChild("ClassList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }
            Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }

            Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            Assert.That(container.Guids.Count(), Is.EqualTo(14));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Пример #2
0
        public void TestStructItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            var objRef = ((ReferenceEnumerable)model.GetChild("SimpleStructList").Content.Reference).First();

            objRef.TargetNode.GetChild("SecondValue").Content.Value = 32;
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.SimpleStructList[0].SecondValue, Is.EqualTo(32));
            Helper.ConsistencyCheck(container, obj);
        }
Пример #3
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            ((List <int>)model.GetChild("IntList").Content.Value)[1] = 42;
            ((List <int>)model.GetChild("IntList").Content.Value).Add(26);
            Assert.That(obj.IntList.Count, Is.EqualTo(4));
            Assert.That(obj.IntList[1], Is.EqualTo(42));
            Assert.That(obj.IntList[3], Is.EqualTo(26));
            Helper.ConsistencyCheck(container, obj);
        }
Пример #4
0
        public void TestListOfNestedStructListsUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            var listRef    = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last();
            var objRef     = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last();
            var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid);

            structNode.GetChild("SecondValue").Content.Value = 32;
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32));
            Helper.ConsistencyCheck(container, obj);
        }
Пример #5
0
        public void TestNestedStructItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            var objRef     = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First();
            var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid);

            structNode.GetChild("SecondValue").Content.Value = 32;
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
            Helper.ConsistencyCheck(container, obj);
        }
Пример #6
0
        public void TestNestedStructItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First();

            objRef.TargetNode.GetChild("Struct").GetChild("SecondValue").Content.Value = 32;
            Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Пример #7
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            ((List <int>)model.GetChild("IntList").Content.Value)[1] = 42;
            ((List <int>)model.GetChild("IntList").Content.Value).Add(26);
            Assert.That(obj.IntList.Count, Is.EqualTo(4));
            Assert.That(obj.IntList[1], Is.EqualTo(42));
            Assert.That(obj.IntList[3], Is.EqualTo(26));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Пример #8
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);

            Assert.That(model.GetChild("IntList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("IntList").Content.Value, Is.SameAs(obj.IntList));
            Assert.That(model.GetChild("IntList").Content.IsReference, Is.False);
            Assert.That(model.GetChild("ClassList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ClassList").Content.Value, Is.SameAs(obj.ClassList));
            Assert.That(model.GetChild("ClassList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model.GetChild("ListOfSimpleStructLists").Content.Reference.AsEnumerable)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }
            Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model.GetChild("ListOfNestedStructLists").Content.Reference.AsEnumerable)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }

            Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            Assert.That(container.Guids.Count(), Is.EqualTo(18));
            Helper.ConsistencyCheck(container, obj);
        }
Пример #9
0
        public void TestConstruction()
        {
            var obj = new ClassWithLists();
            var container = new ModelContainer();
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
            Helper.PrintModelContainerContent(container, model);

            Assert.That(model.GetChild("IntList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("IntList").Content.Value, Is.SameAs(obj.IntList));
            Assert.That(model.GetChild("IntList").Content.IsReference, Is.False);
            Assert.That(model.GetChild("ClassList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ClassList").Content.Value, Is.SameAs(obj.ClassList));
            Assert.That(model.GetChild("ClassList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model.GetChild("ListOfSimpleStructLists").Content.Reference.AsEnumerable)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }
            Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model.GetChild("ListOfNestedStructLists").Content.Reference.AsEnumerable)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }

            Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            Assert.That(container.Guids.Count(), Is.EqualTo(18));
            Helper.ConsistencyCheck(container, obj);
        }
Пример #10
0
 public void TestListOfNestedStructListsUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, model);
     var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last();
     var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last();
     var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid);
     structNode.GetChild("SecondValue").Content.Value = 32;
     Helper.PrintModelContainerContent(container, model);
     Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32));
     Helper.ConsistencyCheck(container, obj);
 }
Пример #11
0
 public void TestNestedStructItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, model);
     var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First();
     var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid);
     structNode.GetChild("SecondValue").Content.Value = 32;
     Helper.PrintModelContainerContent(container, model);
     Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32));
     var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
     visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
     Helper.ConsistencyCheck(container, obj);
 }
Пример #12
0
 public void TestStructItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, model);
     var objRef = ((ReferenceEnumerable)model.GetChild("SimpleStructList").Content.Reference).First();
     objRef.TargetNode.GetChild("SecondValue").Content.Value = 32;
     Helper.PrintModelContainerContent(container, model);
     Assert.That(obj.SimpleStructList[0].SecondValue, Is.EqualTo(32));
     Helper.ConsistencyCheck(container, obj);
 }
Пример #13
0
 public void TestPrimitiveItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Console.WriteLine(model.PrintHierarchy());
     ((List<int>)model.GetChild("IntList").Content.Value)[1] = 42;
     ((List<int>)model.GetChild("IntList").Content.Value).Add(26);
     Assert.That(obj.IntList.Count, Is.EqualTo(4));
     Assert.That(obj.IntList[1], Is.EqualTo(42));
     Assert.That(obj.IntList[3], Is.EqualTo(26));
     Helper.ConsistencyCheck(container, obj);
 }
Пример #14
0
        public void TestConstruction()
        {
            var obj = new ClassWithLists();
            var container = new ModelContainer();
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
            Console.WriteLine(model.PrintHierarchy());
            foreach (var guid in container.Guids)
            {
                var node = container.GetModelNode(guid);
                if (model != node)
                    Console.WriteLine(node.PrintHierarchy());
            }

            Assert.That(model.GetChild("IntList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("IntList").Content.Value, Is.SameAs(obj.IntList));
            Assert.That(model.GetChild("IntList").Content.IsReference, Is.False);
            Assert.That(model.GetChild("ClassList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ClassList").Content.Value, Is.SameAs(obj.ClassList));
            Assert.That(model.GetChild("ClassList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }
            Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }

            Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            Assert.That(container.Guids.Count(), Is.EqualTo(14));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Пример #15
0
 public void TestListOfNestedStructListsUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Console.WriteLine(model.PrintHierarchy());
     var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last();
     var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last();
     objRef.TargetNode.GetChild("Struct").GetChild("SecondValue").Content.Value = 32;
     Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32));
     var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
     visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
     foreach (var node in container.Models)
     {
         visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
     }
 }
Пример #16
0
 public void TestPrimitiveItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Console.WriteLine(model.PrintHierarchy());
     ((List<int>)model.GetChild("IntList").Content.Value)[1] = 42;
     ((List<int>)model.GetChild("IntList").Content.Value).Add(26);
     Assert.That(obj.IntList.Count, Is.EqualTo(4));
     Assert.That(obj.IntList[1], Is.EqualTo(42));
     Assert.That(obj.IntList[3], Is.EqualTo(26));
     var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
     visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true);
     foreach (var node in container.Models)
     {
         visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
     }
 }