コード例 #1
0
        public void TestChildSorting()
        {
            Activity alice   = new Activity("Alice");
            Activity bob     = new Activity("Bob");
            Activity charlie = new Activity("Charlie");
            Activity dingus  = new Activity("Dingus");
            Activity ethel   = new Activity("Ethel");
            Activity frank   = new Activity("Frank");
            Activity george  = new Activity("George");

            alice.AddChild(bob);
            alice.AddChild(charlie);
            alice.AddChild(dingus);

            bob.AddChild(ethel);
            bob.AddChild(frank);
            bob.AddChild(george);

            string s = string.Empty;

            bob.ForEachChild(delegate(ITreeNode <Activity> activity) { s += activity.Payload.Name; });
            Assert.IsTrue(s.Equals("EthelFrankGeorge"));

            s = string.Empty;
            bob.SortChildren(new Comparison <ITreeNode <Activity> >(ReverseSortTreeNodeActivities));
            bob.ForEachChild(delegate(ITreeNode <Activity> activity) { s += activity.Payload.Name; });
            Assert.IsTrue(s.Equals("GeorgeFrankEthel"));

            Console.WriteLine(s);
        }
コード例 #2
0
        public void TestTreeConstructionAndTraversalMethodsOverTreeOfNodeDerivedObjects()
        {
            Activity alice   = new Activity("Alice");
            Activity bob     = new Activity("Bob");
            Activity charlie = new Activity("Charlie");
            Activity dingus  = new Activity("Dingus");
            Activity ethel   = new Activity("Ethel");
            Activity frank   = new Activity("Frank");
            Activity george  = new Activity("George");

            alice.AddChild(bob);
            alice.AddChild(charlie);
            alice.AddChild(dingus);

            bob.AddChild(ethel);
            bob.AddChild(frank);
            bob.AddChild(george);

            StringBuilder sb = new StringBuilder();

            foreach (Activity a in alice.DescendantNodesBreadthFirst(true))
            {
                sb.AppendLine(a.Name);
            }
            foreach (Activity a in alice.DescendantNodesDepthFirst(true))
            {
                sb.AppendLine(a.Name);
            }
            foreach (Activity a in alice.DescendantsBreadthFirst(true))
            {
                sb.AppendLine(a.Name);
            }
            foreach (Activity a in alice.DescendantsDepthFirst(true))
            {
                sb.AppendLine(a.Name);
            }

            Console.WriteLine("This test manipulates a tree that holds elements that derive from TreeNode.");
            Console.WriteLine(sb.ToString());
            Console.WriteLine();
            Assert.IsTrue(StripCRLF(sb.ToString()).Equals(StripCRLF(REQUIRED_ITERATIONSTRING1)));
        }
コード例 #3
0
        public void AddChild(Activity child, object origin)
        {
            ThrowIfDisposed();
            ActivityUtilities.ValidateOrigin(origin, _activity);

            if (child != null)
            {
                _activity.AddChild(child);
                if (child.CacheId != _activity.CacheId)
                {
                    child.Origin = origin;
                }
            }
        }