Exemplo n.º 1
0
        public void TestGetParent()
        {
            var obj = new Class {
                StructMember = { StringMember = "aa" }, ClassMember = 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.IntMember));
            var parentPath = new GraphNodePath(rootNode);

            AssertAreEqual(parentPath, path.GetParent());

            path       = new GraphNodePath(rootNode).PushMember(nameof(Class.StructMember)).PushMember(nameof(Struct.StringMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.StructMember));
            AssertAreEqual(parentPath, path.GetParent());

            path       = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget();
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember));
            AssertAreEqual(parentPath, path.GetParent());

            path       = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget();
            AssertAreEqual(parentPath, path.GetParent());

            path       = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember));
            AssertAreEqual(parentPath, path.GetParent());

            path       = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            AssertAreEqual(parentPath, path.GetParent());
        }
        public void TestGetParent()
        {
            var obj = new Class { StructMember = { StringMember = "aa" }, ClassMember = 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.IntMember));
            var parentPath = new GraphNodePath(rootNode);
            AssertAreEqual(parentPath, path.GetParent());

            path = new GraphNodePath(rootNode).PushMember(nameof(Class.StructMember)).PushMember(nameof(Struct.StringMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.StructMember));
            AssertAreEqual(parentPath, path.GetParent());

            path = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget();
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember));
            AssertAreEqual(parentPath, path.GetParent());

            path = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget();
            AssertAreEqual(parentPath, path.GetParent());

            path = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember));
            AssertAreEqual(parentPath, path.GetParent());

            path = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
            parentPath = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            AssertAreEqual(parentPath, path.GetParent());
        }