//Methods public Class GetClass(string className) { using (var db = new ChineseSchoolAdminSystemContext()) { return(db.Classes.Where(c => c.ClassName == className).FirstOrDefault()); } }
public void CheckAllInformationIsCorrectedWhenTeacherInformationIsEdited() { using (var db = new ChineseSchoolAdminSystemContext()) { var newTeacher = new Teacher { TeacherId = 5, FirstName = "Jo", LastName = "Wong", Email = "*****@*****.**" }; db.Teachers.Add(newTeacher); db.SaveChanges(); } _crudManager.EditTeacher(5, "Alice", "Cheung", "*****@*****.**"); using (var db = new ChineseSchoolAdminSystemContext()) { var selectedTeacher = db.Teachers.Where(t => t.TeacherId == 5).FirstOrDefault(); Thread.Sleep(2000); Assert.AreEqual("Alice", selectedTeacher.FirstName); Assert.AreEqual("Cheung", selectedTeacher.LastName); Assert.AreEqual("*****@*****.**", selectedTeacher.Email); } }
public List <Class> RetrieveAllClasses() { using (var db = new ChineseSchoolAdminSystemContext()) { return(db.Classes.ToList()); } }
public void NumberOfStudentsToDecreaseBy1WhenStudentIsDeleted() { using (var db = new ChineseSchoolAdminSystemContext()) { var newStudent = new Student { StudentId = 7, FirstName = "Lauren", LastName = "Pang", Age = 22, Allergies = "N/A", ParentName = "Emy", ParentContactNumber = "07123123123", ParentEmail = "*****@*****.**", ClassId = 6 }; db.Students.Add(newStudent); db.SaveChanges(); var numberOfStudentsBefore = db.Students.Count(); _crudManager.DeleteStudent(7); var numberOfStudentsAfter = db.Students.Count(); Assert.AreEqual(numberOfStudentsAfter, numberOfStudentsBefore - 1); } }
public List <Teacher> RetrieveAllTeachers() { using (var db = new ChineseSchoolAdminSystemContext()) { return(db.Teachers.ToList()); } }
public void DeleteTeacher(int teacherID) { using (var db = new ChineseSchoolAdminSystemContext()) { var selectedTeacher = db.Teachers.Where(s => s.TeacherId == teacherID).FirstOrDefault(); db.Teachers.Remove(selectedTeacher); db.SaveChanges(); } }
public void DeleteStudent(int studentID) { using (var db = new ChineseSchoolAdminSystemContext()) { var selectedStudent = db.Students.Where(s => s.StudentId == studentID).FirstOrDefault(); db.Students.Remove(selectedStudent); db.SaveChanges(); } }
public void NumberOfStudentsIncreasesBy1WhenNewStudentIsAdded() { using (var db = new ChineseSchoolAdminSystemContext()) { var numberOfStudentsBefore = db.Students.Count(); _crudManager.AddStudent(7, "Lauren", "Pang", 22, "N/A", "Emy Chung", "07123112233", "*****@*****.**", 6); var numberOfStudentsAfter = db.Students.Count(); Assert.AreEqual(numberOfStudentsAfter, numberOfStudentsBefore + 1); } }
public void NumberOfTeachersIncreasesBy1WhenNewTeacherIsAdded() { using (var db = new ChineseSchoolAdminSystemContext()) { var numberOfTeachersBefore = db.Teachers.Count(); _crudManager.AddTeacher(5, "Alice", "Cheung", "*****@*****.**"); var numberOfTeachersAfter = db.Teachers.Count(); Assert.AreEqual(numberOfTeachersAfter, numberOfTeachersBefore + 1); } }
public List <Student> RetrieveAllStudents(string className) { using (var db = new ChineseSchoolAdminSystemContext()) { return((from s in db.Students join c in db.Classes on s.ClassId equals c.ClassId where c.ClassName == className select s).ToList()); } }
public void EditTeacher(int teacherID, string firstName, string lastName, string email) { using (var db = new ChineseSchoolAdminSystemContext()) { SelectedTeacher = db.Teachers.Where(t => t.TeacherId == teacherID).FirstOrDefault(); SelectedTeacher.FirstName = firstName; SelectedTeacher.LastName = lastName; SelectedTeacher.Email = email; db.SaveChanges(); } }
public void AddTeacher(int teacherID, string firstName, string lastName, string email) { using (var db = new ChineseSchoolAdminSystemContext()) { var newTeacher = new Teacher { TeacherId = teacherID, FirstName = firstName, LastName = lastName, Email = email }; db.Teachers.Add(newTeacher); db.SaveChanges(); } }
public void CheckAllInformationIsCorrectedWhenNewTeacherIsAdded() { using (var db = new ChineseSchoolAdminSystemContext()) { _crudManager.AddTeacher(5, "Alice", "Cheung", "*****@*****.**"); var newTeacher = from t in db.Teachers where t.TeacherId == 5 select t; foreach (var s in newTeacher) { Assert.AreEqual("Alice", s.FirstName); Assert.AreEqual("Cheung", s.LastName); Assert.AreEqual("*****@*****.**", s.Email); } } }
public void Teardown() { using (var db = new ChineseSchoolAdminSystemContext()) { var selectedTeacher = from c in db.Teachers where c.TeacherId == 5 select c; foreach (var c in selectedTeacher) { db.Teachers.Remove(c); } db.SaveChanges(); } }
public void Teardown() { using (var db = new ChineseSchoolAdminSystemContext()) { var selectedStudent = from c in db.Students where c.StudentId == 7 select c; foreach (var c in selectedStudent) { db.Students.Remove(c); } db.SaveChanges(); } }
public void EditStudent(int studentID, string firstName, string lastName, int age, string allergies, string parentName, string parentContactNumber, string parentEmail, int classID) { using (var db = new ChineseSchoolAdminSystemContext()) { SelectedStudent = db.Students.Where(s => s.StudentId == studentID).FirstOrDefault(); SelectedStudent.FirstName = firstName; SelectedStudent.LastName = lastName; SelectedStudent.Age = age; SelectedStudent.Allergies = allergies; SelectedStudent.ParentName = parentName; SelectedStudent.ParentContactNumber = parentContactNumber; SelectedStudent.ParentEmail = parentEmail; SelectedStudent.ClassId = classID; db.SaveChanges(); } }
public void NumberOfTeachersDecreasesBy1WhenTeacherisDeleted() { using (var db = new ChineseSchoolAdminSystemContext()) { var newTeacher = new Teacher { TeacherId = 5, FirstName = "Jo", LastName = "Wong", Email = "*****@*****.**" }; db.Teachers.Add(newTeacher); db.SaveChanges(); var numberOfTeachersBefore = db.Teachers.Count(); _crudManager.DeleteTeacher(5); var numberOfTeachersAfter = db.Teachers.Count(); Assert.AreEqual(numberOfTeachersAfter, numberOfTeachersBefore - 1); } }
public void AddStudent(int studentID, string firstName, string lastName, int age, string allergies, string parentName, string parentContactNumber, string parentEmail, int classID) { using (var db = new ChineseSchoolAdminSystemContext()) { var newStudent = new Student { StudentId = studentID, FirstName = firstName, LastName = lastName, Age = age, Allergies = allergies, ParentName = parentName, ParentContactNumber = parentContactNumber, ParentEmail = parentEmail, ClassId = classID }; db.Students.Add(newStudent); db.SaveChanges(); } }
public void CheckAllInformationIsCorrectedWhenNewStudentIsAdded() { using (var db = new ChineseSchoolAdminSystemContext()) { _crudManager.AddStudent(7, "Lauren", "Pang", 22, "N/A", "Emy Chung", "07123112233", "*****@*****.**", 6); var newStudent = from s in db.Students where s.StudentId == 7 select s; foreach (var s in newStudent) { Assert.AreEqual("Lauren", s.FirstName); Assert.AreEqual("Pang", s.LastName); Assert.AreEqual(22, s.Age); Assert.AreEqual("N/A", s.Allergies); Assert.AreEqual("Emy Chung", s.ParentName); Assert.AreEqual("07123112233", s.ParentContactNumber); Assert.AreEqual("*****@*****.**", s.ParentEmail); Assert.AreEqual(6, s.ClassId); } } }
public void CheckAllInformationIsCorrectedWhenStudentInformationIsEdited() { using (var db = new ChineseSchoolAdminSystemContext()) { var newStudent = new Student { StudentId = 7, FirstName = "Olivia", LastName = "Pang", Age = 22, Allergies = "N/A", ParentName = "Emy", ParentContactNumber = "07123123123", ParentEmail = "*****@*****.**", ClassId = 6 }; db.Students.Add(newStudent); db.SaveChanges(); } _crudManager.EditStudent(7, "Lauren", "Chu", 20, "Nuts", "Tony Chu", "07789778899", "*****@*****.**", 5); using (var db = new ChineseSchoolAdminSystemContext()) { var selectedStudent = db.Students.Where(s => s.StudentId == 7).FirstOrDefault(); Thread.Sleep(2000); Assert.AreEqual("Lauren", selectedStudent.FirstName); Assert.AreEqual("Chu", selectedStudent.LastName); Assert.AreEqual(20, selectedStudent.Age); Assert.AreEqual("Nuts", selectedStudent.Allergies); Assert.AreEqual("Tony Chu", selectedStudent.ParentName); Assert.AreEqual("07789778899", selectedStudent.ParentContactNumber); Assert.AreEqual("*****@*****.**", selectedStudent.ParentEmail); Assert.AreEqual(5, selectedStudent.ClassId); } }