コード例 #1
0
        //  [ExpectedException(typeof(AssertFailedException))]
        public void TreeContainsCorrectRecuriveTreeItems()
        {
            var first = new ExtendedClassWithRecursion();

            first.Name = "first";
            var second = new ExtendedClassWithRecursion();

            second.Name = "second";
            var third = new ClassWithRecursion();

            third.Name = "third";


            first.Subclass        = second;
            second.Subclass       = first;
            first.AnotherSubclass = third;
            third.Subclass        = second;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();
            Trace.WriteLine(string.Join("\n", sourceTree.RecursionObjectTreeItems.Select(item => item.Parent.Item)));

            Assert.AreEqual(2, sourceTree.RecursionObjectTreeItems.Count);
            Assert.IsTrue(sourceTree.RecursionObjectTreeItems.Any(item => item.Parent.Item == second));
            Assert.IsFalse(sourceTree.RecursionObjectTreeItems.Any(item => item.Parent.Item == first));
            Assert.IsFalse(sourceTree.RecursionObjectTreeItems.Any(item => item.Parent.Item == third));
        }
コード例 #2
0
        public void RecursiveItemsAreOnlyRecursiveItemsTest()
        {
            var first = new ExtendedClassWithRecursion();

            first.Name = "first";
            var second = new ExtendedClassWithRecursion();

            second.Name = "second";
            var third = new ClassWithRecursion();

            third.Name = "third";

            first.Subclass        = second;
            second.Subclass       = first;
            first.AnotherSubclass = third;
            third.Subclass        = second;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();

            foreach (var recursiveSourceTreeItem in sourceTree.RecursionObjectTreeItems)
            {
                //if (!ReferenceEquals(recursiveSourceTreeItem.Parent.Item, first))
                if (recursiveSourceTreeItem.Item != first)
                {
                    // Tree contains errors, if recursive tree items does not contain root as any of their child
                    Trace.TraceInformation(sourceTree.ToFormattedString());
                    throw new Exception("<<<< BUG IN OBJECT TREE>>>>>\n" +
                                        "In: \"" + recursiveSourceTreeItem.Item + "\"\n" +
                                        "Expected Item: \"" + first + "\"\n" +
                                        "Actual Items: \"" + recursiveSourceTreeItem.ToFormattedString());
                }
            }
        }
コード例 #3
0
        public void CreateTreeProperly()
        {
            var first = new ClassWithRecursion();

            first.Name = "First";
            var second = new ClassWithRecursion();

            second.Name = "Second";

            first.Subclass = second;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();
            Trace.WriteLine(sourceTree.ToFormattedString());
            Assert.IsNull(sourceTree.Parent);
            Assert.IsNotNull(sourceTree.Childs);

            Assert.IsTrue(IEnumerableExtensions.Any(sourceTree.Childs));
            Assert.AreEqual(2, sourceTree.Childs.Count);

            Assert.AreEqual(first, sourceTree.Item);
            Assert.IsTrue(sourceTree.Childs.Any(item => item.Item == second));

            foreach (var objectTreeItem in sourceTree.Childs)
            {
                Assert.AreEqual(sourceTree, objectTreeItem.Parent);
            }
        }
コード例 #4
0
        public void RedirectionWorks()
        {
            var class1 = new ClassWithRecursion("class1");
            var class2 = new ClassWithRecursion("class2");
            var class3 = new ClassWithRecursion("class3");
            var class4 = new ClassWithRecursion("class4");

            class1.Subclass = class2;
            class2.Subclass = class3;
            class3.Subclass = class1;

            Trace.WriteLine(new ObjectTreeItem(class1).CreateTree().ToFormattedString());

            object redirection = null;
            // ReSharper disable once ExpressionIsAlwaysNull
            var redirections = ObjectMerger.ObjectMerger.RedirectRecursions(class1, redirection);

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.AreEqual(redirection, class1.Subclass.Subclass.Subclass);

            redirection  = class4;
            redirections = ObjectMerger.ObjectMerger.RedirectRecursions(redirections, redirection);
            Assert.AreEqual(redirection, class1.Subclass.Subclass.Subclass);

            redirection  = class1;
            redirections = ObjectMerger.ObjectMerger.RedirectRecursions(redirections, redirection);
            Assert.AreEqual(redirection, class1.Subclass.Subclass.Subclass);
            Assert.AreEqual(class1, class3.Subclass);
        }
コード例 #5
0
        public void MergerHandlesSelfReferencing()
        {
            var class1 = new ClassWithRecursion();

            class1.Name     = "class1";
            class1.Subclass = class1;

            var class2 = new ClassWithRecursion();

            class2.Name     = "class2";
            class2.Subclass = class2;

            var mergedClass = ObjectMerger.ObjectMerger.MergeObjects(class1, class2);

            Trace.WriteLine("Merged Class");
            Trace.WriteLine(ClassWithRecursionToString(mergedClass));

            Trace.WriteLine("Class1 after merge");
            Trace.WriteLine(ClassWithRecursionToString(class1));

            Trace.WriteLine("Class2 after merge");
            Trace.WriteLine(ClassWithRecursionToString(class1));

            Assert.AreSame(class1, class1.Subclass);
            Assert.AreSame(class2, class2.Subclass);
            Assert.AreSame(mergedClass, mergedClass.Subclass);
        }
コード例 #6
0
        //  [ExpectedException(typeof(AssertFailedException))]
        public void SelfReferencingObjectIsProperlyCreated()
        {
            var first = new ClassWithRecursion();

            first.Name = "first";

            first.Subclass = first;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();
            Trace.WriteLine(sourceTree.ToFormattedString());

            Assert.AreEqual(1, sourceTree.RecursionObjectTreeItems.Count);
            Assert.IsTrue(sourceTree.RecursionObjectTreeItems.Any(item => item.Parent.Item == first));
            Assert.AreSame(sourceTree.Item, sourceTree.Childs.First(item => item.Item == sourceTree.Item).Item);
        }
コード例 #7
0
        //[Timeout(3000)]
        public void MergerHandlesRecursion()
        {
            var class1 = new ClassWithRecursion();

            class1.Name = "class1";
            var class2 = new ClassWithRecursion();

            class2.Name = "class2";
            var class3 = new ClassWithRecursion();

            class3.Name     = "class3";
            class1.Subclass = class2;
            class2.Subclass = class3;
            class3.Subclass = class1;

            var class4 = new ClassWithRecursion();

            class4.Name = "class4";
            var class5 = new ClassWithRecursion();

            class5.Name = "class5";
            var class6 = new ClassWithRecursion();

            class6.Name     = "class6";
            class4.Subclass = class4;
            class5.Subclass = class5;
            class6.Subclass = class6;

            Trace.WriteLine(ClassWithRecursionToString(class1));

            var mergedClass1 = ObjectMerger.ObjectMerger.MergeObjects(class4, class1);

            Trace.WriteLine(ClassWithRecursionToString(mergedClass1));

            var mergedClass2 = ObjectMerger.ObjectMerger.MergeObjects(class4, class1);

            Trace.WriteLine(ClassWithRecursionToString(mergedClass2));

            //                              class1      class2      class3  class1
            Assert.AreEqual(mergedClass1, mergedClass1.Subclass.Subclass.Subclass);
            Assert.AreEqual(mergedClass2, mergedClass2.Subclass.Subclass.Subclass);
        }
コード例 #8
0
        public void MergerThrowsIfRecursionNotResolvable()
        {
            var class3 = new ClassWithRecursion();
            var class2 = new ClassWithNotSettableRecursion(class3);
            var class1 = new ClassWithNotSettableRecursion(class2);

            class3.Subclass = class1;

            var class6 = new ClassWithRecursion();
            var class5 = new ClassWithNotSettableRecursion(class6);
            var class4 = new ClassWithNotSettableRecursion(class5);

            class6.Subclass = class6;


            var mergedClass1 = ObjectMerger.ObjectMerger.MergeObjects(class1, class4);
            var mergedClass2 = ObjectMerger.ObjectMerger.MergeObjects(class4, class1);

            //                              class1      class2      class3  class1
            Assert.AreEqual(mergedClass1, mergedClass1.Subclass.Subclass.Subclass);
            Assert.AreEqual(mergedClass2, mergedClass2.Subclass.Subclass.Subclass);
        }
コード例 #9
0
        //  [ExpectedException(typeof(AssertFailedException))]
        public void ToFormattedStringTest()
        {
            var first = new ExtendedClassWithRecursion();

            first.Name = "first";
            var second = new ExtendedClassWithRecursion();

            second.Name = "second";
            var third = new ClassWithRecursion();

            third.Name = "third";


            first.Subclass        = second;
            second.Subclass       = first;
            first.AnotherSubclass = third;
            third.Subclass        = second;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();
            Trace.WriteLine(sourceTree.ToFormattedString());
        }