Esempio n. 1
0
        public void TestObjectNurse_Clear()
        {
            _childTestObject.AddChild(_grandChildTestObject);
            _parentTestObject.AddChild(_childTestObject);

            //root Nurse doesn't contain valid testObject, valid test objects start from its children
            TestObjectNurse rootNurse = TestObjectNurse.AddTree(_treeView, _parentTestObject);

            rootNurse.Clear();

            Assert.AreEqual(0, rootNurse.Children.Count);
            Assert.AreEqual(0, rootNurse.Nodes.Count);
        }
        /// <summary>
        /// return value indicate whether the load is successful
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="treeObjects"></param>
        /// <returns>return false if file cannot be found</returns>
        public static bool LoadRecentModelFile(string filePath, TreeView treeObjects)
        {
            try
            {
                TestObjectNurse rootNurse = TestObjectNurse.FromTree(treeObjects);
                rootNurse.Clear();

                LoadModelFile(filePath, rootNurse);

                //_treeObjects is used by the file watcher event
                _treeObjects = treeObjects;

                return(true);
            }
            catch (FileNotFoundException)
            {
                AppEnvironment.CurrentModelPath = null;
                return(false);
            }
        }
        static void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            Form form = _treeObjects.FindForm();

            form.Invoke(new Action(() =>
            {
                //"File changed outside the Manager, do you want to reload?"
                DialogResult result = MessageBox.Show(form, StringResources.LPSpy_ModelFileHandler_ReloadChangedFile
                                                      , StringResources.LPSPY_Confirm
                                                      , MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    //reload the file

                    TestObjectNurse rootNurse = TestObjectNurse.FromTree(_treeObjects);
                    rootNurse.Clear();

                    LoadModelFile(AppEnvironment.CurrentModelPath, rootNurse);
                }
            }));
        }
        /// <summary>
        /// populate tree view with the AppModel
        /// </summary>
        /// <param name="treeObjects"></param>
        /// <returns>indicate whether load successful</returns>
        public static bool DlgLoadModelFile(TreeView treeObjects)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = false;
            fileDialog.Title       = "Plese select an Application Model file";
            fileDialog.Filter      = "*.json|*.json";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                TestObjectNurse rootNurse = TestObjectNurse.FromTree(treeObjects);
                rootNurse.Clear();

                LoadModelFile(fileDialog.FileName, rootNurse);

                //_treeObjects is used by the file watcher event
                _treeObjects = treeObjects;

                return(true);
            }
            return(false);
        }
        public static bool DlgSaveAsModelFile(TestObjectNurse rootNurse)
        {
            SaveFileDialog savefile = new SaveFileDialog();

            savefile.Title  = "Save as";
            savefile.Filter = "*.json|*.json";

            if (savefile.ShowDialog() == DialogResult.OK)
            {
                SaveToModelFile(rootNurse);

                AppEnvironment.CurrentModelPath = savefile.FileName;

                rootNurse.Clear();

                LoadModelFile(AppEnvironment.CurrentModelPath, rootNurse);
                return(true);
            }

            return(false);
        }