/// <summary> /// Ask the user to introduce a valid ID of a student and validates if the student requested exists or not /// </summary> /// <returns>The student selected by the user or null in case of error or not valid</returns> private static Student GetStudent() { long id = -1; Console.WriteLine("Please enter the ID of the student that you want to edit (You can get the ID from the list of students in the option 4. Show students): "); string value = Console.ReadLine(); if (!string.IsNullOrEmpty(value)) { if (!long.TryParse(value, out id)) { ShowContinueMessage("You must enter a valid ID, please look for it and try again."); } } else { ShowContinueMessage("You must enter a valid ID, please look for it and try again."); } var student = StudentMapper.GetById(id); if (student == null) { ShowContinueMessage("We could not get any student with the ID provided, please look for a valid one on the list of students and try again."); } return(student); }
public void TestCreateUpdateDeleteStudents() { //DBConnection.ConnectionString = "Server=(local)\\sqlexpress;Database=Students;Trusted_Connection=True;"; //DBConnection.Type = DBType.SQLServer; DBConnection.Type = DBType.MySQL; DBConnection.ConnectionString = "Server=localhost;Port=3306;Uid=root;Pwd=system32;Database=Students;CheckParameters=false;"; var newStudent = new Student("Superman", "Male", StudentType.High); var result = StudentMapper.Insert(newStudent); Assert.AreEqual(true, result); var savedStudent = StudentMapper.GetById(newStudent.Id); Assert.AreEqual("Superman", savedStudent.Name); savedStudent.Name = "Clark Kent"; StudentMapper.Update(savedStudent); var updatedStudent = StudentMapper.GetById(savedStudent.Id); Assert.AreEqual("Clark Kent", updatedStudent.Name); StudentMapper.Hide(updatedStudent.Id); var hiddenStudent = StudentMapper.GetById(updatedStudent.Id); Assert.AreEqual(false, hiddenStudent.Enabled); StudentMapper.Delete(hiddenStudent.Id); var deleteStudent = StudentMapper.GetById(hiddenStudent.Id); Assert.AreEqual(null, deleteStudent); }