public void GetAllTeachersClassTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); Console.WriteLine("Database created"); List <User> teachers = db.GetAllUsers(UserTypes.Teacher); Console.WriteLine("retrieved all students"); Console.WriteLine("total users Count: " + teachers.Count); foreach (User teacher in teachers) { Console.WriteLine("teacher name: " + teacher.Name); List <Class> classes = db.GetTeachersClasses(teacher); Console.WriteLine("Retrieved all classes for teacher"); Console.WriteLine("Total class count: " + classes.Count); foreach (Class iClass in classes) { Assert.IsTrue(iClass.Teacher.rowId == teacher.rowId); Console.WriteLine("Class does not contain the teacher"); } } }
public void GetAllDepartmentHeadsClassTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); Console.WriteLine("Database created"); List <User> dps = db.GetAllUsers(UserTypes.DepartmentHead); Console.WriteLine("retrieved all DepartmentHead"); Console.WriteLine("total users Count: " + dps.Count); foreach (User dp in dps) { Console.WriteLine("departmentHead name: " + dp.Name); List <Class> classes = db.GetDepartmentClasses(dp); Console.WriteLine("Retrieved all classes for DepartmentHead"); Console.WriteLine("Total class count: " + classes.Count); foreach (Class iClass in classes) { Assert.IsTrue(iClass.DepartmentHead.rowId == dp.rowId); Console.WriteLine("Class does not contain the DepartmentHead"); } } }
public void EnsureDepartmentHeadTest() { List <User> users = null; Assert.DoesNotThrow(delegate { QuizardDatabase db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } Console.WriteLine("database created"); users = db.GetAllUsers(UserTypes.DepartmentHead); Console.WriteLine("Query successful"); Console.WriteLine("all DepartmentHead count = " + users.Count); }); Assert.IsNotNull(users); foreach (User user in users) { Console.WriteLine("Testing " + user.Name); Assert.AreEqual(UserTypes.DepartmentHead, user.Role); Console.WriteLine(user.Name + " is a DepartmentHead"); } }
public void loginFailTest() { List <User> users = null; QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } Console.WriteLine("database created"); users = db.GetAllUsers(); Console.WriteLine("Query successful"); Console.WriteLine("all users count = " + users.Count); }); foreach (User user in users) { Console.WriteLine("User: "******"email: " + user.Email); Console.WriteLine("password: INVALID"); User logUser = db.loginCheck(user.Email, "INVALID"); Console.WriteLine("query successful"); Assert.IsNull(logUser); Console.WriteLine("--------Login Failed as expected!----------"); } }
public void NegativeStudentsClassTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); Console.WriteLine("Database created"); List <User> students = db.GetAllUsers(); Console.WriteLine("retrieved all students"); Console.WriteLine("total users Count: " + students.Count); foreach (User student in students) { if (student.Role != UserTypes.Student) { Console.WriteLine("student name: " + student.Name); List <Class> classes = db.GetStudentsClasses(student); Console.WriteLine("Retrieved all classes for student"); Console.WriteLine("Total class count: " + classes.Count); foreach (Class iClass in classes) { Console.WriteLine("Testing class: " + iClass.Name); bool found = false; foreach (User cStud in iClass.Students) { if (cStud.rowId == student.rowId) { found = true; } } Assert.IsFalse(found); Console.WriteLine("Class does not contain the student"); } } } }
public void GetAllSTAslassTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); Console.WriteLine("Database created"); List <User> tas = db.GetAllUsers(UserTypes.TeachingAssistant); Console.WriteLine("retrieved all TeachingAssistant"); Console.WriteLine("total TeachingAssistant Count: " + tas.Count); foreach (User ta in tas) { Console.WriteLine("TeachingAssistant name: " + ta.Name); List <Class> classes = db.GetTAClasses(ta); Console.WriteLine("Retrieved all classes for TeachingAssistant"); Console.WriteLine("Total class count: " + classes.Count); foreach (Class iClass in classes) { Console.WriteLine("Testing class: " + iClass.Name); bool found = false; foreach (User cStud in iClass.AssistantTeachers) { if (cStud.rowId == ta.rowId) { found = true; } } Assert.IsTrue(found); Console.WriteLine("Class does contain the TeachingAssistant"); } } }
public void GetALlUsersTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); Console.WriteLine("Database created"); List <User> allCUsers = db.GetAllUsers(); Console.WriteLine("Query successful"); Console.WriteLine("users count = " + allCUsers.Count); //Assert.DoesNotThrow(delegate //{ using (SQLiteConnection database = new SQLiteConnection("Data Source = quizard.db")) { database.Open(); using (SQLiteCommand command = database.CreateCommand()) { command.CommandText = "SELECT COUNT(*) FROM users;"; Console.WriteLine("SELECT COUNT(*) FROM users;"); Assert.AreEqual(command.ExecuteScalar(), allCUsers.Count); Console.WriteLine("counts are equal!"); } } //}); }
public void userAddAndRemoveTest() { QuizardDatabase db = null; Assert.DoesNotThrow(delegate { db = new QuizardDatabase(); db.Open(); if (!File.Exists("quizard.db")) { int x = db.buildDB(); Assert.AreEqual(x, 0); } }); long allUsersCount = 0; using (SQLiteConnection database = new SQLiteConnection("Data Source = quizard.db")) { database.Open(); using (SQLiteCommand command = database.CreateCommand()) { command.CommandText = "SELECT COUNT(*) FROM users;"; Console.WriteLine("SELECT COUNT(*) FROM users;"); allUsersCount = (long)command.ExecuteScalar(); Console.WriteLine("current user count: " + allUsersCount); } } Console.WriteLine("Database opened correctly"); Console.WriteLine("name: testName"); Console.WriteLine("email: testEmail"); Console.WriteLine("password: testPassword"); Console.WriteLine("role: " + UserTypes.Teacher.ToString()); int result = db.CreateUser("testName", "testEmail", "testPassword", UserTypes.Teacher.ToString()); Assert.AreEqual(result, 1); using (SQLiteConnection database = new SQLiteConnection("Data Source = quizard.db")) { database.Open(); using (SQLiteCommand command = database.CreateCommand()) { command.CommandText = "SELECT COUNT(*) FROM users;"; Console.WriteLine("SELECT COUNT(*) FROM users;"); long other = (long)command.ExecuteScalar(); Assert.Greater(other, allUsersCount); allUsersCount = other; Console.WriteLine("current user count: " + allUsersCount); } } Console.WriteLine("The user was inserted correctly"); List <User> toRemove = db.GetAllUsers(UserTypes.Teacher); foreach (User user in toRemove) { if (user.Name == "testName") { db.RemoveUser(user); Console.WriteLine("deleted user"); } } using (SQLiteConnection database = new SQLiteConnection("Data Source = quizard.db")) { database.Open(); using (SQLiteCommand command = database.CreateCommand()) { command.CommandText = "SELECT COUNT(*) FROM users;"; Console.WriteLine("SELECT COUNT(*) FROM users;"); long other = (long)command.ExecuteScalar(); Assert.Less(other, allUsersCount); allUsersCount = other; Console.WriteLine("current user count: " + allUsersCount); } } Console.WriteLine("The user was deleted properly correctly"); }