public void TestStudentCourse() { var st = new Student("1234", "Anna", "Nova"); var sc = new StudentCourseEvaluation(st); Assert.AreEqual(st, sc.Student); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); var eval = new CourseEvaluation(); sc = new StudentCourseEvaluation(st, eval); Assert.AreEqual(st, sc.Student); Assert.AreEqual(eval, sc.Evaluation); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); sc = new StudentCourseEvaluation("1234", "Anna", "Nova"); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); sc = new StudentCourseEvaluation("1234", "Anna", "Nova", eval); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); var evalDef = new EvaluationDefinitionCollection(); sc = new StudentCourseEvaluation(st, evalDef); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); sc = new StudentCourseEvaluation("1234", "Anna", "Nova", evalDef); Assert.AreEqual("1234\tNOVA Anna\t?b", sc.ToString()); }
public void TestConstructionWithEmptyDefinition() { var eval = new CourseEvaluation(); Assert.AreEqual(null, eval.GetTotalPoints()); Assert.AreEqual(null, eval.GetTotalPointsReason()); }
public IActionResult Update(long id, CourseEvaluation request) { RequiredFields model = new RequiredFields(); model.CourseEvaluation = request; object validateFields = _validationService.ValidateRequest("Course Evaluation", model); if (JsonConvert.SerializeObject(validateFields).Length > 2) { return(BadRequest(validateFields)); } try { var response = _courseEvaluationRepository.Update(id, request); if (response == 0) { return(NotFound(_NotFound)); } else if (response == 1) { return(BadRequest(_Duplicate)); } else { return(Ok(new GenericResult { Response = true, Message = request.title + " has been successfully updated" })); } } catch (Exception e) { return(BadRequest(e)); } }
public IActionResult Store(CourseEvaluation request) { RequiredFields model = new RequiredFields(); model.CourseEvaluation = request; object validateFields = _validationService.ValidateRequest("Course Evaluation", model); if (JsonConvert.SerializeObject(validateFields).Length > 2) { return(BadRequest(validateFields)); } try { //return Ok(request); var response = _courseEvaluationRepository.Add(request); if (response == true) { return(Ok(new GenericResult { Response = response, Message = request.title + " has been successfully added" })); } else { return(BadRequest(_Duplicate)); } } catch (Exception e) { return(BadRequest(e)); } }
public bool DuplicateByCourseId(long id, long newCourseId) { var courseEvaluation = GetByCourseId(id); foreach (CourseEvaluation ce in courseEvaluation) { CourseEvaluation ceModel = new CourseEvaluation(); ceModel.courseId = newCourseId; ceModel.title = ce.title; ceModel.userGroupId = ce.userGroupId; ceModel.evaluationTypeId = ce.evaluationTypeId; ceModel.evaluationActionId = ce.evaluationActionId; ceModel.isRequired = ce.isRequired; ceModel.minValue = ce.minValue; ceModel.maxValue = ce.maxValue; ceModel.createdAt = DateTime.Now; ceModel.updatedAt = DateTime.Now; _context.CourseEvaluation.Add(ceModel); _context.SaveChanges(); foreach (CourseEvaluationValues cev in ce.CourseEvaluationValues) { CourseEvaluationValues cevModel = new CourseEvaluationValues(); cevModel.courseEvaluationId = ceModel.id; cevModel.name = cev.name; cevModel.createdAt = DateTime.Now; cevModel.updatedAt = DateTime.Now; _context.CourseEvaluationValues.Add(cevModel); _context.SaveChanges(); } } return(true); }
public void TestConstruction() { var eval = new CourseEvaluation(this.Definition); Assert.AreEqual(this.Definition, eval.EvaluationDefinitions); Assert.AreEqual(this.Definition.Count, eval.Evaluations.Count); for (int i = 0; i < this.Definition.Count; i++) { Assert.AreEqual(this.Definition[i], eval.Evaluations[i].Definition); } }
public int Update(long id, CourseEvaluation request) { CourseEvaluation model = GetById(id); var validate = isExistsById(id, request); if (model == null) { return(0); } else if (validate != false) { return(1); } // Will Appear if evaluationTypeId is 2 // Default: 1 = Rating; 2 = Single Answer; 3 = Comment if (request.evaluationTypeId != 2) { request.CourseEvaluationValues = null; } //_context.CourseEvaluation.Update(request); //Save(); model.title = request.title; model.userGroupId = request.userGroupId; model.evaluationTypeId = request.evaluationTypeId; model.evaluationActionId = request.evaluationActionId; model.updatedAt = DateTime.Now; Save(); // Insert Evaluation Values if evaluationTypeId is 2 // Default: 1 = Rating; 2 = Single Answer; 3 = Comment if (request.evaluationTypeId == 2) { foreach (CourseEvaluationValues x in request.CourseEvaluationValues) { x.courseEvaluationId = id; x.name = x.name; x.createdAt = DateTime.Now; x.updatedAt = DateTime.Now; _context.CourseEvaluationValues.Add(x); _context.SaveChanges(); } } return(2); }
static void Main(string[] args) { var repo = new TestRepository(); Console.WriteLine("Number of students: " + repo.StudentsCourseEvaluation.Count); ListStudents(repo); CourseEvaluation student0 = repo.StudentsCourseEvaluation[0].Evaluation; CourseEvaluation student1 = repo.StudentsCourseEvaluation[1].Evaluation; EvaluationValue val0 = student0.Evaluations[0].Value; val0.Points = 5.5m; val0.Reason = "Bad design"; EvaluationValue val1 = student0.Evaluations[1].Value; val1.Points = 4m; val1.Reason = "Bad implementation"; student0.Evaluations[3].Value.Points = 3m; student1.Evaluations[0].Value.Points = 15m; ListStudents(repo); //zmena definice hodnoceni repo.StudentsCourseEvaluation[2].Evaluation.EvaluationDefinitions.RemoveAt(2); repo.StudentsCourseEvaluation[2].Evaluation.EvaluationDefinitions.Move(0, 1); repo.StudentsCourseEvaluation[2].Evaluation.EvaluationDefinitions.Add( new EvaluationDefinition() { Name = "Other", MinPoints = 0m, MaxPoints = 5m }); ListStudents(repo); repo.StudentsCourseEvaluation[2].Evaluation.EvaluationDefinitions[2].MinPoints = 3.5m; student1.Evaluations[3].Value.Points = 4m; ListStudents(repo); repo.StudentsCourseEvaluation[2].Evaluation.EvaluationDefinitions[3] = null; ListStudents(repo); Console.ReadLine(); }
public bool Add(CourseEvaluation request) { var output = false; var validate = isExists(request); if (validate == false) { request.createdAt = DateTime.Now; request.updatedAt = DateTime.Now; // Will Appear if evaluationTypeId is 2 // Default: 1 = Rating; 2 = Single Answer; 3 = Comment if (request.evaluationTypeId != 2) { request.CourseEvaluationValues = null; } _context.CourseEvaluation.Add(request); Save(); output = true; } return(output); }
public void TestModifyingValues() { if (this.Definition.Count != 5) { Assert.Inconclusive("Test corrupted! Definition is in an unexpected state."); return; } var eval = new CourseEvaluation(this.Definition); var col = new List <Evaluation>(eval.GetAllEvaluations()); Assert.AreEqual(5, col.Count, "GetAllEvaluations [Init]."); for (int i = 0; i < 5; i++) { Assert.AreEqual(this.Definition[i], col[i].Definition); } col = new List <Evaluation>(eval.GetValidEvaluations()); Assert.AreEqual(0, col.Count, "GetValidEvaluations [Init]."); col = new List <Evaluation>(eval.GetMissingEvaluations()); Assert.AreEqual(5, col.Count, "GetMissingEvaluations [Init]."); for (int i = 0; i < 5; i++) { Assert.AreEqual(this.Definition[i], col[i].Definition); } col = new List <Evaluation>(eval.GetHasPassedEvaluations()); Assert.AreEqual(2, col.Count, "GetHasPassedEvaluations [Init]."); col = new List <Evaluation>(eval.GetHasFailedEvaluations()); Assert.AreEqual(3, col.Count, "GetHasFailedEvaluations [Init]."); Assert.AreEqual(null, eval.GetTotalPoints()); Assert.AreEqual(null, eval.GetTotalPointsReason()); Assert.AreEqual("?b", eval.ToString()); //let us add some value eval.Evaluations[0].Value.Points = 11; //A - 10-20 eval.Evaluations[1].Value.Points = 11; //B - 5-10 eval.Evaluations[2].Value.Points = 11; //C - <=20 eval.Evaluations[3].Value.Points = 9; //D - >=10 //E - col = new List <Evaluation>(eval.GetValidEvaluations()); Assert.AreEqual(4, col.Count, "GetValidEvaluations [Filled]."); //A-D for (int i = 0; i < 4; i++) { Assert.AreEqual(this.Definition[i], col[i].Definition); } col = new List <Evaluation>(eval.GetMissingEvaluations()); //E Assert.AreEqual(1, col.Count, "GetMissingEvaluations [Filled]."); Assert.AreEqual(this.Definition[4], col[0].Definition); //check HasPassed col = new List <Evaluation>(eval.GetHasPassedEvaluations()); //A,B,C,E Assert.AreEqual(4, col.Count, "GetHasPassedEvaluations [Filled]."); for (int i = 0; i < 3; i++) { Assert.AreEqual(this.Definition[i], col[i].Definition); } Assert.AreEqual(this.Definition[4], col[3].Definition); //check HasFailed col = new List <Evaluation>(eval.GetHasFailedEvaluations()); //D Assert.AreEqual(1, col.Count, "GetHasFailedEvaluations [Filled]."); Assert.AreEqual(this.Definition[3], col[0].Definition); decimal?dec = 11 + 10 + 11 + 9; Assert.AreEqual(dec, eval.GetTotalPoints()); //add reasons eval.Evaluations[1].Value.Reason = "Reason1"; eval.Evaluations[3].Value.Reason = "Reason2"; Assert.AreEqual("A [10-20b]: 11b, B [5-10b]: 11b (Reason1), C [max 20b]: 11b, D [min 10b]: 9b (Reason2)", eval.GetTotalPointsReason()); Assert.AreEqual("41b = A [10-20b]: 11b, B [5-10b]: 11b (Reason1), C [max 20b]: 11b, D [min 10b]: 9b (Reason2)", eval.ToString()); }
public void TestConstructionWithNull() { var eval = new CourseEvaluation(null); Assert.Fail("CourseEvaluation should throw exception if the definition is null"); }
public void TestModyfingDefinition() { //Add some value var eval = new CourseEvaluation(this.Definition); eval.Evaluations[0].Value.Points = 11; //A - 10-20 eval.Evaluations[1].Value.Points = 11; //B - 5-10 eval.Evaluations[1].Value.Reason = "Reason1"; eval.Evaluations[2].Value.Points = 11; //C - <=20 eval.Evaluations[3].Value.Points = 9; //D - >=10 eval.Evaluations[3].Value.Reason = "Reason2"; eval.Evaluations[4].Value.Points = 10; //E - nothing Assert.AreEqual("A [10-20b]: 11b, B [5-10b]: 11b (Reason1), C [max 20b]: 11b, D [min 10b]: 9b (Reason2), E: 10b", eval.GetTotalPointsReason()); eval.Evaluations[3].Definition.Name = "F"; Assert.AreEqual("A [10-20b]: 11b, B [5-10b]: 11b (Reason1), C [max 20b]: 11b, F [min 10b]: 9b (Reason2), E: 10b", eval.GetTotalPointsReason()); this.Definition.Move(4, 3); Assert.AreEqual("A [10-20b]: 11b, B [5-10b]: 11b (Reason1), C [max 20b]: 11b, E: 10b, F [min 10b]: 9b (Reason2)", eval.GetTotalPointsReason()); this.Definition.RemoveAt(1); Assert.AreEqual("A [10-20b]: 11b, C [max 20b]: 11b, E: 10b, F [min 10b]: 9b (Reason2)", eval.GetTotalPointsReason()); this.Definition.Add(new EvaluationDefinition() { Name = "G", MaxPoints = 20, } ); Assert.AreEqual(5, eval.Evaluations.Count); eval.Evaluations[4].Value.Points = 18; //G - <= 20 Assert.AreEqual("A [10-20b]: 11b, C [max 20b]: 11b, E: 10b, F [min 10b]: 9b (Reason2), G [max 20b]: 18b", eval.GetTotalPointsReason()); this.Definition.Insert(1, new EvaluationDefinition() { Name = "B", } ); Assert.AreEqual(6, eval.Evaluations.Count); eval.Evaluations[1].Value.Points = 15; //B - nothing Assert.AreEqual("A [10-20b]: 11b, B: 15b, C [max 20b]: 11b, E: 10b, F [min 10b]: 9b (Reason2), G [max 20b]: 18b", eval.GetTotalPointsReason()); this.Definition[0] = new EvaluationDefinition() { Name = "AR", }; Assert.AreEqual("AR: 11b, B: 15b, C [max 20b]: 11b, E: 10b, F [min 10b]: 9b (Reason2), G [max 20b]: 18b", eval.GetTotalPointsReason()); decimal?sum = 11 + 15 + 11 + 10 + 9 + 18; Assert.AreEqual(sum, eval.GetTotalPoints()); this.Definition.Clear(); Assert.AreEqual(0, eval.Evaluations.Count); Assert.AreEqual(null, eval.GetTotalPointsReason()); this.Definition.Add(new EvaluationDefinition() { Name = "A", } ); Assert.AreEqual(1, eval.Evaluations.Count); eval.Evaluations[0].Value.Points = 10; //A - nothing Assert.AreEqual("A: 10b", eval.GetTotalPointsReason()); }
private bool isExistsById(long id, CourseEvaluation request) { return(_context.CourseEvaluation.Where(x => x.title == request.title && x.userGroupId == request.userGroupId && x.evaluationTypeId == request.evaluationTypeId && x.id != id).Any()); }
private bool isExists(CourseEvaluation request) { return(_context.CourseEvaluation.Where(x => x.title == request.title && x.courseId == request.courseId && x.evaluationTypeId == request.evaluationTypeId).Any()); }