public void AddAssignmentGroup() { // Arrange: AddAssignmentGroupViewModel groupModel = new AddAssignmentGroupViewModel { GradedAssignments = 5, Name = "Another generic group", Weight = 10 }; int courseInstanceID = 1; // Act: AssignmentGroupDTO newGroup = _service.AddAssignmentGroup(courseInstanceID, groupModel); // Assert: Assert.AreEqual(groupModel.Name, newGroup.Name); Assert.AreEqual(groupModel.GradedAssignments, newGroup.GradedAssignments); Assert.AreEqual(groupModel.Weight, newGroup.Weight); }
/// <summary> /// Adds an assignment group to a course instance /// </summary> /// <param name="courseInstanceID"></param> /// <param name="groupData"></param> /// <returns></returns> public AssignmentGroupDTO AddAssignmentGroup(int courseInstanceID, AddAssignmentGroupViewModel groupData) { groupData.ValidateAssignmentGroupVM(); // Fetching the course (throws an error if not found) CourseInstance course = _courseInstances.GetCourseInstanceByID(courseInstanceID); // Fetching the assignments in the group List <AssignmentGroupDTO> courseAssignmentGroups = GetAssignmentGroups(courseInstanceID); // Adding the new group's weight to the list double totalWeight = courseAssignmentGroups.CalculateAssignmentGroupWeight() + groupData.Weight; // Illegal if new group weight goes above the maximum if (totalWeight > 100) { throw new CoursesAPIException(ErrorCodes.ILLEGAL_ASSIGNMENT_GROUP_WEIGHT); } // New group to add AssignmentGroup newGroup = new AssignmentGroup { CourseInstanceID = courseInstanceID, Name = groupData.Name, GradedAssignments = groupData.GradedAssignments, Weight = groupData.Weight }; _assignmentGroups.Add(newGroup); _uow.Save(); AssignmentGroupDTO groupDTO = newGroup.GetAssignmentGroupDTO(); return(groupDTO); }
/// <summary> /// Validates an assignment group /// </summary> /// <param name="groupModel"></param> public static void ValidateAssignmentGroupVM(this AddAssignmentGroupViewModel groupModel) { // Validing the model APIValidation.Validate(groupModel); }
public AssignmentGroupDTO AddAssigmentGroup(int courseInstanceID, AddAssignmentGroupViewModel model) { APIValidation.Validate(model); return(_assignmentService.AddAssignmentGroup(courseInstanceID, model)); }