Exemple #1
0
        /// <summary>
        /// updates  the test,deletes the old one and puts test instead
        /// </summary>
        /// <param name="test">the updated test</param>
        public void UpdateTest(Test test)
        {
            XElement testList = DS.DataSourceXML.TestList;//the xElement version of test
            var      found    = (from d in testList.Elements()
                                 where (d.Element("NumOfTest").Value == test.NumOfTest.ToString())
                                 select d).FirstOrDefault();//found = the test with this num of test, if there is no such a test: found = null

            if (found == null)
            {
                throw new Exception("There is no such a test");
            }

            DeleteTest(found.ToTest());                  //deletes the test
            DS.DataSourceXML.TestList.Add(test.ToXML()); //turns test to Xml and adds it to the file
            DS.DataSourceXML.SaveTests();                //saves the tests file
        }
Exemple #2
0
        /// <summary>
        /// adds a test
        /// </summary>
        /// <param name="test">test to add</param>
        public void AddTest(Test test)
        {
            var elements = DS.DataSourceXML.TesterList.Elements("Test");                                         //every test in the file

            var found = elements.FirstOrDefault(t => t.Element("NumOfTest").Value == test.NumOfTest.ToString()); //found = the test with this num of test, if there is no such a test: found = null

            if (found != null)
            {
                throw new Exception("The test is already exist");
            }
            else
            {
                test.NumOfTest = int.Parse(DS.DataSourceXML.Config.Value) + 1; //changes the config number in the test
                DS.DataSourceXML.Config.Value = test.NumOfTest.ToString();     //loads the new config number in the file
                DS.DataSourceXML.SaveConfig();                                 //saves the config changes
                DS.DataSourceXML.TestList.Add(test.ToXML());                   //turns test to Xml and adds it to the file
                DS.DataSourceXML.SaveTests();                                  //saves the tests file
            }
        }