public async Task CheckAssignmentAddingAndRetriving() { Assignment testAssignment = new Assignment(); //testAssignment.AssignmentID = 999; testAssignment.CourseID = 1; testAssignment.DueDate = DateTime.Now; testAssignment.AssignmentTitle = "testing"; testAssignment.AssignmentDescription = "testDescription"; testAssignment.AssignmentType = "test"; testAssignment.TotalPossible = 10; var returnedAssignment = await _assignmentService.AddNewAssignment(testAssignment); List <Assignment> assignmentList = (_assignmentService.GetAssigmentByCourseID(1)); Assignment checkAssignment = null; for (int i = 0; i < assignmentList.Count; i++) { if (assignmentList[i].AssignmentID == returnedAssignment.AssignmentID) { checkAssignment = assignmentList[i]; break; } } Assert.IsTrue(testAssignment.CourseID == checkAssignment.CourseID && testAssignment.AssignmentID == checkAssignment.AssignmentID && testAssignment.DueDate == checkAssignment.DueDate && testAssignment.AssignmentTitle == checkAssignment.AssignmentTitle && testAssignment.AssignmentDescription == checkAssignment.AssignmentDescription && testAssignment.AssignmentType == checkAssignment.AssignmentType && testAssignment.TotalPossible == checkAssignment.TotalPossible); _dbContext.Remove(testAssignment); await _dbContext.SaveChangesAsync(); }
//Deletes course associated with the course ID throws exception if there is no course with that ID. public async Task <int> DeleteCourse(int courseToDeleteID) { Course courseToDelete = (from c in _classDbContext.Courses where c.CourseID == courseToDeleteID select c).FirstOrDefault <Course>(); if (courseToDelete == null) { throw new Exception("Course does not exists."); } //Get all the assignments associated with the course List <Assignment> assignmentsToDelete = (from a in _classDbContext.Assignments where a.CourseID == courseToDeleteID select a).ToList <Assignment>(); //Get all grades associated with the assignments from the course foreach (Assignment i in assignmentsToDelete) { IEnumerable <Grade> tempGrades = (from g in _classDbContext.Grades where g.AssignmentID == i.AssignmentID select g).ToList <Grade>(); //Delete the found grades if (tempGrades != null) { _classDbContext.RemoveRange(tempGrades); } tempGrades = null; } if (assignmentsToDelete != null) { _classDbContext.RemoveRange(assignmentsToDelete); } //Delete all Announcements associated with course IEnumerable <Announcement> announcementsToDelete = (from a in _classDbContext.Announcements where a.CourseID == courseToDeleteID select a).ToList <Announcement>(); if (announcementsToDelete != null) { _classDbContext.RemoveRange(announcementsToDelete); } //Delete all userCourses associated with course IEnumerable <UserCourse> userCoursesToDelete = (from uc in _classDbContext.UserCourses where uc.CourseID == courseToDeleteID select uc).ToList <UserCourse>(); if (userCoursesToDelete != null) { _classDbContext.RemoveRange(userCoursesToDelete); } _classDbContext.Remove(courseToDelete); await _classDbContext.SaveChangesAsync(); return(courseToDeleteID); }