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(); }
public async Task <IActionResult> AddAssignment([FromBody] Assignment newAssignment) { try { Announcement announcement = new Announcement { AnnouncementID = 0, Body = "New Assignment!", CourseID = newAssignment.CourseID, DateCreated = DateTime.Now, Title = newAssignment.AssignmentTitle }; announcement = await _announcementService.CreateAnnouncement(announcement); return(Ok(await _assignmentService.AddNewAssignment(newAssignment))); } catch (Exception e) { return(BadRequest("Error inserting Course")); } }