Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void TestUseExistingNodesAsReference()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new TestObject {
                Name = "Test1"
            };
            var instance2 = new TestObject {
                Name = "Test2"
            };
            var container = new MultipleObjectContainer {
                Instances = { instance1, instance2 }
            };
            var instance1Node = nodeContainer.GetOrCreateNode(instance1);
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var instance2Node = nodeContainer.GetOrCreateNode(instance2);

            Assert.AreEqual(1, containerNode.Children.Count);
            var memberNode = containerNode.Children.First();

            Assert.AreEqual(true, memberNode.Content.IsReference);
            var reference = memberNode.Content.Reference.AsEnumerable;

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

            Assert.AreEqual(instance1Node, reference1.TargetNode);
            Assert.AreEqual(instance2Node, reference2.TargetNode);
        }
Exemplo n.º 3
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(new Index(0)));
            Assert.AreEqual(instance2, memberNode.Content.Retrieve(new Index(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);
        }
Exemplo n.º 4
0
        public void TestUseExistingNodesAsReference()
        {
            var nodeContainer = new NodeContainer();
            var instance1     = new TestObject {
                Name = "Test1"
            };
            var instance2 = new TestObject {
                Name = "Test2"
            };
            var container = new MultipleObjectContainer {
                Instances = { instance1, instance2 }
            };
            var instance1Node = nodeContainer.GetOrCreateNode(instance1);
            var containerNode = nodeContainer.GetOrCreateNode(container);
            var instance2Node = nodeContainer.GetOrCreateNode(instance2);

            Assert.Equal(1, containerNode.Members.Count);
            var memberNode = containerNode.Members.First();

            Assert.True(memberNode.IsReference);
            var reference = memberNode.Target.ItemReferences;

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

            Assert.Equal(instance1Node, reference1.TargetNode);
            Assert.Equal(instance2Node, reference2.TargetNode);
        }
Exemplo n.º 5
0
        public void TestEnumerableReferenceUpdate()
        {
            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);
            var memberNode    = containerNode.Children.First();
            var reference     = memberNode.Content.Reference.AsEnumerable;
            var reference1    = reference.First();
            var reference2    = reference.Last();

            // Update item 0 to a new instance and item 1 to null
            var newInstance = new TestObject {
                Name = "Test3"
            };

            memberNode.Content.Update(newInstance, new Index(0));
            memberNode.Content.Update(null, new Index(1));
            Assert.AreEqual(container.Instances, memberNode.Content.Retrieve());
            Assert.AreEqual(newInstance, memberNode.Content.Retrieve(new Index(0)));
            Assert.AreEqual(null, memberNode.Content.Retrieve(new Index(1)));
            Helper.TestReferenceEnumerable(memberNode.Content.Reference, container.Instances);

            var newReference = memberNode.Content.Reference.AsEnumerable;

            Assert.AreEqual(reference, newReference);
            Assert.AreEqual(2, newReference.Count);
            var newReference1 = newReference.First();
            var newReference2 = newReference.Last();

            Assert.AreNotEqual(reference1, newReference1);
            Assert.AreNotEqual(reference1.TargetGuid, newReference1.TargetGuid);
            Assert.AreNotEqual(reference1.TargetNode, newReference1.TargetNode);
            Assert.AreNotEqual(reference1.ObjectValue, newReference1.ObjectValue);
            Assert.AreNotEqual(reference2, newReference2);
            Assert.AreNotEqual(reference2.TargetGuid, newReference2.TargetGuid);
            Assert.AreNotEqual(reference2.TargetNode, newReference2.TargetNode);
            Assert.AreNotEqual(reference2.ObjectValue, newReference2.ObjectValue);
        }
Exemplo n.º 6
0
        public void TestNullEnumerableReference()
        {
            var nodeContainer = new NodeContainer();
            var container     = new MultipleObjectContainer {
                Instances = { null, null }
            };
            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(null, memberNode.Content.Retrieve(new Index(0)));
            Assert.AreEqual(null, memberNode.Content.Retrieve(new Index(1)));
        }
Exemplo n.º 7
0
        public void TestNullEnumerableReference()
        {
            var nodeContainer = new NodeContainer();
            var container     = new MultipleObjectContainer {
                Instances = { null, null }
            };
            var containerNode = nodeContainer.GetOrCreateNode(container);

            Helper.TestNonCollectionObjectNode(containerNode, container, 1);

            var memberNode = containerNode.Members.First();

            Helper.TestMemberNode(containerNode, memberNode, container, container.Instances, nameof(MultipleObjectContainer.Instances), true);
            Helper.TestReferenceEnumerable(memberNode.Target.ItemReferences, container.Instances);

            Assert.Equal(container.Instances, memberNode.Retrieve());
            Assert.Null(memberNode.Retrieve(new NodeIndex(0)));
            Assert.Null(memberNode.Retrieve(new NodeIndex(1)));
        }
Exemplo n.º 8
0
 public void TestUseExistingNodesAsReference()
 {
     var nodeContainer = new NodeContainer();
     var instance1 = new TestObject { Name = "Test1" };
     var instance2 = new TestObject { Name = "Test2" };
     var container = new MultipleObjectContainer { Instances = { instance1, instance2 } };
     var instance1Node = nodeContainer.GetOrCreateNode(instance1);
     var containerNode = nodeContainer.GetOrCreateNode(container);
     var instance2Node = nodeContainer.GetOrCreateNode(instance2);
     Assert.AreEqual(1, containerNode.Children.Count);
     var memberNode = containerNode.Children.First();
     Assert.AreEqual(true, memberNode.Content.IsReference);
     var reference = memberNode.Content.Reference.AsEnumerable;
     Assert.AreEqual(2, reference.Indices.Count);
     var reference1 = reference.First();
     var reference2 = reference.Last();
     Assert.AreEqual(instance1Node, reference1.TargetNode);
     Assert.AreEqual(instance2Node, reference2.TargetNode);
 }
Exemplo n.º 9
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.TestNonCollectionObjectContentNode(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);
        }
Exemplo n.º 10
0
        public void TestEnumerableReferenceUpdate()
        {
            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);
            var memberNode = containerNode.Children.First();
            var reference = memberNode.Content.Reference.AsEnumerable;
            var reference1 = reference.First();
            var reference2 = reference.Last();

            // Update item 0 to a new instance and item 1 to null
            var newInstance = new TestObject { Name = "Test3" };
            memberNode.Content.Update(newInstance, new Index(0));
            memberNode.Content.Update(null, new Index(1));
            Assert.AreEqual(container.Instances, memberNode.Content.Retrieve());
            Assert.AreEqual(newInstance, memberNode.Content.Retrieve(new Index(0)));
            Assert.AreEqual(null, memberNode.Content.Retrieve(new Index(1)));
            Helper.TestReferenceEnumerable(memberNode.Content.Reference, container.Instances);

            var newReference = memberNode.Content.Reference.AsEnumerable;
            Assert.AreEqual(reference, newReference);
            Assert.AreEqual(2, newReference.Count);
            var newReference1 = newReference.First();
            var newReference2 = newReference.Last();

            Assert.AreNotEqual(reference1, newReference1);
            Assert.AreNotEqual(reference1.TargetGuid, newReference1.TargetGuid);
            Assert.AreNotEqual(reference1.TargetNode, newReference1.TargetNode);
            Assert.AreNotEqual(reference1.ObjectValue, newReference1.ObjectValue);
            Assert.AreNotEqual(reference2, newReference2);
            Assert.AreNotEqual(reference2.TargetGuid, newReference2.TargetGuid);
            Assert.AreNotEqual(reference2.TargetNode, newReference2.TargetNode);
            Assert.AreNotEqual(reference2.ObjectValue, newReference2.ObjectValue);
        }
Exemplo n.º 11
0
        public void TestNullEnumerableReference()
        {
            var nodeContainer = new NodeContainer();
            var container = new MultipleObjectContainer { Instances = { null, null } };
            var containerNode = nodeContainer.GetOrCreateNode(container);
            Helper.TestNonCollectionObjectContentNode(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(null, memberNode.Content.Retrieve(new Index(0)));
            Assert.AreEqual(null, memberNode.Content.Retrieve(new Index(1)));
        }
Exemplo n.º 12
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.TestNonCollectionObjectContentNode(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(new Index(0)));
            Assert.AreEqual(instance2, memberNode.Content.Retrieve(new Index(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);
        }