public void TestChangeBoxedPrimitiveMember()
 {
     var nodeContainer = new NodeContainer();
     var instance = new ComplexClass { Member3 = 3 };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member3));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, 3, 4, () => node.Content.Update(4));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, 4, 5, () => node.Content.Update(5));
 }
 public void TestChangeReferenceMemberToNull()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new SimpleClass(), null, new SimpleClass() };
     var instance = new ComplexClass { Member2 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member2));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1]));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2]));
 }
        public void TestChangeReferenceInObjectMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member3 = obj[0]
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.TryGetChild(nameof(ComplexClass.Member3));

            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1]));
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2]));
        }
        public VisualScriptBlockViewModel(VisualScriptMethodEditorViewModel method, Block block) : base(method.SafeArgument(nameof(method)).ServiceProvider)
        {
            this.Method    = method;
            this.block     = block;
            this.blockNode = method.Editor.Session.AssetNodeContainer.GetOrCreateNode(block);

            var propertyGraph = method.Editor.Session.GraphContainer.TryGetGraph(method.Editor.Asset.Id);

            // If anything changes in the block, trigger a PropertyChanged on Title to force it to refresh
            graphNodeListener = new AssetGraphNodeChangeListener(blockNode, propertyGraph.Definition);
            graphNodeListener.Initialize();
            graphNodeListener.ValueChanging += GraphNodeListener_Changing;
            graphNodeListener.ValueChanged  += GraphNodeListener_Changed;
        }
Beispiel #5
0
        private static void TestItemChange([NotNull] GraphNodeChangeListener listener, [NotNull] Func <IObjectNode> fetchNode, ContentChangeType type, NodeIndex index, object oldValue, object newValue, [NotNull] Action <IObjectNode> change)
        {
            var i            = 0;
            var contentOwner = fetchNode();
            var changing     = new EventHandler <ItemChangeEventArgs>((sender, e) => { Assert.Equal(0, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, false); ++i; });
            var changed      = new EventHandler <ItemChangeEventArgs>((sender, e) => { Assert.Equal(1, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, true); ++i; });

            listener.ItemChanging += changing;
            listener.ItemChanged  += changed;
            change(contentOwner);
            Assert.Equal(2, i);
            listener.ItemChanging -= changing;
            listener.ItemChanged  -= changed;
        }
        public void TestChangeBoxedPrimitiveMember()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new ComplexClass {
                Member3 = 3
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode[nameof(ComplexClass.Member3)];

            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member3)], ContentChangeType.ValueChange, Index.Empty, 3, 4, x => x.Update(4));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member3)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member3)], ContentChangeType.ValueChange, Index.Empty, 4, 5, x => x.Update(5));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member3)]);
        }
        public void TestChangeReferenceMemberToNull()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), null, new SimpleClass() };
            var instance      = new ComplexClass {
                Member2 = obj[0]
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.GetChild(nameof(ComplexClass.Member2));
            var path     = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member2));

            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], path, () => node.Content.Update(obj[1]));
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], path, () => node.Content.Update(obj[2]));
        }
        public void TestChangeReferenceMemberToNull()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), null, new SimpleClass() };
            var instance      = new ComplexClass {
                Member2 = obj[0]
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode[nameof(ComplexClass.Member2)];

            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member2)], ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], x => x.Update(obj[1]));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member2)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member2)], ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], x => x.Update(obj[2]));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member2)]);
        }
Beispiel #9
0
        public GameEditorChangePropagator([NotNull] AssetCompositeEditorViewModel editor, [NotNull] TItemViewModel owner, [NotNull] TAssetPart assetSidePart)
        {
            Editor = editor;
            Owner  = owner;
            // We want to start listening to change right away, in case a change occurs immedately after creating/adding the entity
            var rootNode = (IAssetNode)Editor.NodeContainer.GetNode(assetSidePart);

            listener = new AssetGraphNodeChangeListener(rootNode, owner.Asset.PropertyGraph.Definition);
            listener.Initialize();
            listener.ValueChanged += AssetSideNodeChanged;
            listener.ItemChanged  += AssetSideNodeChanged;
            gameObjectLinker       = new AssetGraphNodeLinker(owner.Asset.PropertyGraph.Definition)
            {
                LinkAction = LinkNode
            };
            Task.Run(() => PropagatorTask(assetSidePart));
        }
        public void TestChangeStructMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member4 = new Struct {
                    Member1 = obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.TryGetChild(nameof(ComplexClass.Member4)).TryGetChild(nameof(Struct.Member1));

            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1], Index.Empty));
            Assert.AreEqual(node, rootNode.TryGetChild(nameof(ComplexClass.Member4)).TryGetChild(nameof(Struct.Member1)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2], Index.Empty));
            Assert.AreEqual(node, rootNode.TryGetChild(nameof(ComplexClass.Member4)).TryGetChild(nameof(Struct.Member1)));
        }
Beispiel #11
0
 public override void Destroy()
 {
     base.Destroy();
     foreach (var slot in InputSlots.Cast <GraphicsCompositorSlotViewModel>())
     {
         slot.Destroy();
     }
     InputSlots.Clear();
     foreach (var slot in OutputSlots.Cast <GraphicsCompositorSlotViewModel>())
     {
         slot.Destroy();
     }
     OutputSlots.Clear();
     Editor.SelectedSharedRenderers.Remove(this);
     graphNodeListener.ItemChanged  -= GraphNodeListenerChanged;
     graphNodeListener.ValueChanged -= GraphNodeListenerChanged;
     graphNodeListener.Dispose();
     graphNodeListener = null;
 }
        public void TestChangePrimitiveListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member5 = new List <string> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.TryGetChild(nameof(ComplexClass.Member5));

            Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[0], obj[1], () => node.Content.Update(obj[1], new Index(0)));
            Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[1], obj[2], () => node.Content.Update(obj[2], new Index(0)));
            Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(0)));
        }
        public void TestAddReferenceListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.TryGetChild(nameof(ComplexClass.Member6));

            Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.CollectionAdd, new Index(1), null, obj[1], () => node.Content.Add(obj[1], new Index(1)));
            Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(1)));
            TestContentChange(listener, node, ContentChangeType.CollectionAdd, new Index(2), null, obj[2], () => node.Content.Add(obj[2], new Index(2)));
            Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(2)));
        }
        private static void TestContentChange(GraphNodeChangeListener listener, IGraphNode contentOwner, ContentChangeType type, Index index, object oldValue, object newValue, GraphNodePath path, Action change)
        {
            var i              = 0;
            var prepareChange  = new EventHandler <GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(0, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, path, false); ++i; });
            var changing       = new EventHandler <GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(1, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, path, false); ++i; });
            var changed        = new EventHandler <GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(2, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, path, true); ++i; });
            var finalizeChange = new EventHandler <GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(3, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, path, true); ++i; });

            listener.PrepareChange  += prepareChange;
            listener.Changing       += changing;
            listener.Changed        += changed;
            listener.FinalizeChange += finalizeChange;
            change();
            Assert.AreEqual(4, i);
            listener.PrepareChange  -= prepareChange;
            listener.Changing       -= changing;
            listener.Changed        -= changed;
            listener.FinalizeChange -= finalizeChange;
        }
        public void TestChangeReferenceListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.GetChild(nameof(ComplexClass.Member6));
            var path     = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member6));

            Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[0], obj[1], path, () => node.Content.Update(obj[1], new Index(0)));
            Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[1], obj[2], path, () => node.Content.Update(obj[2], new Index(0)));
            Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(0)));
        }
        public void TestChangeReferenceListItemMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { 3, 4, 5 };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    new SimpleClass(), new SimpleClass {
                        Member1 = obj[0]
                    }
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.GetChild(nameof(ComplexClass.Member6)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1));

            Assert.AreEqual(obj[0], node.Content.Retrieve());
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1], Index.Empty));
            Assert.AreEqual(obj[1], node.Content.Retrieve());
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2], Index.Empty));
            Assert.AreEqual(obj[2], node.Content.Retrieve());
        }
        public void TestChangeReferenceListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode[nameof(ComplexClass.Member6)];

            Assert.AreEqual(obj[0], node.Retrieve(new Index(0)));
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member6)], ContentChangeType.CollectionUpdate, new Index(0), obj[0], obj[1], x => x.Update(obj[1], new Index(0)));
            Assert.AreEqual(obj[1], node.Retrieve(new Index(0)));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member6)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member6)], ContentChangeType.CollectionUpdate, new Index(0), obj[1], obj[2], x => x.Update(obj[2], new Index(0)));
            Assert.AreEqual(obj[2], node.Retrieve(new Index(0)));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member6)]);
        }
        public void TestAddPrimitiveListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member5 = new List <string> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode[nameof(ComplexClass.Member5)];

            Assert.AreEqual(obj[0], node.Retrieve(new Index(0)));
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member5)], ContentChangeType.CollectionAdd, new Index(1), null, obj[1], x => x.Add(obj[1], new Index(1)));
            Assert.AreEqual(obj[1], node.Retrieve(new Index(1)));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member5)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member5)], ContentChangeType.CollectionAdd, new Index(2), null, obj[2], x => x.Add(obj[2], new Index(2)));
            Assert.AreEqual(obj[2], node.Retrieve(new Index(2)));
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member5)]);
        }
        public void TestChangeStructMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member4 = new Struct {
                    Member1 = obj[0]
                }
            };
            var rootNode   = nodeContainer.GetOrCreateNode(instance);
            var listener   = new GraphNodeChangeListener(rootNode);
            var targetNode = rootNode[nameof(ComplexClass.Member4)].Target;
            var node       = targetNode[nameof(Struct.Member1)];

            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member4)].Target[nameof(Struct.Member1)], ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], x => x.Update(obj[1], Index.Empty));
            Assert.AreEqual(targetNode, rootNode[nameof(ComplexClass.Member4)].Target);
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member4)].Target[nameof(Struct.Member1)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member4)].Target[nameof(Struct.Member1)], ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], x => x.Update(obj[2], Index.Empty));
            Assert.AreEqual(targetNode, rootNode[nameof(ComplexClass.Member4)].Target);
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member4)].Target[nameof(Struct.Member1)]);
        }
Beispiel #20
0
        public AssetPropertyGraph(AssetPropertyGraphContainer container, AssetItem assetItem, ILogger logger)
        {
            if (assetItem == null)
            {
                throw new ArgumentNullException(nameof(assetItem));
            }
            AssetItem = assetItem;
            Container = container;
            AssetCollectionItemIdHelper.GenerateMissingItemIds(assetItem.Asset);
            CollectionItemIdsAnalysis.FixupItemIds(assetItem, logger);
            RootNode = (AssetNode)Container.NodeContainer.GetOrCreateNode(assetItem.Asset);
            ApplyOverrides(RootNode, AssetItem.Overrides);
            nodeListener           = new GraphNodeChangeListener(RootNode, ShouldListenToTargetNode);
            nodeListener.Changing += AssetContentChanging;
            nodeListener.Changed  += AssetContentChanged;

            baseLinker = new AssetToBaseNodeLinker(this)
            {
                LinkAction = LinkBaseNode
            };
        }
        public void TestAddReferenceListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);

            listener.Initialize();
            var node = rootNode[nameof(ComplexClass.Member6)];

            Assert.Equal(obj[0], node.Retrieve(new NodeIndex(0)));
            TestItemChange(listener, () => rootNode[nameof(ComplexClass.Member6)].Target, ContentChangeType.CollectionAdd, new NodeIndex(1), null, obj[1], x => x.Add(obj[1], new NodeIndex(1)));
            Assert.Equal(obj[1], node.Retrieve(new NodeIndex(1)));
            Assert.Equal(node, rootNode[nameof(ComplexClass.Member6)]);
            TestItemChange(listener, () => rootNode[nameof(ComplexClass.Member6)].Target, ContentChangeType.CollectionAdd, new NodeIndex(2), null, obj[2], x => x.Add(obj[2], new NodeIndex(2)));
            Assert.Equal(obj[2], node.Retrieve(new NodeIndex(2)));
            Assert.Equal(node, rootNode[nameof(ComplexClass.Member6)]);
        }
        public void TestChangePrimitiveListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member5 = new List <string> {
                    obj[0]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);

            listener.Initialize();
            var node = rootNode[nameof(ComplexClass.Member5)];

            Assert.Equal(obj[0], node.Retrieve(new NodeIndex(0)));
            TestItemChange(listener, () => rootNode[nameof(ComplexClass.Member5)].Target, ContentChangeType.CollectionUpdate, new NodeIndex(0), obj[0], obj[1], x => x.Update(obj[1], new NodeIndex(0)));
            Assert.Equal(obj[1], node.Retrieve(new NodeIndex(0)));
            Assert.Equal(node, rootNode[nameof(ComplexClass.Member5)]);
            TestItemChange(listener, () => rootNode[nameof(ComplexClass.Member5)].Target, ContentChangeType.CollectionUpdate, new NodeIndex(0), obj[1], obj[2], x => x.Update(obj[2], new NodeIndex(0)));
            Assert.Equal(obj[2], node.Retrieve(new NodeIndex(0)));
            Assert.Equal(node, rootNode[nameof(ComplexClass.Member5)]);
        }
        public void TestChangeStructListItemMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member7 = new List <Struct> {
                    new Struct(), new Struct {
                        Member1 = obj[0]
                    }
                }
            };
            var   rootNode = nodeContainer.GetOrCreateNode(instance);
            var   listener = new GraphNodeChangeListener(rootNode);
            Index index    = new Index(1);
            var   node     = rootNode[nameof(ComplexClass.Member7)].IndexedTarget(index)[nameof(SimpleClass.Member1)];

            Assert.AreEqual(obj[0], node.Retrieve());
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member7)].IndexedTarget(index)[nameof(SimpleClass.Member1)], ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], x => x.Update(obj[1], Index.Empty));
            Assert.AreEqual(obj[1], node.Retrieve());
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member7)].IndexedTarget(new Index(1))[nameof(SimpleClass.Member1)]);
            TestContentChange(listener, () => rootNode[nameof(ComplexClass.Member7)].IndexedTarget(index)[nameof(SimpleClass.Member1)], ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], x => x.Update(obj[2], Index.Empty));
            Assert.AreEqual(obj[2], node.Retrieve());
            Assert.AreEqual(node, rootNode[nameof(ComplexClass.Member7)].IndexedTarget(new Index(1))[nameof(SimpleClass.Member1)]);
        }
        public void TestChangeStructListItemMember()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member7 = new List <Struct> {
                    new Struct(), new Struct {
                        Member1 = obj[0]
                    }
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var listener = new GraphNodeChangeListener(rootNode);
            var node     = rootNode.GetChild(nameof(ComplexClass.Member7)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1));

            Assert.AreEqual(obj[0], node.Content.Retrieve());
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1], Index.Empty));
            Assert.AreEqual(obj[1], node.Content.Retrieve());
            // TODO: would be nice to be able to keep the same boxed node!
            //Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member7)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2], Index.Empty));
            Assert.AreEqual(obj[2], node.Content.Retrieve());
            //Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member7)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1)));
        }
 public void TestChangePrimitiveListItem()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { "aa", "bb", "cc" };
     var instance = new ComplexClass { Member5 = new List<string> { obj[0] } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member5));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[0], obj[1], () => node.Content.Update(obj[1], new Index(0)));
     Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[1], obj[2], () => node.Content.Update(obj[2], new Index(0)));
     Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(0)));
 }
 public void TestChangeStruct()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new Struct { Member1 = "aa" }, new Struct { Member1 = "bb" }, new Struct { Member1 = "cc" } };
     var instance = new ComplexClass { Member4 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member4));
     Assert.AreEqual("aa", node.TryGetChild(nameof(Struct.Member1)).Content.Retrieve());
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1]));
     Assert.AreEqual("bb", node.TryGetChild(nameof(Struct.Member1)).Content.Retrieve());
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2]));
     Assert.AreEqual("cc", node.TryGetChild(nameof(Struct.Member1)).Content.Retrieve());
     TestContentChange(listener, node.TryGetChild(nameof(Struct.Member1)), ContentChangeType.ValueChange, Index.Empty, "cc", "dd", () => node.TryGetChild(nameof(Struct.Member1)).Content.Update("dd"));
     Assert.AreEqual("dd", node.TryGetChild(nameof(Struct.Member1)).Content.Retrieve());
 }
 public void TestDiscardedReferenceMember()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new SimpleClass(), new SimpleClass() };
     var instance = new ComplexClass { Member2 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var obj0Node = nodeContainer.GetOrCreateNode(obj[0]);
     var obj1Node = nodeContainer.GetOrCreateNode(obj[1]);
     var listener = new GraphNodeChangeListener(rootNode);
     int changingCount = 0;
     int changedCount = 0;
     listener.Changing += (sender, e) => ++changingCount;
     listener.Changed += (sender, e) => ++changedCount;
     obj0Node.TryGetChild(nameof(SimpleClass.Member1)).Content.Update(1);
     Assert.AreEqual(1, changingCount);
     Assert.AreEqual(1, changedCount);
     rootNode.TryGetChild(nameof(ComplexClass.Member2)).Content.Update(obj[1]);
     Assert.AreEqual(2, changingCount);
     Assert.AreEqual(2, changedCount);
     obj0Node.TryGetChild(nameof(SimpleClass.Member1)).Content.Update(2);
     Assert.AreEqual(2, changingCount);
     Assert.AreEqual(2, changedCount);
     obj1Node.TryGetChild(nameof(SimpleClass.Member1)).Content.Update(3);
     Assert.AreEqual(3, changingCount);
     Assert.AreEqual(3, changedCount);
 }
 private static void TestContentChange(GraphNodeChangeListener listener, IGraphNode contentOwner, ContentChangeType type, Index index, object oldValue, object newValue, Action change)
 {
     var i = 0;
     var prepareChange = new EventHandler<GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(0, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, false); ++i; });
     var changing = new EventHandler<GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(1, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, false); ++i; });
     var changed = new EventHandler<GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(2, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, true); ++i; });
     var finalizeChange = new EventHandler<GraphContentChangeEventArgs>((sender, e) => { Assert.AreEqual(3, i); VerifyListenerEvent(e, contentOwner, type, index, oldValue, newValue, true); ++i; });
     listener.PrepareChange += prepareChange;
     listener.Changing += changing;
     listener.Changed += changed;
     listener.FinalizeChange += finalizeChange;
     change();
     Assert.AreEqual(4, i);
     listener.PrepareChange -= prepareChange;
     listener.Changing -= changing;
     listener.Changed -= changed;
     listener.FinalizeChange -= finalizeChange;
 }
 public void TestRemoveStructListItem()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new Struct { Member1 = "aa" }, new Struct { Member1 = "bb" }, new Struct { Member1 = "cc" } };
     var instance = new ComplexClass { Member7 = new List<Struct> { obj[0], obj[1], obj[2] } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member7));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
     Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(1)));
     Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(2)));
     TestContentChange(listener, node, ContentChangeType.CollectionRemove, new Index(1), obj[1], null, () => node.Content.Remove(obj[1], new Index(1)));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
     Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(1)));
     TestContentChange(listener, node, ContentChangeType.CollectionRemove, new Index(1), obj[2], null, () => node.Content.Remove(obj[2], new Index(1)));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
 }
 public void TestChangeStructListItemMember()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { "aa", "bb", "cc" };
     var instance = new ComplexClass { Member7 = new List<Struct> { new Struct(), new Struct { Member1 = obj[0] } } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     Index index = new Index(1);
     IGraphNode tempQualifier = rootNode.TryGetChild(nameof(ComplexClass.Member7));
     var node = tempQualifier.IndexedTarget(index).TryGetChild(nameof(SimpleClass.Member1));
     Assert.AreEqual(obj[0], node.Content.Retrieve());
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1], Index.Empty));
     Assert.AreEqual(obj[1], node.Content.Retrieve());
     // TODO: would be nice to be able to keep the same boxed node!
     //Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member7)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2], Index.Empty));
     Assert.AreEqual(obj[2], node.Content.Retrieve());
     //Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member7)).GetTarget(new Index(1)).GetChild(nameof(SimpleClass.Member1)));
 }
 public void TestChangeStructList()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new List<Struct> { new Struct() }, new List<Struct> { new Struct() }, new List<Struct> { new Struct() } };
     var instance = new ComplexClass { Member7 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member7));
     Assert.AreEqual(obj[0][0], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1]));
     Assert.AreEqual(obj[1][0], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2]));
     Assert.AreEqual(obj[2][0], node.Content.Retrieve(new Index(0)));
     var newItem = new Struct();
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[2][0], newItem, () => node.Content.Update(newItem, new Index(0)));
     Assert.AreEqual(newItem, node.Content.Retrieve(new Index(0)));
 }
 public void TestChangeReferenceListItemMember()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { 3, 4, 5 };
     var instance = new ComplexClass { Member6 = new List<SimpleClass> { new SimpleClass(), new SimpleClass { Member1 = obj[0] } } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     Index index = new Index(1);
     IGraphNode tempQualifier = rootNode.TryGetChild(nameof(ComplexClass.Member6));
     var node = tempQualifier.IndexedTarget(index).TryGetChild(nameof(SimpleClass.Member1));
     Assert.AreEqual(obj[0], node.Content.Retrieve());
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1], Index.Empty));
     Assert.AreEqual(obj[1], node.Content.Retrieve());
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2], Index.Empty));
     Assert.AreEqual(obj[2], node.Content.Retrieve());
 }
 public void TestChangeReferenceInObjectMember()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
     var instance = new ComplexClass { Member3 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.GetChild(nameof(ComplexClass.Member3));
     var path = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member3));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], path, () => node.Content.Update(obj[1]));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], path, () => node.Content.Update(obj[2]));
 }
 public void TestChangePrimitiveList()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new List<string> { "aa" }, new List<string> { "bb" }, new List<string> { "cc" } };
     var instance = new ComplexClass { Member5 = obj[0] };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.GetChild(nameof(ComplexClass.Member5));
     var path = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member5));
     Assert.AreEqual("aa", node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], path, () => node.Content.Update(obj[1]));
     Assert.AreEqual("bb", node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], path, () => node.Content.Update(obj[2]));
     Assert.AreEqual("cc", node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), "cc", "dd", path, () => node.Content.Update("dd", new Index(0)));
     Assert.AreEqual("dd", node.Content.Retrieve(new Index(0)));
 }
 public void TestChangeStructListItem()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new Struct { Member1 = "aa" }, new Struct { Member1 = "bb" }, new Struct { Member1 = "cc" } };
     var instance = new ComplexClass { Member7 = new List<Struct> { obj[0] } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.GetChild(nameof(ComplexClass.Member7));
     var path = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member7));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[0], obj[1], path, () => node.Content.Update(obj[1], new Index(0)));
     Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), obj[1], obj[2], path, () => node.Content.Update(obj[2], new Index(0)));
     Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(0)));
 }
 public void TestChangeStructMember()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { "aa", "bb", "cc" };
     var instance = new ComplexClass { Member4 = new Struct { Member1 = obj[0] } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.GetChild(nameof(ComplexClass.Member4)).GetChild(nameof(Struct.Member1));
     var path = new GraphNodePath(rootNode).PushMember(nameof(ComplexClass.Member4)).PushMember(nameof(Struct.Member1));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], path, () => node.Content.Update(obj[1], Index.Empty));
     Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member4)).GetChild(nameof(Struct.Member1)));
     TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], path, () => node.Content.Update(obj[2], Index.Empty));
     Assert.AreEqual(node, rootNode.GetChild(nameof(ComplexClass.Member4)).GetChild(nameof(Struct.Member1)));
 }
 public void TestAddReferenceListItem()
 {
     var nodeContainer = new NodeContainer();
     var obj = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
     var instance = new ComplexClass { Member6 = new List<SimpleClass> { obj[0] } };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var listener = new GraphNodeChangeListener(rootNode);
     var node = rootNode.TryGetChild(nameof(ComplexClass.Member6));
     Assert.AreEqual(obj[0], node.Content.Retrieve(new Index(0)));
     TestContentChange(listener, node, ContentChangeType.CollectionAdd, new Index(1), null, obj[1], () => node.Content.Add(obj[1], new Index(1)));
     Assert.AreEqual(obj[1], node.Content.Retrieve(new Index(1)));
     TestContentChange(listener, node, ContentChangeType.CollectionAdd, new Index(2), null, obj[2], () => node.Content.Add(obj[2], new Index(2)));
     Assert.AreEqual(obj[2], node.Content.Retrieve(new Index(2)));
 }