Example #1
0
        public override bool RemoveChild(ITestObject testObject)
        {
            bool            removed        = false;
            TestObjectNurse childNurse     = testObject as TestObjectNurse;
            ITestObject     realTestObject = (childNurse == null) ? testObject : childNurse.TestObject;

            if (childNurse != null)
            {
                childNurse.TreeNode.Remove();

                AddToRecycleBin(childNurse);
                base.RemoveChild(childNurse);
            }

            foreach (ITestObject childTestObject in Children)
            {
                TestObjectNurse nurse = childTestObject as TestObjectNurse;
                if (nurse.TestObject == testObject)
                {
                    nurse.TreeNode.Remove();
                    base.RemoveChild(nurse);
                    removed = true;
                    break;
                }
            }

            if (realTestObject != null)
            {
                this.TestObject.RemoveChild(realTestObject);
                removed = true;
            }

            return(removed);
        }
Example #2
0
        public override ITestObject AddChild(ITestObject childObject)
        {
            if (childObject == null)
            {
                return(null);
            }

            TestObjectNurse childNurse = childObject as TestObjectNurse;

            if (childNurse == null)
            {
                //childObject is not nurse object
                childNurse = new TestObjectNurse(childObject);
            }

            ITestObject childTestObject = childNurse.TestObject;

            //connect 2 test objects
            if (childTestObject.Parent != _testObject && !this.IsRoot)
            {
                _testObject.AddChild(childTestObject);
            }

            //connect 2 nurses object
            base.AddChild(childNurse);

            if (Nodes != null)
            {
                Nodes.Add(childNurse.TreeNode);
            }
            return(childNurse);
        }
Example #3
0
        /// <summary>
        /// return the root nurse object
        /// </summary>
        /// <param name="treeView"></param>
        /// <param name="rootTestObject"></param>
        /// <returns>return root nurse, which does not contain test object</returns>
        internal static TestObjectNurse AddTree(TreeView treeView, ITestObject testObject)
        {
            TestObjectNurse rootNurse = TestObjectNurse.FromTree(treeView);

            TestObjectNurse nurse = rootNurse.AddDecendants(testObject);

            return(rootNurse);
        }
Example #4
0
        public static TestObjectNurse ConvertSubtree(UIATestObject topTestObject)
        {
            TestObjectNurse nurse = new TestObjectNurse(topTestObject);

            foreach (ITestObject childTestObject in topTestObject.Children)
            {
                nurse.AddDecendants(childTestObject);
            }
            return(nurse);
        }
Example #5
0
        /// <summary>
        /// Add testObjects subtree to the current nurse node.
        /// </summary>
        /// <param name="testObject"></param>
        /// <returns></returns>
        internal TestObjectNurse AddDecendants(ITestObject testObject)
        {
            TestObjectNurse nurse = this.AddChild(testObject) as TestObjectNurse;

            foreach (ITestObject childTestObject in testObject.Children)
            {
                nurse.AddDecendants(childTestObject);
            }
            return(nurse);
        }
Example #6
0
        private void AddToRecycleBin(TestObjectNurse childNurse)
        {
            TestObjectNurse nurse = childNurse;

            //find root nurse
            while (nurse.IsRoot == false && nurse.ParentNurse != null)
            {
                nurse = nurse.ParentNurse;
            }
            nurse.RecycleBin.Add(childNurse);
        }
Example #7
0
        public static TestObjectNurse FromTree(TreeView treeView)
        {
            TestObjectNurse rootNurse = treeView.Tag as TestObjectNurse;

            if (rootNurse == null)
            {
                rootNurse    = new TestObjectNurse(treeView);
                treeView.Tag = rootNurse; //store root nurse to
            }

            return(rootNurse);
        }
Example #8
0
        /// <summary>
        /// should be called with parameter inRecursion = false;
        /// </summary>
        /// <param name="nurse"></param>
        /// <param name="deleteFile"></param>
        /// <param name="inRecursion"></param>
        public static void CleanupDeletedItems(TestObjectNurse nurse, Action <string> deleteFile, bool inRecursion = false)
        {
            if (nurse == null)
            {
                return;
            }

            if (inRecursion == false)
            {
                while (nurse.IsRoot == false && nurse.ParentNurse != null)
                {
                    nurse = nurse.ParentNurse;
                }


                List <ITestObject> recycleBin = nurse.RecycleBin;
                foreach (TestObjectNurse nurseObject in recycleBin)
                {
                    if (!string.IsNullOrEmpty(nurseObject.ImageFile))
                    {
                        string imageFile = nurseObject.ImageFile;
                        deleteFile(nurseObject.ImageFile);
                    }
                    CleanupDeletedItems(nurseObject, deleteFile, true);
                }

                recycleBin.Clear();
            }
            else
            {
                foreach (TestObjectNurse nurseObject in nurse.Children)
                {
                    if (!string.IsNullOrEmpty(nurseObject.ImageFile))
                    {
                        deleteFile(nurseObject.ImageFile);
                    }
                    CleanupDeletedItems(nurseObject, deleteFile, true);
                }
            }
        }
Example #9
0
        public static TestObjectNurse FromTreeNode(TreeNode treeNode)
        {
            TestObjectNurse nurse = treeNode.Tag as TestObjectNurse;

            return(nurse);
        }