public async Task AddStudentAsync_ShouldReturnStudent() { var expectedStudent = this.students.Single(s => s.UserId == 1); var mockContext = new Mock <StudentInfoSysDbContext>(); mockContext.Setup(c => c.Set <Student>()) .Returns(this.mockSet.Object); var repository = new StudentRepository(mockContext.Object); var result = await repository.AddStudentAsync(expectedStudent); Assert.Equal(expectedStudent.Enrollments.First().CourseId, result.Enrollments.First().CourseId); }
private async Task seedDatabase() { scienceRoom = new ClassRoom() { ClassRoomName = "Science Room", SeatsHorizontally = 10, SeatsVertically = 8 }; jonathan = new Teacher() { TeacherName = "jonathan" }; heber = new Teacher() { TeacherName = "not jonathan" }; sam = new Student() { StudentName = "sam" }; ben = new Student() { StudentName = "ben" }; tim = new Student() { StudentName = "tim" }; await classRepository.AddClassRoomAsync(scienceRoom); await classRepository.AddTeacherAsync(jonathan); await classRepository.AddTeacherAsync(heber); await studentRepository.AddStudentAsync(sam); await studentRepository.AddStudentAsync(ben); await studentRepository.AddStudentAsync(tim); mathClass = new ClassModel() { ClassName = "math", TeacherId = jonathan.TeacherId, ClassRoomId = scienceRoom.ClassRoomId }; scienceClass = new ClassModel() { ClassName = "science", TeacherId = jonathan.TeacherId, ClassRoomId = scienceRoom.ClassRoomId }; notScienceClass = new ClassModel() { ClassName = "not science", TeacherId = heber.TeacherId, ClassRoomId = scienceRoom.ClassRoomId }; await classRepository.AddClassAsync(mathClass); await classRepository.AddClassAsync(scienceClass); await classRepository.AddClassAsync(notScienceClass); math1010 = new Course() { CourseName = "math 1010", TeacherId = jonathan.TeacherId }; science1010 = new Course() { CourseName = "science 1010", TeacherId = jonathan.TeacherId }; await courseRepository.AddCourseAsync(math1010); await courseRepository.AddCourseAsync(science1010); await classRepository.EnrollStudentAsync(sam.StudentId, mathClass.ClassId, math1010.CourseId); await classRepository.EnrollStudentAsync(ben.StudentId, mathClass.ClassId, science1010.CourseId); await classRepository.EnrollStudentAsync(tim.StudentId, scienceClass.ClassId, science1010.CourseId); }
public void AddStudent_WhenTheParameterIsNull_ThrowsException() { Assert.ThrowsAsync <ArgumentException>( async() => await _studentRepository.AddStudentAsync(null)); }