public IHttpActionResult PostGradingScheme(GradingSchemeDetailDTO schemeDTO) { User authorizedUser = new Authorize().GetAuthorizedUser(Request.Headers.GetCookies("user").FirstOrDefault()); if (authorizedUser == null || authorizedUser.GetTeacher() == null) { return(Unauthorized()); } Teacher teacher = authorizedUser.GetTeacher(); Course course = db.Courses.Find(schemeDTO.NewCourseId); if (!ModelState.IsValid || !schemeDTO.Validate(teacher) || course == null) { return(BadRequest()); } GradingScheme scheme = schemeDTO.Create(); db.GradingSchemes.Add(scheme); string error = db.Update(scheme, Added); if (error != null) { return(BadRequest(error)); } return(Redirect("https://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port + "/Courses/" + course.Id)); }
[Test] // Create GradeRanges array where the values are in ascending order public void GradingScheme_PassGradeRangesArrayInAscendingOrder() { int[] gradeRanges = { 10, 30, 40, 41, 90 }; string[] gradeSymbols = new string[5]; double[] gradePointValues = new double[5]; GradingScheme scheme = new GradingScheme(gradeRanges, gradeSymbols, gradePointValues); }
public void GradingScheme_PassArraysOfDifferentLengths2_Exception() { int[] gradeRanges = new int[5]; string[] gradeSymbols = new string[4]; double[] gradePointValues = new double[4]; GradingScheme scheme = new GradingScheme(gradeRanges, gradeSymbols, gradePointValues); }
[Test] // do boundary value analysis for all the grade ranges // using a grade range supplied by user public void CalculateGrade_UseUserDefinedValues_NoException() { int[] gradeRanges = { 49, 69, 89, 100 }; string[] gradeSymbols = { "F", "C", "B", "A" }; double[] gradePointValues = { 0, 1.0, 2.0, 3.0 }; GradingScheme myscheme = new GradingScheme(gradeRanges, gradeSymbols, gradePointValues); UnitGrade ugrade; ugrade = new UnitGrade("unit", "12345", 49); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("F", ugrade.gradeSymbol); Assert.AreEqual(0.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 50); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("C", ugrade.gradeSymbol); Assert.AreEqual(1.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 69); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("C", ugrade.gradeSymbol); Assert.AreEqual(1.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 70); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("B", ugrade.gradeSymbol); Assert.AreEqual(2.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 89); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("B", ugrade.gradeSymbol); Assert.AreEqual(2.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 90); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("A", ugrade.gradeSymbol); Assert.AreEqual(3.0, ugrade.gradePoint); ugrade = new UnitGrade("unit", "12345", 100); ugrade.gradingScheme = myscheme; ugrade.CalculateGrade(); Assert.AreEqual("A", ugrade.gradeSymbol); Assert.AreEqual(3.0, ugrade.gradePoint); }
public IHttpActionResult GetGradingScheme(int id) { User authorizedUser = new Authorize().GetAuthorizedUser(Request.Headers.GetCookies("user").FirstOrDefault()); if (authorizedUser == null || authorizedUser.GetTeacher() == null) { return(Unauthorized()); } GradingScheme scheme = db.GradingSchemes.Find(id); if (scheme == null) { return(NotFound()); } return(Ok(new GradingSchemeDetailDTO(scheme))); }
public IHttpActionResult DeleteGradingScheme(int id) { Authorize auth = new Authorize(); User authorizedUser = auth.GetAuthorizedUser(Request.Headers.GetCookies("user").FirstOrDefault()); if (authorizedUser == null || authorizedUser.GetTeacher() == null) { return(Unauthorized()); } GradingScheme scheme = db.GradingSchemes.Find(id); if (scheme == null) { return(NotFound()); } bool authorized = scheme.Courses.Count == 0; if (!authorized) { foreach (Course course in scheme.Courses) { if ("Teacher".Equals(auth.GetAccessRole(authorizedUser, course))) { authorized = true; break; } } } if (!authorized) { return(Unauthorized()); } ICollection <object> entities = new HashSet <object>(); foreach (Grade grade in scheme.Grades) { entities.Add(grade); } entities.Add(scheme); string error = db.UpdateAll(entities, Deleted); if (error != null) { return(BadRequest(error)); } return(StatusCode(HttpStatusCode.NoContent)); }
private static void InitializeGradingSchemes() { var gradingScheme = new GradingScheme() { Name = "French" }; db.GradingSchemes.Add(gradingScheme); db.SaveChanges(); for (double i = 0; i <= 20; ++i) { db.Grades.Add(new Grade() { GradingSchemeId = 1, MinPercentage = i / 20, Name = i.ToString() }); db.SaveChanges(); } gradingScheme = new GradingScheme() { Name = "American" }; db.GradingSchemes.Add(gradingScheme); db.SaveChanges(); string[] grades = new string[] { "D", "C", "B", "A" }; for (double i = 0; i < 4; ++i) { db.Grades.Add(new Grade() { GradingSchemeId = 2, MinPercentage = i / 4, Name = grades[(int)i] }); db.SaveChanges(); } }
public void GradingScheme_ArgumentsNull_Exception() { GradingScheme scheme = new GradingScheme(null, null, null); }
public void GradingScheme_NoArgumentConstructor() { GradingScheme scheme = new GradingScheme(); }