示例#1
0
 public void TestCloneNewRoot()
 {
     var obj1 = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
     var obj2 = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
     var nodeContainer = new NodeContainer();
     var newRoot = nodeContainer.GetOrCreateNode(obj2);
     var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj1));
     var clone = path1.Clone(newRoot);
     Assert.AreNotEqual(newRoot, path1.RootNode);
     Assert.AreEqual(newRoot, clone.RootNode);
     Assert.AreEqual(path1.IsValid, clone.IsValid);
     Assert.AreEqual(path1.IsEmpty, clone.IsEmpty);
     var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
     clone = path2.Clone(newRoot);
     Assert.AreNotEqual(newRoot, path2.RootNode);
     Assert.AreEqual(newRoot, clone.RootNode);
     Assert.AreEqual(path2.IsValid, clone.IsValid);
     Assert.AreEqual(path2.IsEmpty, clone.IsEmpty);
     var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
     clone = path3.Clone(newRoot);
     Assert.AreNotEqual(newRoot, path3.RootNode);
     Assert.AreEqual(newRoot, clone.RootNode);
     Assert.AreEqual(path3.IsValid, clone.IsValid);
     Assert.AreEqual(path3.IsEmpty, clone.IsEmpty);
 }
示例#2
0
        public void TestObjectListWithSimpleObjects()
        {
            var items = new[] { new SimpleObject(), new SimpleObject(), new SimpleObject(), new SimpleObject() };
            var obj   = new ListContainer {
                ObjectList = { items[0], items[1] }
            };
            var nodeContainer = new NodeContainer();
            var containerNode = nodeContainer.GetOrCreateNode(obj);
            var memberNode    = containerNode[nameof(ListContainer.ObjectList)];

            Helper.TestMemberNode(containerNode, memberNode, obj, obj.ObjectList, nameof(ListContainer.ObjectList), true);
            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);

            // Add a new item
            memberNode.Add(items[2]);
            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);
            VerifyItem(memberNode, 2, items[2], false);

            // Update existing item (with a different type here)
            memberNode.Update(items[3], new Index(2));
            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);
            VerifyItem(memberNode, 2, items[3], false);
        }
示例#3
0
        public void TestListInObjectMember()
        {
            var nodeContainer = new NodeContainer();
            var values        = new object[] { new SimpleObject(), new List <SimpleObject> {
                                                   new SimpleObject(), new SimpleObject()
                                               }, new SimpleObject() };
            var container = new ListContainer {
                ObjectMember = values[0]
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Assert.AreEqual(container.ObjectMember, containerNode[nameof(ListContainer.ObjectMember)].Retrieve());
            containerNode[nameof(ListContainer.ObjectMember)].Update(values[1]);
            Assert.AreEqual(values[1], container.ObjectMember);
            Assert.AreEqual(container.ObjectMember, containerNode[nameof(ListContainer.ObjectMember)].Retrieve());
            Assert.AreEqual(true, containerNode[nameof(ListContainer.ObjectMember)].IsReference);
            Assert.NotNull(containerNode[nameof(ListContainer.ObjectMember)].Indices);
            Assert.AreEqual(2, containerNode[nameof(ListContainer.ObjectMember)].Indices.Count());
            Assert.AreEqual(new Index(0), containerNode[nameof(ListContainer.ObjectMember)].Indices.ToList()[0]);
            Assert.AreEqual(new Index(1), containerNode[nameof(ListContainer.ObjectMember)].Indices.ToList()[1]);
            Assert.AreEqual(TypeDescriptorFactory.Default.Find(typeof(object)), containerNode[nameof(ListContainer.ObjectMember)].Descriptor);
            Assert.IsFalse(containerNode[nameof(ListContainer.ObjectMember)].IsPrimitive);
            Assert.AreEqual(((IList)values[1])[0], containerNode[nameof(ListContainer.ObjectMember)].IndexedTarget(new Index(0)));
            Assert.AreEqual(((IList)values[1])[1], containerNode[nameof(ListContainer.ObjectMember)].IndexedTarget(new Index(1)));
            Assert.AreEqual(typeof(object), containerNode[nameof(ListContainer.ObjectMember)].Type);
            // TODO: more things could be checked!
            containerNode[nameof(ListContainer.ObjectMember)].Update(values[2]);
            Assert.AreEqual(values[2], container.ObjectMember);
            Assert.AreEqual(container.ObjectMember, containerNode[nameof(ListContainer.ObjectMember)]);
        }
 public void TestSimpleObject()
 {
     var nodeContainer = new NodeContainer();
     var instance = new SimpleClass { Member1 = 3, Member2 = new SimpleClass() };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var visitor = new TestVisitor();
     visitor.Visit(rootNode);
     var expectedNodes = new[]
     {
         rootNode,
         rootNode.TryGetChild(nameof(SimpleClass.Member1)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target,
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member1)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member2)),
     };
     var expectedPaths = new[]
     {
         new GraphNodePath(rootNode),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member1)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget(),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member1)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member2)),
     };
     VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
 }
示例#5
0
        public void TestObjectReferenceSameInstance()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new TestObject {
                Name = "Test"
            };
            var container = new ObjectsContainer {
                Instance1 = instance, Instance2 = instance
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Helper.TestObjectContentNode(containerNode, container, 2);

            var member1Node = containerNode.Children.First();

            Helper.TestMemberContentNode(containerNode, member1Node, container, instance, nameof(ObjectsContainer.Instance1), true);
            Helper.TestNonNullObjectReference(member1Node.Content.Reference, instance);

            var member2Node = containerNode.Children.Last();

            Helper.TestMemberContentNode(containerNode, member2Node, container, instance, nameof(ObjectsContainer.Instance2), true);
            Helper.TestNonNullObjectReference(member2Node.Content.Reference, instance);

            var reference1 = member1Node.Content.Reference.AsObject;
            var reference2 = member2Node.Content.Reference.AsObject;

            Assert.AreEqual(reference1.TargetGuid, reference2.TargetGuid);
            Assert.AreEqual(reference1.TargetNode, reference2.TargetNode);
            Assert.AreEqual(reference1.ObjectValue, reference2.ObjectValue);
        }
示例#6
0
        public void TestRegisteredPrimitiveStructMember()
        {
            var obj = new RegisteredPrimitiveStructMember {
                Member = new PrimitiveStruct {
                    Value = 1
                }
            };
            var container = new NodeContainer();

            container.NodeBuilder.RegisterPrimitiveType(typeof(PrimitiveStruct));

            // Construction
            var containerNode = container.GetOrCreateNode(obj);

            Helper.TestNonCollectionObjectNode(containerNode, obj, 1);
            var memberNode = containerNode.Members.First();

            Helper.TestMemberNode(containerNode, memberNode, obj, obj.Member, nameof(RegisteredPrimitiveStructMember.Member), false);

            // Update from object
            obj.Member = new PrimitiveStruct {
                Value = 2
            };
            Helper.TestMemberNode(containerNode, memberNode, obj, obj.Member, nameof(RegisteredPrimitiveStructMember.Member), false);

            // Update from Quantum
            containerNode.Members.Last().Update(new PrimitiveStruct {
                Value = 3
            });
            Helper.TestMemberNode(containerNode, memberNode, obj, obj.Member, nameof(RegisteredPrimitiveStructMember.Member), false);
        }
示例#7
0
        public void TestSimpleStructUpdate()
        {
            var nodeContainer = new NodeContainer();
            var container     = new StructContainer {
                Struct = new SimpleStruct {
                    Name = "Test", Value = 1
                }
            };
            var containerNode     = nodeContainer.GetOrCreateNode(container);
            var memberNode        = containerNode[nameof(StructContainer.Struct)];
            var targetNode        = memberNode.Target;
            var structMember1Node = targetNode[nameof(SimpleStruct.Name)];
            var structMember2Node = targetNode[nameof(SimpleStruct.Value)];

            memberNode.Update(new SimpleStruct {
                Name = "Test2", Value = 2
            });

            Assert.Equal("Test2", container.Struct.Name);
            Assert.Equal(2, container.Struct.Value);
            Assert.Equal(targetNode, memberNode.Target);
            Assert.Equal(structMember1Node, memberNode.Target[nameof(SimpleStruct.Name)]);
            Assert.Equal(structMember2Node, memberNode.Target[nameof(SimpleStruct.Value)]);
            structMember1Node = memberNode.Target[nameof(SimpleStruct.Name)];
            Helper.TestMemberNode(memberNode.Target, structMember1Node, container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);
            structMember2Node = memberNode.Target[nameof(SimpleStruct.Value)];
            Helper.TestMemberNode(memberNode.Target, structMember2Node, container.Struct, container.Struct.Value, nameof(SimpleStruct.Value), false);
        }
示例#8
0
        public void TestSimpleStructCollectionUpdate()
        {
            var nodeContainer = new NodeContainer();
            var container     = new StructWithCollectionContainer {
                Struct = new StructWithCollection {
                    Strings = new List <string> {
                        "aaa", "bbb"
                    }
                }
            };
            var containerNode    = nodeContainer.GetOrCreateNode(container);
            var memberNode       = containerNode[nameof(StructWithCollectionContainer.Struct)];
            var targetNode       = memberNode.Target;
            var structMemberNode = targetNode[nameof(StructWithCollection.Strings)];

            Helper.TestNonCollectionObjectNode(containerNode, container, 1);
            Helper.TestMemberNode(containerNode, memberNode, container, container.Struct, nameof(StructWithCollectionContainer.Struct), true);
            Helper.TestNonNullObjectReference(memberNode.TargetReference, container.Struct, false);
            Helper.TestMemberNode(targetNode, structMemberNode, container.Struct, container.Struct.Strings, nameof(StructWithCollection.Strings), true);

            structMemberNode.Target.Update("ddd", new NodeIndex(1));
            Assert.Equal("ddd", container.Struct.Strings[1]);
            Assert.Equal(targetNode, memberNode.Target);
            Assert.Equal(structMemberNode, targetNode[nameof(StructWithCollection.Strings)]);
            Helper.TestMemberNode(targetNode, structMemberNode, container.Struct, container.Struct.Strings, nameof(StructWithCollection.Strings), true);
        }
示例#9
0
        public void TestRemoveReferenceListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { new SimpleClass(), new SimpleClass(), new SimpleClass() };
            var instance      = new ComplexClass {
                Member6 = new List <SimpleClass> {
                    obj[0], obj[1], obj[2]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member6[0], (SimpleClass)dynNode.Member6[0]);
            Assert.Equal(instance.Member6[1], (SimpleClass)dynNode.Member6[1]);
            Assert.Equal(instance.Member6[2], (SimpleClass)dynNode.Member6[2]);
            Assert.Equal(obj[0], (SimpleClass)dynNode.Member6[0]);
            Assert.Equal(obj[1], (SimpleClass)dynNode.Member6[1]);
            Assert.Equal(obj[2], (SimpleClass)dynNode.Member6[2]);
            dynNode.Member6.Remove(obj[1], new Index(1));
            Assert.Equal(instance.Member6[0], (SimpleClass)dynNode.Member6[0]);
            Assert.Equal(instance.Member6[1], (SimpleClass)dynNode.Member6[1]);
            Assert.Equal(obj[0], (SimpleClass)dynNode.Member6[0]);
            Assert.Equal(obj[2], (SimpleClass)dynNode.Member6[1]);
            rootNode[nameof(ComplexClass.Member6)].Target.Remove(obj[2], new Index(1));
            Assert.Equal(instance.Member6[0], (SimpleClass)dynNode.Member6[0]);
            Assert.Equal(obj[0], (SimpleClass)dynNode.Member6[0]);
        }
示例#10
0
        public void TestRemovePrimitiveListItem()
        {
            var nodeContainer = new NodeContainer();
            var obj           = new[] { "aa", "bb", "cc" };
            var instance      = new ComplexClass {
                Member5 = new List <string> {
                    obj[0], obj[1], obj[2]
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member5[0], (string)dynNode.Member5[0]);
            Assert.Equal(instance.Member5[1], (string)dynNode.Member5[1]);
            Assert.Equal(instance.Member5[2], (string)dynNode.Member5[2]);
            Assert.Equal(obj[0], (string)dynNode.Member5[0]);
            Assert.Equal(obj[1], (string)dynNode.Member5[1]);
            Assert.Equal(obj[2], (string)dynNode.Member5[2]);
            dynNode.Member5.Remove(obj[1], new Index(1));
            Assert.Equal(instance.Member5[0], (string)dynNode.Member5[0]);
            Assert.Equal(instance.Member5[1], (string)dynNode.Member5[1]);
            Assert.Equal(obj[0], (string)dynNode.Member5[0]);
            Assert.Equal(obj[2], (string)dynNode.Member5[1]);
            rootNode[nameof(ComplexClass.Member5)].Target.Remove(obj[2], new Index(1));
            Assert.Equal(instance.Member5[0], (string)dynNode.Member5[0]);
            Assert.Equal(obj[0], (string)dynNode.Member5[0]);
        }
示例#11
0
        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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member5, (List <string>)dynNode.Member5);
            Assert.Equal(obj[0], (List <string>)dynNode.Member5);
            dynNode.Member5 = obj[1];
            Assert.Equal(instance.Member5, (List <string>)dynNode.Member5);
            Assert.Equal(obj[1], (List <string>)dynNode.Member5);
            rootNode[nameof(ComplexClass.Member5)].Update(obj[2]);
            Assert.Equal(instance.Member5, (List <string>)dynNode.Member5);
            Assert.Equal(obj[2], (List <string>)dynNode.Member5);
        }
示例#12
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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member4, (Struct)dynNode.Member4);
            Assert.Equal(obj[0].Member1, (string)dynNode.Member4.Member1);
            dynNode.Member4 = obj[1];
            Assert.Equal(obj[1], instance.Member4);
            Assert.Equal(obj[1].Member1, (string)dynNode.Member4.Member1);
            Assert.Equal(instance.Member4, (Struct)dynNode.Member4);
            rootNode[nameof(ComplexClass.Member4)].Update(obj[2]);
            Assert.Equal(obj[2], instance.Member4);
            Assert.Equal(obj[2].Member1, (string)dynNode.Member4.Member1);
            Assert.Equal(instance.Member4, (Struct)dynNode.Member4);
        }
示例#13
0
        public void TestSimpleObject()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new SimpleClass {
                Member1 = 3, Member2 = new SimpleClass()
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var visitor  = new TestVisitor();

            visitor.Visit(rootNode);
            var expectedNodes = new IGraphNode[]
            {
                rootNode,
                rootNode[nameof(SimpleClass.Member1)],
                rootNode[nameof(SimpleClass.Member2)],
                rootNode[nameof(SimpleClass.Member2)].Target,
                rootNode[nameof(SimpleClass.Member2)].Target[nameof(SimpleClass.Member1)],
                rootNode[nameof(SimpleClass.Member2)].Target[nameof(SimpleClass.Member2)],
            };
            var expectedPaths = new GraphNodePath[6];

            expectedPaths[0] = new GraphNodePath(rootNode);
            expectedPaths[1] = new GraphNodePath(rootNode);
            expectedPaths[1].PushMember(nameof(SimpleClass.Member1));
            expectedPaths[2] = new GraphNodePath(rootNode);
            expectedPaths[2].PushMember(nameof(SimpleClass.Member2));
            expectedPaths[3] = expectedPaths[2].Clone();
            expectedPaths[3].PushTarget();
            expectedPaths[4] = expectedPaths[3].Clone();
            expectedPaths[4].PushMember(nameof(SimpleClass.Member1));
            expectedPaths[5] = expectedPaths[3].Clone();
            expectedPaths[5].PushMember(nameof(SimpleClass.Member2));
            VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
        }
示例#14
0
        public void TestObjectWithPrimitiveList()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new PrimitiveListClass {
                Member1 = 3, Member2 = new List <string> {
                    "aaa", "bbb", "ccc"
                }
            };
            var rootNode = nodeContainer.GetOrCreateNode(instance);
            var visitor  = new TestVisitor();

            visitor.Visit(rootNode);
            var expectedNodes = new IGraphNode[]
            {
                rootNode,
                rootNode[nameof(PrimitiveListClass.Member1)],
                rootNode[nameof(PrimitiveListClass.Member2)],
                rootNode[nameof(PrimitiveListClass.Member2)].Target,
            };
            var expectedPaths = new GraphNodePath[4];

            expectedPaths[0] = new GraphNodePath(rootNode);
            expectedPaths[1] = expectedPaths[0].Clone();
            expectedPaths[1].PushMember(nameof(PrimitiveListClass.Member1));
            expectedPaths[2] = expectedPaths[0].Clone();
            expectedPaths[2].PushMember(nameof(PrimitiveListClass.Member2));
            expectedPaths[3] = expectedPaths[2].Clone();
            expectedPaths[3].PushTarget();
            VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
        }
        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.GetChild(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)));
        }
示例#16
0
        public void TestSimpleStructMemberUpdate()
        {
            var nodeContainer = new NodeContainer();
            var container     = new StructContainer {
                Struct = new SimpleStruct {
                    Name = "Test", Value = 1
                }
            };
            var containerNode     = nodeContainer.GetOrCreateNode(container);
            var memberNode        = containerNode[nameof(StructContainer.Struct)];
            var targetNode        = memberNode.Target;
            var structMember1Node = targetNode[nameof(SimpleStruct.Name)];
            var structMember2Node = targetNode[nameof(SimpleStruct.Value)];

            Helper.TestNonCollectionObjectNode(containerNode, container, 1);
            Helper.TestMemberNode(containerNode, memberNode, container, container.Struct, nameof(StructContainer.Struct), true);
            Helper.TestNonNullObjectReference(memberNode.TargetReference, container.Struct, false);
            Helper.TestMemberNode(memberNode.Target, structMember1Node, container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);

            structMember1Node.Update("Test2");
            Assert.Equal("Test2", container.Struct.Name);
            Assert.Equal(targetNode, memberNode.Target);
            Assert.Equal(structMember1Node, memberNode.Target[nameof(SimpleStruct.Name)]);
            Assert.Equal(structMember2Node, memberNode.Target[nameof(SimpleStruct.Value)]);
            Helper.TestMemberNode(memberNode.Target, structMember1Node, container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);
            Helper.TestMemberNode(memberNode.Target, memberNode.Target.Members.First(), container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);
        }
示例#17
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.Equal(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
            Assert.Equal(obj[0], (int)dynNode.Member6[1].Member1);
            dynNode.Member6[1].Member1 = obj[1];
            Assert.Equal(obj[1], (int)dynNode.Member6[1].Member1);
            Assert.Equal(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
            Index index = new Index(1);

            rootNode[nameof(ComplexClass.Member6)].Target.IndexedTarget(index)[nameof(SimpleClass.Member1)].Update(obj[2]);
            Assert.Equal(obj[2], (int)dynNode.Member6[1].Member1);
            Assert.Equal(instance.Member6[1].Member1, (int)dynNode.Member6[1].Member1);
        }
示例#18
0
        public void TestNestedStruct()
        {
            var nodeContainer = new NodeContainer();
            var container     = new NestingStructContainer {
                Struct = new FirstNestingStruct {
                    Struct1 = new SecondNestingStruct {
                        Struct2 = new SimpleStruct {
                            Name = "Test", Value = 1
                        }
                    }
                }
            };
            var containerNode           = nodeContainer.GetOrCreateNode(container);
            var memberNode              = containerNode[nameof(NestingStructContainer.Struct)];
            var firstTargetNode         = memberNode.Target;
            var firstNestingMemberNode  = firstTargetNode[nameof(FirstNestingStruct.Struct1)];
            var secondTargetNode        = firstNestingMemberNode.Target;
            var secondNestingMemberNode = secondTargetNode[nameof(SecondNestingStruct.Struct2)];
            var structMember1Node       = secondNestingMemberNode.Target[nameof(SimpleStruct.Name)];
            var structMember2Node       = secondNestingMemberNode.Target[nameof(SimpleStruct.Value)];

            Helper.TestNonCollectionObjectNode(containerNode, container, 1);
            Helper.TestMemberNode(containerNode, memberNode, container, container.Struct, nameof(StructContainer.Struct), true);
            Helper.TestNonNullObjectReference(memberNode.TargetReference, container.Struct, false);
            Helper.TestMemberNode(memberNode.Target, firstNestingMemberNode, container.Struct, container.Struct.Struct1, nameof(FirstNestingStruct.Struct1), true);
            Helper.TestNonNullObjectReference(firstNestingMemberNode.TargetReference, container.Struct.Struct1, false);
            Helper.TestMemberNode(firstNestingMemberNode.Target, secondNestingMemberNode, container.Struct.Struct1, container.Struct.Struct1.Struct2, nameof(SecondNestingStruct.Struct2), true);
            Helper.TestNonNullObjectReference(secondNestingMemberNode.TargetReference, container.Struct.Struct1.Struct2, false);
            Helper.TestMemberNode(secondNestingMemberNode.Target, structMember1Node, container.Struct.Struct1.Struct2, container.Struct.Struct1.Struct2.Name, nameof(SimpleStruct.Name), false);
            Helper.TestMemberNode(secondNestingMemberNode.Target, structMember2Node, container.Struct.Struct1.Struct2, container.Struct.Struct1.Struct2.Value, nameof(SimpleStruct.Value), false);
        }
示例#19
0
        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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member7, (List <Struct>)dynNode.Member7);
            Assert.Equal(obj[0], (List <Struct>)dynNode.Member7);
            dynNode.Member7 = obj[1];
            Assert.Equal(instance.Member7, (List <Struct>)dynNode.Member7);
            Assert.Equal(obj[1], (List <Struct>)dynNode.Member7);
            rootNode[nameof(ComplexClass.Member7)].Update(obj[2]);
            Assert.Equal(instance.Member7, (List <Struct>)dynNode.Member7);
            Assert.Equal(obj[2], (List <Struct>)dynNode.Member7);
        }
 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());
 }
示例#21
0
        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 dynNode  = DynamicNode.FromNode(rootNode);

            Assert.Equal(instance.Member7[0], (Struct)dynNode.Member7[0]);
            Assert.Equal(instance.Member7[1], (Struct)dynNode.Member7[1]);
            Assert.Equal(instance.Member7[2], (Struct)dynNode.Member7[2]);
            Assert.Equal(obj[0], (Struct)dynNode.Member7[0]);
            Assert.Equal(obj[1], (Struct)dynNode.Member7[1]);
            Assert.Equal(obj[2], (Struct)dynNode.Member7[2]);
            dynNode.Member7.Remove(obj[1], new Index(1));
            Assert.Equal(instance.Member7[0], (Struct)dynNode.Member7[0]);
            Assert.Equal(instance.Member7[1], (Struct)dynNode.Member7[1]);
            Assert.Equal(obj[0], (Struct)dynNode.Member7[0]);
            Assert.Equal(obj[2], (Struct)dynNode.Member7[1]);
            rootNode[nameof(ComplexClass.Member7)].Target.Remove(obj[2], new Index(1));
            Assert.Equal(instance.Member7[0], (Struct)dynNode.Member7[0]);
            Assert.Equal(obj[0], (Struct)dynNode.Member7[0]);
        }
示例#22
0
        public void TestEnumerableReference()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new TestObject {
                Name = "Test1"
            };
            var instance2 = new TestObject {
                Name = "Test2"
            };
            var container = new MultipleObjectContainer {
                Instances = { instance1, instance2 }
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Helper.TestObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();

            Helper.TestMemberContentNode(containerNode, memberNode, container, container.Instances, nameof(MultipleObjectContainer.Instances), true);
            Helper.TestReferenceEnumerable(memberNode.Content.Reference, container.Instances);

            Assert.AreEqual(container.Instances, memberNode.Content.Retrieve());
            Assert.AreEqual(instance1, memberNode.Content.Retrieve(0));
            Assert.AreEqual(instance2, memberNode.Content.Retrieve(1));

            var reference1 = memberNode.Content.Reference.AsEnumerable.First();

            Helper.TestMemberContentNode(reference1.TargetNode, reference1.TargetNode.Children.First(), instance1, instance1.Name, nameof(TestObject.Name), false);

            var reference2 = memberNode.Content.Reference.AsEnumerable.Last();

            Helper.TestMemberContentNode(reference2.TargetNode, reference2.TargetNode.Children.First(), instance2, instance2.Name, nameof(TestObject.Name), false);
        }
示例#23
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.Equal(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
            Assert.Equal(obj[0], (string)dynNode.Member7[1].Member1);
            dynNode.Member7[1].Member1 = obj[1];
            Assert.Equal(obj[1], (string)dynNode.Member7[1].Member1);
            Assert.Equal(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
            Index index = new Index(1);

            rootNode[nameof(ComplexClass.Member7)].Target.IndexedTarget(index)[nameof(SimpleClass.Member1)].Update(obj[2]);
            Assert.Equal(obj[2], (string)dynNode.Member7[1].Member1);
            Assert.Equal(instance.Member7[1].Member1, (string)dynNode.Member7[1].Member1);
        }
示例#24
0
        public void TestEnumerableReferenceSameInstance()
        {
            var nodeContainer = new NodeContainer();
            var instance      = new TestObject {
                Name = "Test"
            };
            var container = new MultipleObjectContainer {
                Instances = { instance, instance }
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Helper.TestObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();

            Helper.TestMemberContentNode(containerNode, memberNode, container, container.Instances, nameof(MultipleObjectContainer.Instances), true);
            Helper.TestReferenceEnumerable(memberNode.Content.Reference, container.Instances);

            var reference = memberNode.Content.Reference.AsEnumerable;

            Assert.AreEqual(2, reference.Count);
            var reference1 = reference.First();
            var reference2 = reference.Last();

            Assert.AreEqual(reference1.ObjectValue, reference2.ObjectValue);
            Assert.AreEqual(reference1.TargetGuid, reference2.TargetGuid);
            Assert.AreEqual(reference1.TargetNode, reference2.TargetNode);
        }
        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.GetChild(nameof(ComplexClass.Member4));

            Assert.AreEqual("aa", node.GetChild(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.GetChild(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.GetChild(nameof(Struct.Member1)).Content.Retrieve());
            TestContentChange(listener, node.GetChild(nameof(Struct.Member1)), ContentChangeType.ValueChange, Index.Empty, "cc", "dd", () => node.GetChild(nameof(Struct.Member1)).Content.Update("dd"));
            Assert.AreEqual("dd", node.GetChild(nameof(Struct.Member1)).Content.Retrieve());
        }
示例#26
0
        public void TestObjectListWithBoxedPrimitiveValue()
        {
            var obj = new ListContainer {
                ObjectList = { 1.0f, 2.0f }
            };
            var nodeContainer = new NodeContainer();

            // Construction
            var containerNode = nodeContainer.GetOrCreateNode(obj);
            var memberNode    = containerNode[nameof(ListContainer.ObjectList)];

            Helper.TestMemberNode(containerNode, memberNode, obj, obj.ObjectList, nameof(ListContainer.ObjectList), true);
            VerifyItem(memberNode, 0, 1.0f, true);
            VerifyItem(memberNode, 1, 2.0f, true);

            // Add a new item
            memberNode.Add(3.0f);
            VerifyItem(memberNode, 0, 1.0f, true);
            VerifyItem(memberNode, 1, 2.0f, true);
            VerifyItem(memberNode, 2, 3.0f, true);

            // Update existing item (with a different type here)
            memberNode.Update(4.0, new Index(2));
            VerifyItem(memberNode, 0, 1.0f, true);
            VerifyItem(memberNode, 1, 2.0f, true);
            VerifyItem(memberNode, 2, 4.0, true);
        }
        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));

            Assert.AreEqual("aa", node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => 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], () => node.Content.Update(obj[2]));
            Assert.AreEqual("cc", node.Content.Retrieve(new Index(0)));
            TestContentChange(listener, node, ContentChangeType.ValueChange, new Index(0), "cc", "dd", () => node.Content.Update("dd", new Index(0)));
            Assert.AreEqual("dd", node.Content.Retrieve(new Index(0)));
        }
示例#28
0
        public void TestMultipleTimesSameObject()
        {
            var items         = new[] { new SimpleObject(), new SimpleObject() };
            var nodeContainer = new NodeContainer();
            var container     = new ListContainer {
                List = { items[0], items[1], items[0], items[1] }
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var memberNode    = containerNode[nameof(ListContainer.List)];

            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);
            VerifyItem(memberNode, 2, items[0], false);
            VerifyItem(memberNode, 3, items[1], false);

            memberNode.Add(items[0]);
            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);
            VerifyItem(memberNode, 2, items[0], false);
            VerifyItem(memberNode, 3, items[1], false);
            VerifyItem(memberNode, 4, items[0], false);

            memberNode.Update(items[1], new Index(2));
            VerifyItem(memberNode, 0, items[0], false);
            VerifyItem(memberNode, 1, items[1], false);
            VerifyItem(memberNode, 2, items[1], false);
            VerifyItem(memberNode, 3, items[1], false);
            VerifyItem(memberNode, 4, items[0], false);
        }
        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.GetChild(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)));
        }
示例#30
0
        public void TestCircularReferences()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new ObjectContainer();
            var instance2     = new ObjectContainer();

            instance1.Instance = instance2;
            instance2.Instance = instance1;
            var instance1Node = nodeContainer.GetOrCreateNode(instance1);
            var instance2Node = nodeContainer.GetOrCreateNode(instance2);

            Assert.AreEqual(1, instance1Node.Children.Count);
            Assert.AreEqual(1, instance2Node.Children.Count);
            Assert.AreEqual(instance1Node.Children.First().Content.Reference.AsObject.TargetNode, instance2Node);
            Assert.AreEqual(instance2Node.Children.First().Content.Reference.AsObject.TargetNode, instance1Node);
        }
示例#31
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);
        }
示例#32
0
        public void TestConstruction()
        {
            var obj = new ClassWithStructs();
            var container = new NodeContainer();
            container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
            IGraphNode model = container.GetOrCreateNode(obj);
            Helper.PrintModelContainerContent(container, model);

            // Members should never have children
            Assert.That(model.GetChild("PrimitiveStruct").Children.Count, Is.EqualTo(0));
            // Primitive struct has been registered as a primitive type, so it should not hold a reference.
            Assert.Null(model.GetChild("PrimitiveStruct").Content.Reference);
            // Members should never have children.
            Assert.That(model.GetChild("NestedStruct").Children.Count, Is.EqualTo(0));
            // NestedStruct members should be accessible via a reference.
            Assert.NotNull(model.GetChild("NestedStruct").Content.Reference);
            // The referenced node must exist.
            var structNode = model.GetChild("NestedStruct").Content.Reference.AsObject.TargetNode;
            Assert.NotNull(structNode);
            // It should have two children, as the NestedStruct has.
            Assert.That(structNode.Children.Count, Is.EqualTo(2));
            // Similarly, the Struct member of the NestedStruct should hold a reference.
            Assert.NotNull(structNode.GetChild("Struct").Content.Reference);
            // The referenced node must exist.
            structNode = structNode.GetChild("Struct").Content.Reference.AsObject.TargetNode;
            Assert.NotNull(structNode);
            // It should have two children, as the SimpleStruct has.
            Assert.That(structNode.Children.Count, Is.EqualTo(2));
            // Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues.
            Helper.ConsistencyCheck(container, obj);
        }
示例#33
0
        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);
        }
示例#34
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);
        }
示例#35
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);
        }
示例#36
0
        public void TestReferenceMember()
        {
            var obj = new ReferenceMember { Member = new StringMember { Member = "a" } };

            var container = new NodeContainer();
            var node = container.GetOrCreateNode(obj);
            Assert.AreEqual(obj, node.Content.Value);
            Assert.AreEqual(1, node.Children.Count);
            Assert.AreEqual(nameof(ReferenceMember.Member), node.Children.First().Name);
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
            Assert.AreEqual(true, node.Children.First().Content.IsReference);
            Assert.IsInstanceOf<ObjectReference>(node.Children.First().Content.Reference);
            var reference = (ObjectReference)node.Children.First().Content.Reference;
            Assert.AreEqual(obj.Member, reference.ObjectValue);
            Assert.IsNotNull(reference.TargetNode);
            Assert.AreEqual(obj.Member, reference.TargetNode.Content.Value);
            node = reference.TargetNode;
            Assert.AreEqual(obj.Member, node.Content.Value);
            Assert.AreEqual(1, node.Children.Count);
            Assert.AreEqual(nameof(StringMember.Member), node.Children.First().Name);
            Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
            obj.Member.Member = "b";
            Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
            node.Children.First().Content.Update("c");
            Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
        }
 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));
 }
示例#38
0
 public void TestConstructor()
 {
     var obj = new Class();
     var nodeContainer = new NodeContainer();
     var rootNode = nodeContainer.GetOrCreateNode(obj);
     var path = new GraphNodePath(rootNode);
     Assert.True(path.IsValid);
     Assert.True(path.IsEmpty);
     Assert.AreEqual(rootNode, path.RootNode);
 }
示例#39
0
        public void TestNullObjectReference()
        {
            var nodeContainer = new NodeContainer();
            var container = new ObjectContainer { Instance = null };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            Helper.TestNonCollectionObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();
            Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true);
            Helper.TestNullObjectReference(memberNode.Content.Reference);
        }
 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 TestChangePrimitiveMember()
 {
     var nodeContainer = new NodeContainer();
     var instance = new ComplexClass { Member1 = 3 };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var dynNode = DynamicNode.FromNode(rootNode);
     Assert.AreEqual(instance.Member1, (int)dynNode.Member1);
     dynNode.Member1 = 4;
     Assert.AreEqual(4, instance.Member1);
     Assert.AreEqual(instance.Member1, (int)dynNode.Member1);
     rootNode.TryGetChild(nameof(ComplexClass.Member1)).Content.Update(5);
     Assert.AreEqual(5, instance.Member1);
     Assert.AreEqual(instance.Member1, (int)dynNode.Member1);
 }
示例#42
0
        public void TestStringMember()
        {
            var obj = new StringMember { Member = "a" };

            var container = new NodeContainer();
            var node = (GraphNode)container.GetOrCreateNode(obj);
            Assert.AreEqual(obj, node.Content.Value);
            Assert.AreEqual(1, node.Children.Count);
            Assert.AreEqual(nameof(StringMember.Member), node.Children.First().Name);
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
            obj.Member = "b";
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
            node.Children.First().Content.Update("c");
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
        }
示例#43
0
        public void TestPrimitiveMember()
        {
            var obj = new PrimitiveMember { Member = 5 };

            var container = new NodeContainer();
            var node = (GraphNode)container.GetOrCreateNode(obj);
            Assert.AreEqual(obj, node.Content.Value);
            Assert.AreEqual(1, node.Children.Count);
            Assert.AreEqual(nameof(PrimitiveMember.Member), node.Children.First().Name);
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
            obj.Member = 6;
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
            node.Children.First().Content.Update(7);
            Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
        }
 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 dynNode = DynamicNode.FromNode(rootNode);
     Assert.AreEqual(instance.Member2, (SimpleClass)dynNode.Member2);
     dynNode.Member2 = obj[1];
     Assert.AreEqual(obj[1], instance.Member2);
     Assert.AreEqual(instance.Member2, (SimpleClass)dynNode.Member2);
     rootNode.TryGetChild(nameof(ComplexClass.Member2)).Content.Update(obj[2]);
     Assert.AreEqual(obj[2], instance.Member2);
     Assert.AreEqual(instance.Member2, (SimpleClass)dynNode.Member2);
 }
示例#45
0
        public void TestDoubleReferenceMemberDataUpdate()
        {
            var doubleRef = new DoubleReferenceClass(new SimpleObject());
            var container = new NodeContainer();
            IGraphNode model = container.GetOrCreateNode(doubleRef);

            doubleRef.Object1.Name = "New Name";

            Assert.That(doubleRef.Object1.Name, Is.EqualTo("New Name"));
            Assert.That(doubleRef.Object2.Name, Is.EqualTo("New Name"));
            var object1TargetNode = ((ObjectReference)model.GetChild("Object1").Content.Reference).TargetNode;
            var object2TargetNode = ((ObjectReference)model.GetChild("Object2").Content.Reference).TargetNode;
            Assert.That(object1TargetNode.GetChild("Name").Content.Value, Is.EqualTo("New Name"));
            Assert.That(object2TargetNode.GetChild("Name").Content.Value, Is.EqualTo("New Name"));
        }
示例#46
0
        public void TestSimpleStruct()
        {
            var nodeContainer = new NodeContainer();
            var container = new StructContainer { Struct = new SimpleStruct { Name = "Test", Value = 1 } };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            Helper.TestNonCollectionObjectContentNode(containerNode, container, 1);

            var memberNode = containerNode.Children.First();
            Helper.TestMemberContentNode(containerNode, memberNode, container, container.Struct, nameof(StructContainer.Struct), false);
            Helper.TestStructContentNode(memberNode, container.Struct, 2);
            var structMember1Node = memberNode.Children.First();
            Helper.TestMemberContentNode(memberNode, structMember1Node, container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);
            var structMember2Node = memberNode.Children.Last();
            Helper.TestMemberContentNode(memberNode, structMember2Node, container.Struct, container.Struct.Value, nameof(SimpleStruct.Value), false);
        }
示例#47
0
        public void TestSimpleStructUpdate()
        {
            var nodeContainer = new NodeContainer();
            var container = new StructContainer { Struct = new SimpleStruct { Name = "Test", Value = 1 } };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var memberNode = containerNode.Children.First();
            memberNode.Content.Update(new SimpleStruct { Name = "Test2", Value = 2 });

            Assert.AreEqual("Test2", container.Struct.Name);
            Assert.AreEqual(2, container.Struct.Value);
            var structMember1Node = memberNode.Children.First();
            Helper.TestMemberContentNode(memberNode, structMember1Node, container.Struct, container.Struct.Name, nameof(SimpleStruct.Name), false);
            var structMember2Node = memberNode.Children.Last();
            Helper.TestMemberContentNode(memberNode, structMember2Node, container.Struct, container.Struct.Value, nameof(SimpleStruct.Value), false);
        }
示例#48
0
        /// <summary>
        /// Set the <see cref="TargetNode"/> and <see cref="TargetGuid"/> of the targeted object by retrieving it from or creating it to the given <see cref="NodeContainer"/>.
        /// </summary>
        /// <param name="nodeContainer">The <see cref="NodeContainer"/> used to retrieve or create the target node.</param>
        public IGraphNode SetTarget(NodeContainer nodeContainer)
        {
            if (nodeContainer == null) throw new ArgumentNullException("nodeContainer");
            IGraphNode targetNode = nodeContainer.GetOrCreateNode(ObjectValue);
            if (targetNode != null)
            {
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value)) throw new InvalidOperationException(@"The type of the retrieved node content does not match the type of this reference");

                if (TargetNode != null || TargetGuid != Guid.Empty)
                    throw new InvalidOperationException("TargetNode has already been set.");
                if (targetNode.Content.Value != null && !Type.IsInstanceOfType(targetNode.Content.Value))
                    throw new InvalidOperationException("TargetNode type does not match the reference type.");
                TargetNode = targetNode;
                TargetGuid = targetNode.Guid;
            }
            return targetNode;
        }
示例#49
0
        public void TestDoubleReferenceAtConstruction()
        {
            var doubleRef = new DoubleReferenceClass(new SimpleObject());
            var container = new NodeContainer();
            IGraphNode model = container.GetOrCreateNode(doubleRef);
            Assert.That(doubleRef.Object1, Is.EqualTo(doubleRef.Object2));
            Assert.That(model.GetChild("Object1").Content.Value, Is.EqualTo(doubleRef.Object1));
            Assert.That(model.GetChild("Object2").Content.Value, Is.EqualTo(doubleRef.Object2));

            Assert.That(model.GetChild("Object1").Content.IsReference, Is.True);
            Assert.That(model.GetChild("Object2").Content.IsReference, Is.True);

            var object1TargetNode = ((ObjectReference)model.GetChild("Object1").Content.Reference).TargetNode;
            var object2TargetNode = ((ObjectReference)model.GetChild("Object2").Content.Reference).TargetNode;
            Assert.That(object1TargetNode, Is.EqualTo(object2TargetNode));
            Assert.That(object1TargetNode.Content.Value, Is.EqualTo(doubleRef.Object1));
        }
示例#50
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);
        }
        public void TestConstruction()
        {
            var obj = new ClassWithDictionaries();
            var container = new NodeContainer();
            IGraphNode model = container.GetOrCreateNode(obj);
            Helper.PrintModelContainerContent(container, model);

            Assert.That(model.TryGetChild("StringIntDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.TryGetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic));
            Assert.That(model.TryGetChild("StringIntDic").Content.IsReference, Is.False);
            Assert.That(model.TryGetChild("StringClassDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.TryGetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic));
            Assert.That(model.TryGetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            var enumerator = obj.StringClassDic.GetEnumerator();
            foreach (var reference in model.TryGetChild("StringClassDic").Content.Reference.AsEnumerable)
            {
                enumerator.MoveNext();
                var keyValuePair = enumerator.Current;
                Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key));
                Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value));
            }
            //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 (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}
            //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 (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}

            //Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null);
            //Assert.That(container.Guids.Count(), Is.EqualTo(10));
        }
        public void TestStringMember()
        {
            var obj = new StringMember { Member = "aaa" };
            var container = new NodeContainer();

            // Construction
            var containerNode = (GraphNode)container.GetOrCreateNode(obj);
            Helper.TestNonCollectionObjectContentNode(containerNode, obj, 1);
            var memberNode = containerNode.Children.First();
            Helper.TestMemberContentNode(containerNode, memberNode, obj, obj.Member, nameof(StringMember.Member), false);

            // Update from object
            obj.Member = "bbb";
            Helper.TestMemberContentNode(containerNode, memberNode, obj, obj.Member, nameof(StringMember.Member), false);

            // Update from Quantum
            containerNode.Children.First().Content.Update("ccc");
            Helper.TestMemberContentNode(containerNode, memberNode, obj, obj.Member, nameof(StringMember.Member), false);
        }
示例#53
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);
        }
示例#54
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);
 }
示例#55
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);
 }
示例#56
0
 public void TestStructItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new NodeContainer();
     IGraphNode model = container.GetOrCreateNode(obj);
     Helper.PrintModelContainerContent(container, model);
     var objRef = ((ReferenceEnumerable)model.GetChild("SimpleStructList").Content.Reference).First();
     objRef.TargetNode.GetChild("SecondValue").Content.Update(32);
     Helper.PrintModelContainerContent(container, model);
     Assert.That(obj.SimpleStructList[0].SecondValue, Is.EqualTo(32));
     Helper.ConsistencyCheck(container, obj);
 }
示例#57
0
 public void TestPrimitiveItemUpdate()
 {
     var obj = new ClassWithLists();
     var container = new NodeContainer();
     IGraphNode model = container.GetOrCreateNode(obj);
     Console.WriteLine(model.PrintHierarchy());
     ((List<int>)model.GetChild("IntList").Content.Value)[1] = 42;
     ((List<int>)model.GetChild("IntList").Content.Value).Add(26);
     Assert.That(obj.IntList.Count, Is.EqualTo(4));
     Assert.That(obj.IntList[1], Is.EqualTo(42));
     Assert.That(obj.IntList[3], Is.EqualTo(26));
     Helper.ConsistencyCheck(container, obj);
 }
示例#58
0
 public void TestNullLists()
 {
     var obj = new ClassWithNullLists();
     var container = new NodeContainer();
     IGraphNode model = container.GetOrCreateNode(obj);
     Helper.PrintModelContainerContent(container, model);
     Helper.ConsistencyCheck(container, obj);
 }
示例#59
0
        public void TestSimpleContent()
        {
            var obj = new SimpleClass(1, "test");
            Assert.That(obj.FirstValue, Is.EqualTo(1));
            Assert.That(obj.SecondValue, Is.EqualTo("test"));

            var container = new NodeContainer();
            IGraphNode model = container.GetOrCreateNode(obj);
            Console.WriteLine(model.PrintHierarchy());
            model.GetChild("FirstValue").Content.Update(2);
            model.GetChild("SecondValue").Content.Update("new value");

            Assert.That(obj.FirstValue, Is.EqualTo(2));
            Assert.That(obj.SecondValue, Is.EqualTo("new value"));
        }
示例#60
0
        public void TestMultipleNestedStruct()
        {
            var obj = new SimpleClassWithNestedStruct(1.0, "test", 5.0, "inner value");
            Assert.That(obj.Struct.FirstValue, Is.EqualTo(1.0));
            Assert.That(obj.Struct.SecondValue, Is.EqualTo("test"));
            Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(5.0));
            Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("inner value"));

            var container = new NodeContainer();
            IGraphNode model = container.GetOrCreateNode(obj);
            Console.WriteLine(model.PrintHierarchy());
            var structNode = model.GetChild("Struct").Content.Reference.AsObject.TargetNode;
            structNode.GetChild("FirstValue").Content.Update(2.0);
            structNode.GetChild("SecondValue").Content.Update("new value");
            structNode = structNode.GetChild("InnerStruct").Content.Reference.AsObject.TargetNode;
            structNode.GetChild("FirstValue").Content.Update(7.0);
            structNode.GetChild("SecondValue").Content.Update("new inner value");

            Assert.That(obj.Struct.FirstValue, Is.EqualTo(2.0));
            Assert.That(obj.Struct.SecondValue, Is.EqualTo("new value"));
            Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(7.0));
            Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("new inner value"));
        }