Exemplo n.º 1
0
        public void TestConstruction()
        {
            var obj       = new ClassWithStructs();
            var container = new ModelContainer();

            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);

            // Members should never have children
            Assert.That(model.GetChild("PrimitiveStruct").Children.Count, Is.EqualTo(0));
            // Primitive struct has been registered as a primitive type, so it should not hold a reference.
            Assert.Null(model.GetChild("PrimitiveStruct").Content.Reference);
            // Members should never have children.
            Assert.That(model.GetChild("NestedStruct").Children.Count, Is.EqualTo(0));
            // NestedStruct members should be accessible via a reference.
            Assert.NotNull(model.GetChild("NestedStruct").Content.Reference);
            // The referenced node must exist.
            var structNode = model.GetChild("NestedStruct").Content.Reference.AsObject.TargetNode;

            Assert.NotNull(structNode);
            // It should have two children, as the NestedStruct has.
            Assert.That(structNode.Children.Count, Is.EqualTo(2));
            // Similarly, the Struct member of the NestedStruct should hold a reference.
            Assert.NotNull(structNode.GetChild("Struct").Content.Reference);
            // The referenced node must exist.
            structNode = structNode.GetChild("Struct").Content.Reference.AsObject.TargetNode;
            Assert.NotNull(structNode);
            // It should have two children, as the SimpleStruct has.
            Assert.That(structNode.Children.Count, Is.EqualTo(2));
            // Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues.
            Helper.ConsistencyCheck(container, obj);
        }
Exemplo n.º 2
0
        public void TestViewModelUpdate()
        {
            var obj       = new ClassWithStructs();
            var container = new ModelContainer();

            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            // Modify direct struct via Quantum, check value on actual object
            var structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid);

            structNode.GetChild("SecondValue").Content.Value = 15;
            Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15));
            // Modify nested struct via Quantum, check value on actual object
            structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid);
            structNode.GetChild("FirstValue").Content.Value = 20;
            Assert.That(obj.NestedStruct.Struct.FirstValue, Is.EqualTo(20));
            // Modify direct struct on actual value, check value via Quantum
            obj.NestedStruct = new NestedStruct {
                Struct = new SimpleStruct {
                    FirstValue = 30
                }, SecondValue = 10
            };
            // TODO: this is needed to refresh the references in the node - maybe we could add a Refresh method in the IModelNode?
            model      = container.GetModelNode(obj);
            structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid);
            Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10));
            structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid);
            Assert.That(structNode.GetChild("FirstValue").Content.Value, Is.EqualTo(30));
            // Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues.
            Helper.ConsistencyCheck(container, obj);
        }
Exemplo n.º 3
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
            Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
            Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
            Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
            Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
            Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
            Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
            Helper.PrintModelContainerContent(container, model);
            Helper.ConsistencyCheck(container, obj);
        }
Exemplo n.º 6
0
        public void TestMultipleNestedStruct()
        {
            var obj = new SimpleClassWithNestedStruct(1.0, "test", 5.0, "inner value");

            Assert.That(obj.Struct.FirstValue, Is.EqualTo(1.0));
            Assert.That(obj.Struct.SecondValue, Is.EqualTo("test"));
            Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(5.0));
            Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("inner value"));

            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            var structNode = model.GetChild("Struct").Content.Reference.AsObject.TargetNode;

            structNode.GetChild("FirstValue").Content.Value  = 2.0;
            structNode.GetChild("SecondValue").Content.Value = "new value";
            structNode = structNode.GetChild("InnerStruct").Content.Reference.AsObject.TargetNode;
            structNode.GetChild("FirstValue").Content.Value  = 7.0;
            structNode.GetChild("SecondValue").Content.Value = "new inner value";

            Assert.That(obj.Struct.FirstValue, Is.EqualTo(2.0));
            Assert.That(obj.Struct.SecondValue, Is.EqualTo("new value"));
            Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(7.0));
            Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("new inner value"));
        }
Exemplo n.º 7
0
        public void TestDoubleReferenceMemberDataUpdate()
        {
            var        doubleRef = new DoubleReferenceClass(new SimpleObject());
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(doubleRef, doubleRef.GetType());

            doubleRef.Object1.Name = "New Name";

            Assert.That(doubleRef.Object1.Name, Is.EqualTo("New Name"));
            Assert.That(doubleRef.Object2.Name, Is.EqualTo("New Name"));
            var object1TargetNode = ((ObjectReference)model.GetChild("Object1").Content.Reference).TargetNode;
            var object2TargetNode = ((ObjectReference)model.GetChild("Object2").Content.Reference).TargetNode;

            Assert.That(object1TargetNode.GetChild("Name").Content.Value, Is.EqualTo("New Name"));
            Assert.That(object2TargetNode.GetChild("Name").Content.Value, Is.EqualTo("New Name"));
        }
Exemplo n.º 8
0
        public void TestSimpleContent()
        {
            var obj = new SimpleClass(1, "test");

            Assert.That(obj.FirstValue, Is.EqualTo(1));
            Assert.That(obj.SecondValue, Is.EqualTo("test"));

            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            model.GetChild("FirstValue").Content.Value  = 2;
            model.GetChild("SecondValue").Content.Value = "new value";

            Assert.That(obj.FirstValue, Is.EqualTo(2));
            Assert.That(obj.SecondValue, Is.EqualTo("new value"));
        }
Exemplo n.º 9
0
        public void TestConstruction()
        {
            var obj       = new ClassWithStructs();
            var container = new ModelContainer();

            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            Assert.That(model.GetChild("NestedStruct").Children.Count, Is.EqualTo(2));
            Assert.That(model.GetChild("NestedStruct").GetChild("Struct").Children.Count, Is.EqualTo(2));
            Assert.That(model.GetChild("PrimitiveStruct").Children.Count, Is.EqualTo(0));
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithStructs), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithDictionaries();
            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("StringIntDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic));
            Assert.That(model.GetChild("StringIntDic").Content.IsReference, Is.False);
            Assert.That(model.GetChild("StringClassDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic));
            Assert.That(model.GetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            var enumerator = obj.StringClassDic.GetEnumerator();

            foreach (var reference in (ReferenceEnumerable)model.GetChild("StringClassDic").Content.Reference)
            {
                enumerator.MoveNext();
                var keyValuePair = enumerator.Current;
                Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key));
                Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value));
            }
            //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(ReferenceEnumerable)));
            //}
            //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(ReferenceEnumerable)));
            //}

            //Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            //Assert.That(container.Guids.Count(), Is.EqualTo(10));
        }
Exemplo n.º 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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
0
        public void TestDoubleReferenceAtConstruction()
        {
            var        doubleRef = new DoubleReferenceClass(new SimpleObject());
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(doubleRef, doubleRef.GetType());

            Assert.That(doubleRef.Object1, Is.EqualTo(doubleRef.Object2));
            Assert.That(model.GetChild("Object1").Content.Value, Is.EqualTo(doubleRef.Object1));
            Assert.That(model.GetChild("Object2").Content.Value, Is.EqualTo(doubleRef.Object2));

            Assert.That(model.GetChild("Object1").Content.IsReference, Is.True);
            Assert.That(model.GetChild("Object2").Content.IsReference, Is.True);

            var object1TargetNode = ((ObjectReference)model.GetChild("Object1").Content.Reference).TargetNode;
            var object2TargetNode = ((ObjectReference)model.GetChild("Object2").Content.Reference).TargetNode;

            Assert.That(object1TargetNode, Is.EqualTo(object2TargetNode));
            Assert.That(object1TargetNode.Content.Value, Is.EqualTo(doubleRef.Object1));
        }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets the child of the given node that matches the given name. If the given node holds an object reference, resolve the target of the reference
        /// and gets the child of the target node that matches the given name.
        /// </summary>
        /// <param name="modelNode">The model node.</param>
        /// <param name="name">The name of the child to retrieve.</param>
        /// <returns></returns>
        public static IModelNode GetChildThroughReferences(this IModelNode modelNode, string name)
        {
            var child = modelNode.GetChild(name) ?? modelNode.ResolveTarget().GetChild(name);

            return(child);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Retrieve the child node of the given <see cref="IModelNode"/> that matches the given name. If the node represents an object reference, it returns the referenced object.
        /// </summary>
        /// <param name="modelNode">The view model node to look into.</param>
        /// <param name="name">The name of the child to retrieve.</param>
        /// <returns>The child node that matches the given name, or the referenced node if the child hold an object reference, or <c>null</c> if no child matches.</returns>
        public static IModelNode GetReferencedChild(this IModelNode modelNode, string name)
        {
            var child = modelNode.GetChild(name);

            return(child != null?child.ResolveTarget() : null);
        }