public async Task CreateGradeAsync_WhenTeacherNull_ShouldHandleException() { OneTimeSetUp(); _teachersRepositoryMock.Setup(t => t.All()) .Returns(new List <Teacher> { }.AsQueryable()); var newGrade = new GradeInputModel() { StudentId = 5, Period = GradePeriod.FirstTerm, Type = GradeType.Final, TeacherId = TestTeacherDBId, SubjectId = 4, }; try { await _gradesService.CreateAsync(newGrade); } catch (ArgumentException ae) { ae.Message.Should().Be($"Sorry, we couldn't find teacher with id {TestTeacherDBId}"); } }
public async Task CreateAsync(GradeInputModel inputModel) { var studentSubject = _studentSubjectsRepository.All().FirstOrDefault(s => s.StudentId == inputModel.StudentId && s.SubjectId == inputModel.SubjectId); if (studentSubject != null) { var teacher = _teachersRepository.All().FirstOrDefault(t => t.Id == inputModel.TeacherId); if (teacher != null) { var grade = new Grade { Value = inputModel.Value, Period = inputModel.Period, Type = inputModel.Type, StudentSubject = studentSubject, Teacher = teacher }; await _gradesRepository.AddAsync(grade); await _gradesRepository.SaveChangesAsync(); return; } throw new ArgumentException($"Sorry, we couldn't find teacher with id {inputModel.TeacherId}"); } throw new ArgumentException($"Sorry, we couldn't find pair of student ({inputModel.StudentId}) and subject({inputModel.SubjectId})"); }
public async Task CreateGradeAsync_HappyPath() { OneTimeSetUp(); var newAbsence = new GradeInputModel() { Period = GradePeriod.FirstTerm, Type = GradeType.Final, TeacherId = TestTeacherDBId, StudentId = StudentCorrectId, SubjectId = SubjectCorrectId, }; await _gradesService.CreateAsync(newAbsence); _gradesRepositoryMock.Object.All().Count().Should().Be(1); }
public void GradeStudent(string studentId, GradeInputModel gradeModel) { var student = Repositories.Students.GetById(studentId); var grade = Repositories.Grades.GetWithoutTracking() .SingleOrDefault(g => g.Id == gradeModel.GradeId); var ts = Repositories.TeacherToSubject.Query() .AsNoTracking() .Include(tts => tts.Teacher) .Include(tts => tts.Subject) .SingleOrDefault(tts => tts.TeacherId == gradeModel.TeacherId && tts.SubjectId == gradeModel.SubjectId); if (ts is null) { throw new TargetException("Invalid input data"); } var subject = Repositories.Subjects.GetWithoutTracking() .SingleOrDefault(s => s.Id == gradeModel.SubjectId); var teacher = Repositories.Teachers.GetWithoutTracking() .SingleOrDefault(t => t.Id == gradeModel.TeacherId); var newGrade = new StudentToGrade { DateCreated = DateTime.Now, DateModified = DateTime.Now, GradeId = gradeModel.GradeId, Grade = grade, SubjectId = gradeModel.SubjectId, Subject = subject, StudentId = studentId, Student = student, Teacher = teacher }; student.Grades.Add(newGrade); Repositories.Students.SaveChanges(); }
public async Task CreateGradeAsync_WhenStudentSubjectNull_ShouldHandleException() { _teachersRepositoryMock.Setup(t => t.All()) .Returns(new List <Teacher> { }.AsQueryable()); var newGrade = new GradeInputModel() { StudentId = StudentSubjectId, Period = GradePeriod.FirstTerm, Type = GradeType.Final, TeacherId = TestTeacherDBId, SubjectId = 10, }; try { await _gradesService.CreateAsync(newGrade); } catch (ArgumentException ae) { ae.Message.Should().Be($"Sorry, we couldn't find pair of student ({StudentSubjectId}) and subject({10})"); } }
public IActionResult Save(GradeInputModel model) { this.service.Save(model); return(this.Ok()); }
public void GradeStudent([FromRoute] string studentId, [FromBody] GradeInputModel gradeModel) { _studentService.GradeStudent(studentId, gradeModel); }