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); }
public void TestPushStructMember() { var obj = new Class { StructMember = { StringMember = "aa" } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.StructMember)); path.PushTarget(); path.PushMember(nameof(Struct.StringMember)); var structNode = rootNode[nameof(Class.StructMember)]; var targetNode = rootNode[nameof(Class.StructMember)].Target; var memberNode = rootNode[nameof(Class.StructMember)].Target[nameof(Struct.StringMember)]; var nodes = new IGraphNode[] { rootNode, structNode, targetNode, memberNode }; Assert.NotNull(targetNode); Assert.NotNull(memberNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(memberNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
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); }
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); }
public void TestClone() { var obj = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); var clone = path1.Clone(); Assert.AreEqual(path1.RootNode, clone.RootNode); Assert.AreEqual(path1.IsValid, clone.IsValid); Assert.AreEqual(path1.IsEmpty, clone.IsEmpty); Assert.AreEqual(path1.GetNode(), clone.GetNode()); var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember)); clone = path2.Clone(); Assert.AreEqual(path2.RootNode, clone.RootNode); Assert.AreEqual(path2.IsValid, clone.IsValid); Assert.AreEqual(path2.IsEmpty, clone.IsEmpty); Assert.AreEqual(path2.GetNode(), clone.GetNode()); var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember)); clone = path3.Clone(); Assert.AreEqual(path3.RootNode, clone.RootNode); Assert.AreEqual(path3.IsValid, clone.IsValid); Assert.AreEqual(path3.IsEmpty, clone.IsEmpty); Assert.AreEqual(path3.GetNode(), clone.GetNode()); }
public void TestClone() { var obj = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); var clone = path1.Clone(); AssertAreEqual(path1, clone); AssertAreEqual(path1.GetHashCode(), clone.GetHashCode()); AssertAreEqual(path1.RootNode, clone.RootNode); AssertAreEqual(path1.IsValid, clone.IsValid); AssertAreEqual(path1.IsEmpty, clone.IsEmpty); AssertAreEqual(path1.GetNode(), clone.GetNode()); var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember)); clone = path2.Clone(); AssertAreEqual(path2, clone); AssertAreEqual(path2.RootNode, clone.RootNode); AssertAreEqual(path2.IsValid, clone.IsValid); AssertAreEqual(path2.IsEmpty, clone.IsEmpty); AssertAreEqual(path2.GetNode(), clone.GetNode()); var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember)); clone = path3.Clone(); AssertAreEqual(path3, clone); AssertAreEqual(path3.RootNode, clone.RootNode); AssertAreEqual(path3.IsValid, clone.IsValid); AssertAreEqual(path3.IsEmpty, clone.IsEmpty); AssertAreEqual(path3.GetNode(), clone.GetNode()); }
public override async Task Invoke(object parameter) { using (var transaction = ActionService?.CreateTransaction()) { var modelNode = NodePath.GetNode(); if (modelNode == null) { throw new InvalidOperationException("Unable to retrieve the node on which to apply the redo operation."); } await NodeCommand.Execute(modelNode.Content, Index, parameter); ActionService?.SetName(transaction, ActionName); } }
public void TestPushMember() { var obj = new Class(); var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.IntMember)); var intNode = rootNode[nameof(Class.IntMember)]; var nodes = new IContentNode[] { rootNode, intNode }; Assert.NotNull(intNode); Assert.True(path.IsValid); 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); }
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); }
public void TestPushMember() { var obj = new Class(); var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.IntMember)); var intNode = rootNode.GetChild(nameof(Class.IntMember)); var nodes = new[] { rootNode, intNode }; 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); }
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.GetChild(nameof(Class.ListMember)), targetNode }; Assert.NotNull(targetNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); Assert.AreEqual(rootNode, path.RootNode); Assert.AreEqual(targetNode, path.GetNode()); var i = 0; foreach (var node in path) { Assert.AreEqual(nodes[i++], node); } Assert.AreEqual(nodes.Length, i); }
public void TestPushStructMember() { var obj = new Class { StructMember = { StringMember = "aa" } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.StructMember)).PushMember(nameof(Struct.StringMember)); var structNode = rootNode.TryGetChild(nameof(Class.StructMember)); var memberNode = rootNode.TryGetChild(nameof(Class.StructMember)).TryGetChild(nameof(Struct.StringMember)); var nodes = new[] { rootNode, structNode, memberNode }; Assert.NotNull(memberNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(memberNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }