private static void addStudentsFromXML(IStudentController controller, String doc) { #region codes //String adviser = ""; //XmlNodeList nodeList = doc.GetElementsByTagName("stud_recordinfo"); //XmlNodeList primelist = doc.SelectNodes("easygradepro/class"); //foreach (XmlNode primenode in primelist) //{ // XmlNodeList periodList = primenode.SelectNodes("classrecord"); // foreach (XmlNode adviseNode in periodList) // { // adviser = adviseNode.ChildNodes[8].InnerText; // } //} //foreach (XmlNode node in nodeList) //{ // Student stud = new Student(); // stud.StudentID = node["stud_id"].InnerText; // stud.FirstName = node["stud_firstname"].InnerText; // stud.LastName = node["stud_lastname"].InnerText; // stud.Section = node.ChildNodes[8].InnerText; // stud.Level = node.ChildNodes[7].InnerText; // stud.Adviser = adviser; // controller.addOrUpdateStudent(stud); //} #endregion try { myReader = new StreamReader(doc); } catch (Exception er) { System.Windows.Forms.MessageBox.Show(er.Message, "Unable to run the File"); } try { String loadedString = null; while ((loadedString = myReader.ReadLine()) != null) { Student stud = new Student(); String[] studentDetails = loadedString.Split('\t'); stud.StudentID = studentDetails[0]; stud.FirstName = studentDetails[2]; stud.LastName = studentDetails[1]; if (studentDetails[5] != "" && studentDetails[6] != "" && studentDetails[7] != "") { stud.Level = studentDetails[5]; stud.Section = studentDetails[6]; stud.Adviser = studentDetails[7]; } controller.addOrUpdateStudent(stud); } myReader.Close(); } catch { } }
public void testAddNewStudent() { //contoller = new FrontController().getStudentController(); Student std = new Student(); std.StudentID = "123"; std.FirstName = "any"; int asd = contoller.getAllStudents().Count; contoller.addOrUpdateStudent(std); int sample2 = contoller.getAllStudents().Count; Assert.AreEqual(contoller.getStudent("123"), std); Assert.AreEqual(contoller.getStudent("123").FirstName, std.FirstName); Assert.AreNotEqual(contoller.getAllStudents().Count, asd); Assert.AreEqual(sample2, contoller.getAllStudents().Count); }