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

            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IGraphNode model = container.GetOrCreateNode(obj);

            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);
        }
Ejemplo n.º 2
0
        public void TestViewModelUpdate()
        {
            var obj       = new ClassWithStructs();
            var container = new NodeContainer();

            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IGraphNode model = container.GetOrCreateNode(obj);

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

            structNode.GetChild("SecondValue").Content.Update(15);
            Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15));
            // Modify nested struct via Quantum, check value on actual object
            structNode = container.GetNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid);
            structNode.GetChild("FirstValue").Content.Update(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.GetNode(obj);
            structNode = container.GetNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid);
            Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10));
            structNode = container.GetNode(((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);
        }
Ejemplo n.º 3
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

            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);
        }
Ejemplo n.º 4
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

            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);
        }
Ejemplo n.º 5
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 NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

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

            structNode.GetChild("FirstValue").Content.Update(2.0);
            structNode.GetChild("SecondValue").Content.Update("new value");
            structNode = structNode.GetChild("InnerStruct").Content.Reference.AsObject.TargetNode;
            structNode.GetChild("FirstValue").Content.Update(7.0);
            structNode.GetChild("SecondValue").Content.Update("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"));
        }
Ejemplo n.º 6
0
        public void TestDoubleReferenceMemberDataUpdate()
        {
            var        doubleRef = new DoubleReferenceClass(new SimpleObject());
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(doubleRef);

            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"));
        }
Ejemplo n.º 7
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 NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

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

            Assert.That(obj.FirstValue, Is.EqualTo(2));
            Assert.That(obj.SecondValue, Is.EqualTo("new value"));
        }
Ejemplo n.º 8
0
        public void TestStructItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

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

            objRef.TargetNode.GetChild("SecondValue").Content.Update(32);
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.SimpleStructList[0].SecondValue, Is.EqualTo(32));
            Helper.ConsistencyCheck(container, obj);
        }
Ejemplo n.º 9
0
        public void TestListOfNestedStructListsUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

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

            structNode.GetChild("SecondValue").Content.Update(32);
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32));
            Helper.ConsistencyCheck(container, obj);
        }
Ejemplo n.º 10
0
        public void TestNestedStructItemUpdate()
        {
            var        obj       = new ClassWithLists();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

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

            structNode.GetChild("SecondValue").Content.Update(32);
            Helper.PrintModelContainerContent(container, model);
            Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32));
            //var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            //visitor.Check((GraphNode)model, obj, typeof(ClassWithLists), true);
            Helper.ConsistencyCheck(container, obj);
        }
Ejemplo n.º 11
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

            Helper.PrintModelContainerContent(container, model);

            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 model.GetChild("StringClassDic").Content.Reference.AsEnumerable)
            {
                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.GetNode(obj.ClassList[0]), !Is.Null);
            //Assert.That(container.Guids.Count(), Is.EqualTo(10));
        }
Ejemplo n.º 12
0
        public void TestDoubleReferenceAtConstruction()
        {
            var        doubleRef = new DoubleReferenceClass(new SimpleObject());
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(doubleRef);

            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));
        }
Ejemplo n.º 13
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithLists();
            var        container = new NodeContainer();
            IGraphNode model     = container.GetOrCreateNode(obj);

            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.GetNode(obj.ClassList[0]), !Is.Null);
            Assert.That(container.Guids.Count(), Is.EqualTo(18));
            Helper.ConsistencyCheck(container, obj);
        }
Ejemplo n.º 14
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 IGraphNode GetChildThroughReferences(this IGraphNode modelNode, string name)
        {
            var child = modelNode.GetChild(name) ?? modelNode.ResolveTarget().GetChild(name);

            return(child);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Retrieve the child node of the given <see cref="IGraphNode"/> 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 IGraphNode GetReferencedChild(this IGraphNode modelNode, string name)
 {
     return(modelNode.GetChild(name)?.ResolveTarget());
 }