Ejemplo n.º 1
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.º 2
0
        public void TestPushTarget()
        {
            var obj = new Class {
                ClassMember = new Class()
            };
            var nodeContainer = new NodeContainer();
            var rootNode      = nodeContainer.GetOrCreateNode(obj);
            var path          = new GraphNodePath(rootNode);

            path.PushMember(nameof(Class.ClassMember));
            path.PushTarget();
            var targetNode = nodeContainer.GetNode(obj.ClassMember);
            var nodes      = new IGraphNode[] { rootNode, rootNode[nameof(Class.ClassMember)], targetNode };

            Assert.NotNull(targetNode);
            Assert.False(path.IsEmpty);
            AssertAreEqual(rootNode, path.RootNode);
            AssertAreEqual(targetNode, path.GetNode());
            var i = 0;

            foreach (var node in path)
            {
                AssertAreEqual(nodes[i++], node);
            }
            AssertAreEqual(nodes.Length, i);
        }
Ejemplo n.º 3
0
        public void TestPushIndexAndMember()
        {
            var obj = new Class {
                ListMember = { new Class(), new Class(), new Class() }
            };
            var nodeContainer = new NodeContainer();
            var rootNode      = nodeContainer.GetOrCreateNode(obj);
            var path          = new GraphNodePath(rootNode);

            path.PushMember(nameof(Class.ListMember));
            path.PushTarget();
            path.PushIndex(new NodeIndex(1));
            path.PushMember(nameof(Class.IntMember));
            var targetNode = nodeContainer.GetNode(obj.ListMember[1]);
            var intNode    = targetNode[nameof(Class.IntMember)];
            var nodes      = new IGraphNode[] { rootNode, rootNode[nameof(Class.ListMember)], rootNode[nameof(Class.ListMember)].Target, targetNode, intNode };

            Assert.NotNull(targetNode);
            Assert.NotNull(intNode);
            Assert.False(path.IsEmpty);
            AssertAreEqual(rootNode, path.RootNode);
            AssertAreEqual(intNode, path.GetNode());
            var i = 0;

            foreach (var node in path)
            {
                AssertAreEqual(nodes[i++], node);
            }
            AssertAreEqual(nodes.Length, i);
        }
Ejemplo n.º 4
0
        public void TestPushTargetAndMember()
        {
            var obj = new Class {
                ClassMember = new Class()
            };
            var nodeContainer = new NodeContainer();
            var rootNode      = nodeContainer.GetOrCreateNode(obj);
            var path          = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
            var targetNode    = nodeContainer.GetNode(obj.ClassMember);
            var intNode       = targetNode.GetChild(nameof(Class.IntMember));
            var nodes         = new[] { rootNode, rootNode.GetChild(nameof(Class.ClassMember)), targetNode, intNode };

            Assert.NotNull(targetNode);
            Assert.NotNull(intNode);
            Assert.True(path.IsValid);
            Assert.False(path.IsEmpty);
            Assert.AreEqual(rootNode, path.RootNode);
            Assert.AreEqual(intNode, path.GetNode());
            var i = 0;

            foreach (var node in path)
            {
                Assert.AreEqual(nodes[i++], node);
            }
            Assert.AreEqual(nodes.Length, i);
        }
Ejemplo n.º 5
0
        public void TestConstruction()
        {
            var obj       = new ClassWithLists();
            var container = new NodeContainer();
            var model     = container.GetOrCreateNode(obj);

            Assert.That(model["IntList"].Retrieve(), Is.SameAs(obj.IntList));
            Assert.That(model["IntList"].IsReference, Is.False);
            Assert.That(model["ClassList"].Retrieve(), Is.SameAs(obj.ClassList));
            //Assert.That(model["ClassList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model["SimpleStructList"].Retrieve(), Is.SameAs(obj.SimpleStructList));
            //Assert.That(model["SimpleStructList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model["NestedStructList"].Retrieve(), Is.SameAs(obj.NestedStructList));
            //Assert.That(model["NestedStructList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            Assert.That(model["ListOfSimpleStructLists"].Retrieve(), Is.SameAs(obj.ListOfSimpleStructLists));
            //Assert.That(model["ListOfSimpleStructLists"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model["ListOfSimpleStructLists"].Target.ItemReferences)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }
            Assert.That(model["ListOfNestedStructLists"].Retrieve(), Is.SameAs(obj.ListOfNestedStructLists));
            //Assert.That(model["ListOfNestedStructLists"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            foreach (var reference in model["ListOfNestedStructLists"].Target.ItemReferences)
            {
                Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference)));
            }

            Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null);
        }
Ejemplo n.º 6
0
        private void UpdatePublicUIElementsEntry(Guid rootId, [CanBeNull] string name)
        {
            var node  = NodeContainer.GetNode((UILibraryAsset)Asset.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target;
            var index = new Index(rootId);

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                // update UILibraryAsset's PublicUIElements collection
                if (string.IsNullOrWhiteSpace(name))
                {
                    // Remove the entry if it exists
                    if (node.Indices.Contains(index))
                    {
                        node.Remove(name, index);
                        UndoRedoService.SetName(transaction, $"Remove '{name}' export from the UILibrary");
                    }
                }
                else
                {
                    if (!node.Indices.Contains(index))
                    {
                        // Note: update would probably work, but we want to remove the item when Undo
                        node.Add(name, index);
                        UndoRedoService.SetName(transaction, $"Add '{name}' export to the UILibrary");
                    }
                    else
                    {
                        node.Update(name, index);
                        UndoRedoService.SetName(transaction, "Update name of export in the UILibrary");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        protected AssetCompositeHierarchyViewModel([NotNull] AssetViewModelConstructionParameters parameters) : base(parameters)
        {
            Asset.Hierarchy.Parts.Values.ForEach(TrackBaseChanges);
            var parts = NodeContainer.GetNode(Asset.Hierarchy.Parts);

            parts.ItemChanged            += PartsChanged;
            Session.DeletedAssetsChanged += AssetsDeleted;
        }
Ejemplo n.º 8
0
        private void RemoveLibrary(UILibraryViewModel library)
        {
            factories.RemoveWhere(l => l.Category == library.Url);

            var node = NodeContainer.GetNode(library.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target;

            node.ItemChanged -= LibraryContentChanged;
        }
Ejemplo n.º 9
0
 private void UntrackBaseChanges(TAssetPartDesign part)
 {
     if (part != null)
     {
         var partNode = NodeContainer.GetNode(part);
         partNode[nameof(IAssetPartDesign.Base)].ValueChanged -= BaseChanged;
     }
 }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public override void Destroy()
        {
            Asset.Hierarchy.Parts.Values.ForEach(UntrackBaseChanges);
            var parts = NodeContainer.GetNode(Asset.Hierarchy.Parts);

            parts.ItemChanged            -= PartsChanged;
            Session.DeletedAssetsChanged -= AssetsDeleted;
            base.Destroy();
        }
Ejemplo n.º 11
0
        private void ClearPublicUIElements()
        {
            var node = NodeContainer.GetNode((UILibraryAsset)Asset.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target;

            if (node is Xenko.Core.Assets.Quantum.Internal.AssetObjectNode)
            {
                ((Xenko.Core.Assets.Quantum.Internal.AssetObjectNode)node).Clear();
            }
        }
Ejemplo n.º 12
0
 public static void ConsistencyCheck(NodeContainer container, object rootObject)
 {
     var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
     var model = container.GetNode(rootObject);
     visitor.Check((GraphNode)model, rootObject, rootObject.GetType(), true);
     foreach (var node in container.Nodes)
     {
         visitor.Check((GraphNode)node, node.Content.Value, node.Content.Type, true);
     }
 }
Ejemplo n.º 13
0
        public static void ConsistencyCheck(NodeContainer container, object rootObject)
        {
            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            var model   = container.GetNode(rootObject);

            visitor.Check((GraphNode)model, rootObject, rootObject.GetType(), true);
            foreach (var node in container.Nodes)
            {
                visitor.Check((GraphNode)node, node.Content.Value, node.Content.Type, true);
            }
        }
Ejemplo n.º 14
0
 public void MakeAdjactedBothWay(NodeContainer nodes)
 {
     foreach (var node in nodes)
     {
         foreach (var adjacted in node.adjacentNodes)
         {
             var adjNode = nodes.GetNode(adjacted);
             var corrected = adjNode.adjacentNodes.Concat(new[] {node.id}).ToArray();
             adjNode.adjacentNodes = corrected;
         }
     }
 }
Ejemplo n.º 15
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.º 16
0
        public SceneViewModel([NotNull] AssetViewModelConstructionParameters parameters)
            : base(parameters)
        {
            SetAsDefaultCommand = new AnonymousCommand(ServiceProvider, SetAsDefault);
            assetCommands.Add(new MenuCommandInfo(ServiceProvider, SetAsDefaultCommand)
            {
                DisplayName = "Set as default", Tooltip = "Set as default scene"
            });
            UpdateCommands();

            Session.SessionStateChanged += SessionStateChanged;

            var assetNode = NodeContainer.GetNode(Asset);

            childrenNode = assetNode[nameof(SceneAsset.ChildrenIds)].Target;
            parentNode   = assetNode[nameof(SceneAsset.Parent)];
        }
Ejemplo n.º 17
0
        public void TestObjectReference()
        {
            var nodeContainer = new NodeContainer();
            var instance = new TestObject { Name = "Test" };
            var container = new ObjectContainer { Instance = instance };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            Helper.TestNonCollectionObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();
            Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instance, false);
            var instanceNode = nodeContainer.GetNode(instance);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance);

            memberNode = instanceNode.Children.First();
            Helper.TestMemberContentNode(instanceNode, memberNode, instance, instance.Name, nameof(TestObject.Name), false);
        }
Ejemplo n.º 18
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.º 19
0
        private void BaseChanged(object sender, MemberNodeChangeEventArgs e)
        {
            var part     = NodeContainer.GetNode(((TAssetPartDesign)e.Member.Parent.Retrieve()).Part);
            var baseInfo = (BasePart)e.Member.Retrieve();

            if (baseInfo == null)
            {
                AssetHierarchyPropertyGraph.RefreshBase((IAssetNode)part, null);
            }
            else
            {
                var baseAsset = Session.GetAssetById(baseInfo.BasePartAsset.Id) as AssetCompositeHierarchyViewModel <TAssetPartDesign, TAssetPart>;
                TAssetPartDesign basePart;
                if (baseAsset != null && baseAsset.Asset.Hierarchy.Parts.TryGetValue(baseInfo.BasePartId, out basePart))
                {
                    var basePartNode = (IAssetNode)NodeContainer.GetNode(basePart.Part);
                    AssetHierarchyPropertyGraph.RefreshBase((IAssetNode)part, basePartNode);
                }
            }
        }
Ejemplo n.º 20
0
        public void UpdateProperties(Guid elementId, IReadOnlyDictionary <string, object> changes)
        {
            var partId  = new AbsoluteId(Asset.Id, elementId);
            var element = (UIElementViewModel)FindPartViewModel(partId);

            if (element == null)
            {
                return;
            }

            var node = NodeContainer.GetNode(element.AssetSideUIElement);

            if (node == null)
            {
                return;
            }

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                foreach (var kv in changes)
                {
                    var propertyName  = kv.Key;
                    var propertyValue = kv.Value;

                    var member = node.TryGetChild(propertyName);
                    if (member == null)
                    {
                        continue;
                    }

                    // Update properties only when they actually changed
                    var currentValue = member.Retrieve();
                    if (currentValue != propertyValue)
                    {
                        member.Update(propertyValue);
                    }
                }
                UndoRedoService.SetName(transaction, $"Update {element.ElementType.Name}");
            }
        }
Ejemplo n.º 21
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.º 22
0
        public void TestObjectReferenceUpdate()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new TestObject {
                Name = "Test"
            };
            var container = new ObjectContainer {
                Instance = instance
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var memberNode    = containerNode.Children.First();
            var instanceNode  = memberNode.Content.Reference.AsObject.TargetNode;

            // Update to a new instance
            var newInstance = new TestObject {
                Name = "Test2"
            };

            memberNode.Content.Update(newInstance);
            Helper.TestMemberContentNode(containerNode, memberNode, container, newInstance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstance);

            var newInstanceNode = nodeContainer.GetNode(newInstance);

            Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstanceNode, newInstance);
            Assert.AreNotEqual(instanceNode.Guid, newInstanceNode.Guid);

            // Update to null
            memberNode.Content.Update(null);
            Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true);
            Helper.TestNullObjectReference(memberNode.Content.Reference);

            // Update back to the initial instance
            memberNode.Content.Update(instance);
            Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance);
        }
Ejemplo n.º 23
0
        public void TestPushIndex()
        {
            var obj = new Class {
                ListMember = { new Class(), new Class(), new Class() }
            };
            var nodeContainer = new NodeContainer();
            var rootNode      = nodeContainer.GetOrCreateNode(obj);
            var path          = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            var targetNode    = nodeContainer.GetNode(obj.ListMember[1]);
            var nodes         = new[] { rootNode, rootNode.TryGetChild(nameof(Class.ListMember)), targetNode };

            Assert.NotNull(targetNode);
            Assert.True(path.IsValid);
            Assert.False(path.IsEmpty);
            AssertAreEqual(rootNode, path.RootNode);
            AssertAreEqual(targetNode, path.GetNode());
            var i = 0;

            foreach (var node in path)
            {
                AssertAreEqual(nodes[i++], node);
            }
            AssertAreEqual(nodes.Length, i);
        }
Ejemplo n.º 24
0
        public void TestObjectReference()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new TestObject {
                Name = "Test"
            };
            var container = new ObjectContainer {
                Instance = instance
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Helper.TestObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();

            Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instance);
            var instanceNode = nodeContainer.GetNode(instance);

            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance);

            memberNode = instanceNode.Children.First();
            Helper.TestMemberContentNode(instanceNode, memberNode, instance, instance.Name, nameof(TestObject.Name), false);
        }
Ejemplo n.º 25
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.º 26
0
 public void TestPushIndexAndMember()
 {
     var obj = new Class { ListMember = { new Class(), new Class(), new Class() } };
     var nodeContainer = new NodeContainer();
     var rootNode = nodeContainer.GetOrCreateNode(obj);
     var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
     var targetNode = nodeContainer.GetNode(obj.ListMember[1]);
     var intNode = targetNode.GetChild(nameof(Class.IntMember));
     var nodes = new[] { rootNode, rootNode.GetChild(nameof(Class.ListMember)), targetNode, intNode };
     Assert.NotNull(targetNode);
     Assert.NotNull(intNode);
     Assert.True(path.IsValid);
     Assert.False(path.IsEmpty);
     Assert.AreEqual(rootNode, path.RootNode);
     Assert.AreEqual(intNode, path.GetNode());
     var i = 0;
     foreach (var node in path)
     {
         Assert.AreEqual(nodes[i++], node);
     }
     Assert.AreEqual(nodes.Length, i);
 }
Ejemplo n.º 27
0
        public void TestObjectReferenceUpdate()
        {
            var nodeContainer = new NodeContainer();
            var instance = new TestObject { Name = "Test" };
            var container = new ObjectContainer { Instance = instance };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var memberNode = containerNode.Children.First();
            var instanceNode = memberNode.Content.Reference.AsObject.TargetNode;

            // Update to a new instance
            var newInstance = new TestObject { Name = "Test2" };
            memberNode.Content.Update(newInstance);
            Helper.TestMemberContentNode(containerNode, memberNode, container, newInstance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstance, false);

            var newInstanceNode = nodeContainer.GetNode(newInstance);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstanceNode, newInstance);
            Assert.AreNotEqual(instanceNode.Guid, newInstanceNode.Guid);

            // Update to null
            memberNode.Content.Update(null);
            Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true);
            Helper.TestNullObjectReference(memberNode.Content.Reference);

            // Update back to the initial instance
            memberNode.Content.Update(instance);
            Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true);
            Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance);
        }
Ejemplo n.º 28
0
 /// <inheritdoc />
 protected override IObjectNode GetPropertiesRootNode()
 {
     return(NodeContainer.GetNode(((UIAssetBase)Asset).Design));
 }
Ejemplo n.º 29
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.º 30
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.º 31
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.º 32
0
 public void TestPushTarget()
 {
     var obj = new Class { ClassMember = new Class() };
     var nodeContainer = new NodeContainer();
     var rootNode = nodeContainer.GetOrCreateNode(obj);
     var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget();
     var targetNode = nodeContainer.GetNode(obj.ClassMember);
     var nodes = new[] { rootNode, rootNode.TryGetChild(nameof(Class.ClassMember)), targetNode };
     Assert.NotNull(targetNode);
     Assert.True(path.IsValid);
     Assert.False(path.IsEmpty);
     AssertAreEqual(rootNode, path.RootNode);
     AssertAreEqual(targetNode, path.GetNode());
     var i = 0;
     foreach (var node in path)
     {
         AssertAreEqual(nodes[i++], node);
     }
     AssertAreEqual(nodes.Length, i);
 }