예제 #1
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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.AreEqual(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
            Assert.AreEqual(obj[0], (string)dynNode.Member7[1].Member1);
            dynNode.Member7[1].Member1 = obj[1];
            Assert.AreEqual(obj[1], (string)dynNode.Member7[1].Member1);
            Assert.AreEqual(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
            Index        index         = new Index(1);
            IContentNode tempQualifier = rootNode[nameof(ComplexClass.Member7)];

            tempQualifier.IndexedTarget(index)[nameof(SimpleClass.Member1)].Update(obj[2]);
            Assert.AreEqual(obj[2], (string)dynNode.Member7[1].Member1);
            Assert.AreEqual(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
        }
예제 #2
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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.AreEqual(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
            Assert.AreEqual(obj[0], (int)dynNode.Member6[1].Member1);
            dynNode.Member6[1].Member1 = obj[1];
            Assert.AreEqual(obj[1], (int)dynNode.Member6[1].Member1);
            Assert.AreEqual(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
            Index        index         = new Index(1);
            IContentNode tempQualifier = rootNode[nameof(ComplexClass.Member6)];

            tempQualifier.IndexedTarget(index)[nameof(SimpleClass.Member1)].Update(obj[2]);
            Assert.AreEqual(obj[2], (int)dynNode.Member6[1].Member1);
            Assert.AreEqual(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
        }
예제 #3
0
        public void TestObjectWithListOfReferences()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new ObjectListClass {
                Member1 = 3, Member2 = new List <SimpleClass> {
                    new SimpleClass(), new SimpleClass()
                }
            };
            var instance2 = new ObjectListClass {
                Member1 = 3, Member2 = new List <SimpleClass> {
                    new SimpleClass(), new SimpleClass()
                }
            };
            var source = nodeContainer.GetOrCreateNode(instance1);
            var target = nodeContainer.GetOrCreateNode(instance2);
            var linker = new TestLinker();

            linker.LinkGraph(source, target);
            Index        index           = new Index(0);
            IContentNode tempQualifier   = source[nameof(SimpleClass.Member2)];
            Index        index1          = new Index(0);
            IContentNode tempQualifier1  = target[nameof(SimpleClass.Member2)];
            Index        index2          = new Index(0);
            IContentNode tempQualifier2  = source[nameof(SimpleClass.Member2)];
            Index        index3          = new Index(0);
            IContentNode tempQualifier3  = target[nameof(SimpleClass.Member2)];
            Index        index4          = new Index(0);
            IContentNode tempQualifier4  = source[nameof(SimpleClass.Member2)];
            Index        index5          = new Index(0);
            IContentNode tempQualifier5  = target[nameof(SimpleClass.Member2)];
            Index        index6          = new Index(1);
            IContentNode tempQualifier6  = source[nameof(SimpleClass.Member2)];
            Index        index7          = new Index(1);
            IContentNode tempQualifier7  = target[nameof(SimpleClass.Member2)];
            Index        index8          = new Index(1);
            IContentNode tempQualifier8  = source[nameof(SimpleClass.Member2)];
            Index        index9          = new Index(1);
            IContentNode tempQualifier9  = target[nameof(SimpleClass.Member2)];
            Index        index10         = new Index(1);
            IContentNode tempQualifier10 = source[nameof(SimpleClass.Member2)];
            Index        index11         = new Index(1);
            IContentNode tempQualifier11 = target[nameof(SimpleClass.Member2)];
            var          expectedLinks   = new Dictionary <IContentNode, IContentNode>
            {
                { source, target },
                { source[nameof(SimpleClass.Member1)], target[nameof(SimpleClass.Member1)] },
                { source[nameof(SimpleClass.Member2)], target[nameof(SimpleClass.Member2)] },
                { tempQualifier.IndexedTarget(index), tempQualifier1.IndexedTarget(index1) },
                { tempQualifier2.IndexedTarget(index2)[nameof(SimpleClass.Member1)], tempQualifier3.IndexedTarget(index3)[nameof(SimpleClass.Member1)] },
                { tempQualifier4.IndexedTarget(index4)[nameof(SimpleClass.Member2)], tempQualifier5.IndexedTarget(index5)[nameof(SimpleClass.Member2)] },
                { tempQualifier6.IndexedTarget(index6), tempQualifier7.IndexedTarget(index7) },
                { tempQualifier8.IndexedTarget(index8)[nameof(SimpleClass.Member1)], tempQualifier9.IndexedTarget(index9)[nameof(SimpleClass.Member1)] },
                { tempQualifier10.IndexedTarget(index10)[nameof(SimpleClass.Member2)], tempQualifier11.IndexedTarget(index11)[nameof(SimpleClass.Member2)] },
            };

            VerifyLinks(expectedLinks, linker);
        }
예제 #4
0
        public void TestObjectWithStructList()
        {
            var nodeContainer = new NodeContainer();
            // We also test a null item in the list
            var instance = new StructListClass {
                Member1 = 3, Member2 = new List <Struct> {
                    new Struct(), new Struct()
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var visitor  = new TestVisitor();

            visitor.Visit(rootNode);
            Index        index          = new Index(0);
            IContentNode tempQualifier  = rootNode[nameof(StructListClass.Member2)];
            Index        index1         = new Index(0);
            IContentNode tempQualifier1 = rootNode[nameof(StructListClass.Member2)];
            Index        index2         = new Index(0);
            IContentNode tempQualifier2 = rootNode[nameof(StructListClass.Member2)];
            Index        index3         = new Index(1);
            IContentNode tempQualifier3 = rootNode[nameof(StructListClass.Member2)];
            Index        index4         = new Index(1);
            IContentNode tempQualifier4 = rootNode[nameof(StructListClass.Member2)];
            Index        index5         = new Index(1);
            IContentNode tempQualifier5 = rootNode[nameof(StructListClass.Member2)];
            var          expectedNodes  = new IContentNode[]
            {
                rootNode,
                rootNode[nameof(StructListClass.Member1)],
                rootNode[nameof(StructListClass.Member2)],
                tempQualifier.IndexedTarget(index),
                tempQualifier1.IndexedTarget(index1)[nameof(StructListClass.Member1)],
                tempQualifier2.IndexedTarget(index2)[nameof(StructListClass.Member2)],
                tempQualifier3.IndexedTarget(index3),
                tempQualifier4.IndexedTarget(index4)[nameof(StructListClass.Member1)],
                tempQualifier5.IndexedTarget(index5)[nameof(StructListClass.Member2)],
            };
            var expectedPaths = new[]
            {
                new GraphNodePath(rootNode),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member1)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(0)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(0)).PushMember(nameof(StructListClass.Member1)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(0)).PushMember(nameof(StructListClass.Member2)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(1)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(1)).PushMember(nameof(StructListClass.Member1)),
                new GraphNodePath(rootNode).PushMember(nameof(StructListClass.Member2)).PushIndex(new Index(1)).PushMember(nameof(StructListClass.Member2)),
            };

            VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
        }
예제 #5
0
        public void TestCustomFindTargetReference()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new ObjectListClass {
                Member1 = 3, Member2 = new List <SimpleClass> {
                    new SimpleClass {
                        Member1 = 1
                    }, new SimpleClass {
                        Member1 = 2
                    }, new SimpleClass {
                        Member1 = 3
                    }
                }
            };
            var instance2 = new ObjectListClass {
                Member1 = 3, Member2 = new List <SimpleClass> {
                    new SimpleClass {
                        Member1 = 2
                    }, new SimpleClass {
                        Member1 = 4
                    }, new SimpleClass {
                        Member1 = 1
                    }
                }
            };
            var source = nodeContainer.GetOrCreateNode(instance1);
            var target = nodeContainer.GetOrCreateNode(instance2);
            var linker = new CustomFindTargetReferenceLinker();

            linker.LinkGraph(source, target);
            // Expected links by index: 0 -> 2, 1 -> 0, 2 -> null
            Index        index           = new Index(0);
            IContentNode tempQualifier   = source[nameof(SimpleClass.Member2)];
            Index        index1          = new Index(2);
            IContentNode tempQualifier1  = target[nameof(SimpleClass.Member2)];
            Index        index2          = new Index(0);
            IContentNode tempQualifier2  = source[nameof(SimpleClass.Member2)];
            Index        index3          = new Index(2);
            IContentNode tempQualifier3  = target[nameof(SimpleClass.Member2)];
            Index        index4          = new Index(0);
            IContentNode tempQualifier4  = source[nameof(SimpleClass.Member2)];
            Index        index5          = new Index(2);
            IContentNode tempQualifier5  = target[nameof(SimpleClass.Member2)];
            Index        index6          = new Index(1);
            IContentNode tempQualifier6  = source[nameof(SimpleClass.Member2)];
            Index        index7          = new Index(0);
            IContentNode tempQualifier7  = target[nameof(SimpleClass.Member2)];
            Index        index8          = new Index(1);
            IContentNode tempQualifier8  = source[nameof(SimpleClass.Member2)];
            Index        index9          = new Index(0);
            IContentNode tempQualifier9  = target[nameof(SimpleClass.Member2)];
            Index        index10         = new Index(1);
            IContentNode tempQualifier10 = source[nameof(SimpleClass.Member2)];
            Index        index11         = new Index(0);
            IContentNode tempQualifier11 = target[nameof(SimpleClass.Member2)];
            Index        index12         = new Index(2);
            IContentNode tempQualifier12 = source[nameof(SimpleClass.Member2)];
            Index        index13         = new Index(2);
            IContentNode tempQualifier13 = source[nameof(SimpleClass.Member2)];
            Index        index14         = new Index(2);
            IContentNode tempQualifier14 = source[nameof(SimpleClass.Member2)];
            var          expectedLinks   = new Dictionary <IContentNode, IContentNode>
            {
                { source, target },
                { source[nameof(SimpleClass.Member1)], target[nameof(SimpleClass.Member1)] },
                { source[nameof(SimpleClass.Member2)], target[nameof(SimpleClass.Member2)] },
                { tempQualifier.IndexedTarget(index), tempQualifier1.IndexedTarget(index1) },
                { tempQualifier2.IndexedTarget(index2)[nameof(SimpleClass.Member1)], tempQualifier3.IndexedTarget(index3)[nameof(SimpleClass.Member1)] },
                { tempQualifier4.IndexedTarget(index4)[nameof(SimpleClass.Member2)], tempQualifier5.IndexedTarget(index5)[nameof(SimpleClass.Member2)] },
                { tempQualifier6.IndexedTarget(index6), tempQualifier7.IndexedTarget(index7) },
                { tempQualifier8.IndexedTarget(index8)[nameof(SimpleClass.Member1)], tempQualifier9.IndexedTarget(index9)[nameof(SimpleClass.Member1)] },
                { tempQualifier10.IndexedTarget(index10)[nameof(SimpleClass.Member2)], tempQualifier11.IndexedTarget(index11)[nameof(SimpleClass.Member2)] },
                { tempQualifier12.IndexedTarget(index12), null },
                { tempQualifier13.IndexedTarget(index13)[nameof(SimpleClass.Member1)], null },
                { tempQualifier14.IndexedTarget(index14)[nameof(SimpleClass.Member2)], null },
            };

            VerifyLinks(expectedLinks, linker);
        }