Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Set the <see cref="TargetNode"/> and <see cref="TargetGuid"/> of the targeted object by retrieving it from or creating it to the given <see cref="ModelContainer"/>.
        /// </summary>
        /// <param name="modelContainer">The <see cref="ModelContainer"/> used to retrieve or create the target node.</param>
        public IModelNode SetTarget(ModelContainer modelContainer)
        {
            if (modelContainer == null)
            {
                throw new ArgumentNullException("modelContainer");
            }
            IModelNode targetNode = modelContainer.GetOrCreateModelNode(ObjectValue, Type);

            if (targetNode != null)
            {
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value))
                {
                    throw new InvalidOperationException(@"The type of the retrieved node content does not match the type of this reference");
                }

                if (TargetNode != null || TargetGuid != Guid.Empty)
                {
                    throw new InvalidOperationException("TargetNode has already been set.");
                }
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value))
                {
                    throw new InvalidOperationException("TargetNode type does not match the reference type.");
                }
                TargetNode = targetNode;
                TargetGuid = targetNode.Guid;
            }
            return(targetNode);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #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 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"));
        }
Пример #6
0
        public void TestNullLists()
        {
            var        obj       = new ClassWithNullLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            Helper.ConsistencyCheck(container, obj);
        }
Пример #7
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));
        }
Пример #8
0
        public void TestConstructionWithNullObject()
        {
            var obj       = new ClassWithNullObject();
            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, node);
            // TODO: Asserts regarding the status of the null value
            // Run the consistency check to verify construction.
            Helper.ConsistencyCheck(container, obj);
        }
Пример #9
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);
            }
        }
Пример #10
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));
        }
Пример #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));
        }
Пример #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 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);
        }
Пример #15
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);
        }
Пример #16
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"));
        }
Пример #17
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"));
        }
Пример #18
0
        /// <summary>
        /// Set the <see cref="TargetNode"/> and <see cref="TargetGuid"/> of the targeted object by retrieving it from or creating it to the given <see cref="ModelContainer"/>.
        /// </summary>
        /// <param name="modelContainer">The <see cref="ModelContainer"/> used to retrieve or create the target node.</param>
        public IModelNode SetTarget(ModelContainer modelContainer)
        {
            if (modelContainer == null) throw new ArgumentNullException("modelContainer");
            IModelNode targetNode = modelContainer.GetOrCreateModelNode(ObjectValue, Type);
            if (targetNode != null)
            {
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value)) throw new InvalidOperationException(@"The type of the retrieved node content does not match the type of this reference");

                if (TargetNode != null || TargetGuid != Guid.Empty)
                    throw new InvalidOperationException("TargetNode has already been set.");
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value))
                    throw new InvalidOperationException("TargetNode type does not match the reference type.");
                TargetNode = targetNode;
                TargetGuid = targetNode.Guid;
            }
            return targetNode;
        }
Пример #19
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);
     }
 }
Пример #20
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));
        }
Пример #21
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);
        }
Пример #22
0
        public void TestConstructionWithNullObject()
        {
            var obj       = new ClassWithNullObject();
            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check(node, obj, typeof(ClassWithNullObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }
        }
Пример #23
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);
            }
        }
Пример #24
0
        public void TestNullLists()
        {
            var        obj       = new ClassWithNullLists();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            foreach (var node in container.Guids.Select(container.GetModelNode).Where(x => model != x))
            {
                Console.WriteLine(node.PrintHierarchy());
            }
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check((ModelNode)model, obj, typeof(ClassWithNullLists), true);
            foreach (var node in container.Models)
            {
                visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Пример #25
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));
        }
Пример #26
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);
            }
        }
Пример #27
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);
            }
        }
Пример #28
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);
        }
Пример #29
0
        public void TestNodeConstruction()
        {
            var obj = new SimpleObject(1, 2, 3, 4)
            {
                Name           = "Test",
                MemberToIgnore = int.MaxValue,
                SubObject      = new SimpleObject(5, 6, 7, 8),
                Collection     =
                {
                    "List Item",
                    22.5,
                    Guid.NewGuid(),
                    new List <string> {
                        "one",         "two","three"
                    },
                    new SimpleObject(9, 10, 11, 12),
                },
                Dictionary =
                {
                    { "Item1", "List Item"    },
                    { "Item2",           22.5 },
                    { "Item3", Guid.NewGuid() },
                    { "Item4", new List <string> {
                          "one", "two", "three"
                      } },
                    { "Item5", new SimpleObject(9, 10, 11, 12)},
                },
            };

            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, node);
            // Run the consistency check to verify construction.
            Helper.ConsistencyCheck(container, obj);
        }
Пример #30
0
        public void TestNodeConstruction()
        {
            var simpleObject = new SimpleObject(1, 2, 3, 4)
            {
                Name = "Test", MemberToIgnore = int.MaxValue, SubObject = new SimpleObject(5, 6, 7, 8)
            };

            simpleObject.Collection.Add("List Item");
            simpleObject.Collection.Add(22.5);
            simpleObject.Collection.Add(Guid.NewGuid());
            simpleObject.Collection.Add(new List <string> {
                "one", "two", "three"
            });
            simpleObject.Collection.Add(new SimpleObject(9, 10, 11, 12));
            simpleObject.Dictionary.Add("Item1", "List Item");
            simpleObject.Dictionary.Add("Item2", 22.5);
            simpleObject.Dictionary.Add("Item3", Guid.NewGuid());
            simpleObject.Dictionary.Add("Item4", new List <string> {
                "one", "two", "three"
            });
            simpleObject.Dictionary.Add("Item5", new SimpleObject(9, 10, 11, 12));
            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(simpleObject, simpleObject.GetType());

            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check(node, simpleObject, typeof(SimpleObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }
        }
Пример #31
0
        public void TestNodeConstruction()
        {
            var simpleObject = new SimpleObject(1, 2, 3, 4) { Name = "Test", MemberToIgnore = int.MaxValue, SubObject = new SimpleObject(5, 6, 7, 8) };
            simpleObject.Collection.Add("List Item");
            simpleObject.Collection.Add(22.5);
            simpleObject.Collection.Add(Guid.NewGuid());
            simpleObject.Collection.Add(new List<string> { "one", "two", "three" });
            simpleObject.Collection.Add(new SimpleObject(9, 10, 11, 12));
            simpleObject.Dictionary.Add("Item1", "List Item");
            simpleObject.Dictionary.Add("Item2", 22.5);
            simpleObject.Dictionary.Add("Item3", Guid.NewGuid());
            simpleObject.Dictionary.Add("Item4", new List<string> { "one", "two", "three" });
            simpleObject.Dictionary.Add("Item5", new SimpleObject(9, 10, 11, 12));
            var container = new ModelContainer();
            var node = (ModelNode)container.GetOrCreateModelNode(simpleObject, simpleObject.GetType());
            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            visitor.Check(node, simpleObject, typeof(SimpleObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }
        }
Пример #32
0
        public void TestConstructionWithNullObject()
        {
            var obj = new ClassWithNullObject();
            var container = new ModelContainer();
            var node = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());
            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            visitor.Check(node, obj, typeof(ClassWithNullObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }

        }
Пример #33
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);
 }
Пример #34
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);
        }
Пример #35
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);
 }
Пример #36
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);
 }
Пример #37
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);
            }
        }
Пример #38
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);
 }
Пример #39
0
        public void TestNodeConstruction()
        {
            var obj = new SimpleObject(1, 2, 3, 4)
            {
                Name = "Test",
                MemberToIgnore = int.MaxValue,
                SubObject = new SimpleObject(5, 6, 7, 8),
                Collection = 
                {
                    "List Item",
                    22.5,
                    Guid.NewGuid(),
                    new List<string> { "one", "two", "three" },
                    new SimpleObject(9, 10, 11, 12),
                },
                Dictionary =
                {
                    { "Item1", "List Item" },
                    { "Item2", 22.5 },
                    { "Item3", Guid.NewGuid() },
                    { "Item4", new List<string> { "one", "two", "three" } },
                    { "Item5", new SimpleObject(9, 10, 11, 12) },
                },
            };

            var container = new ModelContainer();
            var node = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());
            Helper.PrintModelContainerContent(container, node);
            // Run the consistency check to verify construction.
            Helper.ConsistencyCheck(container, obj);
        }
Пример #40
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);
     }
 }
Пример #41
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"));
        }
Пример #42
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);
     }
 }
Пример #43
0
 public void TestNullLists()
 {
     var obj = new ClassWithNullLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, model);
     Helper.ConsistencyCheck(container, obj);
 }
Пример #44
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);
 }
Пример #45
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"));
        }
Пример #46
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));
 }
Пример #47
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"));
        }
Пример #48
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);
 }
Пример #49
0
 public void TestConstructionWithNullObject()
 {
     var obj = new ClassWithNullObject();
     var container = new ModelContainer();
     var node = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, node);
     // TODO: Asserts regarding the status of the null value
     // Run the consistency check to verify construction.
     Helper.ConsistencyCheck(container, obj);
 }
Пример #50
0
 public void TestNullLists()
 {
     var obj = new ClassWithNullLists();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Console.WriteLine(model.PrintHierarchy());
     foreach (var node in container.Guids.Select(container.GetModelNode).Where(x => model != x))
     {
         Console.WriteLine(node.PrintHierarchy());
     }
     var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
     visitor.Check((ModelNode)model, obj, typeof(ClassWithNullLists), true);
     foreach (var node in container.Models)
     {
         visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true);
     }
 }