public async Task Create_ShouldReturnInstanceOfCourseDetailsDto() { // Arrange _mockCourseService.Setup(service => service.GetCourseById(_examCreatingDto.CourseId)).ReturnsAsync(CourseTestUtils.GetCourse()); _mockExamMapper.Setup(mapper => mapper.Map(_examCreatingDto, CourseTestUtils.GetCourse())).Returns(_exam); _mockWriteRepository.Setup(repo => repo.AddNewAsync <Domain.Entities.Exam>(_exam)).Returns(() => Task.FromResult(_exam)); _mockExamMapper.Setup(mapper => mapper.Map(_exam)).Returns(_examDto); var expectedStudents = new List <Student> { StudentTestUtils.GetStudent() }; var expectedExams = new List <Domain.Entities.Exam> { _exam }; _mockReadRepository.Setup(repo => repo.GetAll <Student>()).Returns(expectedStudents.AsQueryable().BuildMock()); _mockReadRepository.Setup(repo => repo.GetAll <Domain.Entities.Exam>()).Returns(expectedExams.AsQueryable().BuildMock()); IGenericEmail email = null; _mockEmailService.Setup(service => service.SendEmail(email)).Verifiable(); var classroomAllocation = new List <ClassroomAllocationCreatingDto> { }; _mockClassroomAllocationMapper.Setup(mapper => mapper.Map(_examCreatingDto, _exam.Id)).Returns(classroomAllocation); // Act ExamDto actualExam = await this._examService.Create(_examCreatingDto); // Assert actualExam.Should().BeEquivalentTo(_examDto); }
public void Setup() { this._student = StudentTestUtils.GetStudent(); this._studentDetailsDto = StudentTestUtils.GetStudentDetailsDto(this._student.Id); this._studentCreationDto = StudentTestUtils.GetStudentCreationDto(); this._studentMapper = new StudentMapper(); }
public static async System.Threading.Tasks.Task PopulateTestDatabaseAsync(ExamContext examContext) { Student student = StudentTestUtils.GetStudent(); Course course = CourseTestUtils.GetCourse(); await examContext.AddNewAsync(student); await examContext.AddNewAsync(StudentTestUtils.GetStudent2()); await examContext.AddNewAsync(course); await examContext.AddNewAsync(CourseTestUtils.GetCourse2()); await examContext.AddNewAsync(ProfessorTestUtils.GetProfessor()); await examContext.AddNewAsync(ProfessorTestUtils.GetProfessor2()); await examContext.AddNewAsync(StudentCourseTestUtils.GetStudentCourse(student.Id, course.Id)); await examContext.AddNewAsync(ExamTestUtils.GetExam()); await examContext.AddNewAsync(ClassroomTestUtils.GetClassroom()); await examContext.AddNewAsync(GradeTestUtils.GetInitialStateGrade()); await examContext.AddNewAsync(ClassroomAllocationTestUtils.GetClassroomAllocation()); await examContext.AddNewAsync(GradeTestUtils.GetGradeWithValue()); await examContext.SaveAsync(); }
public async Task GetCheckedInStudent_ShouldReturnStudentsThatCheckedInAtExam() { // Arrange Grade grade = GradeTestUtils.GetInitialStateGrade(); var grades = new List <Grade> { grade }; GradeDto gradeDto = GradeTestUtils.GetInitialGradeDto(grade.Id); Student student = StudentTestUtils.GetStudent(); _mockReadRepository.Setup(repo => repo.GetByIdAsync <Domain.Entities.Exam>(_exam.Id)).ReturnsAsync(_exam); _mockReadRepository.Setup(repo => repo.GetAll <Grade>()).Returns(grades.AsQueryable().BuildMock); _mockGradeMapper.Setup(mapper => mapper.Map(grade)).Returns(gradeDto); _mockStudentMapper.Setup(mapper => mapper.Map(student, gradeDto)) .Returns(StudentTestUtils.GetStudentFetchingGradeDto(student.Id, gradeDto)); var expectedResult = new List <StudentFetchingGradeDto> { StudentTestUtils.GetStudentFetchingGradeDto(student.Id, gradeDto) }; // Act var result = await _examService.GetCheckedInStudents(_exam.Id); // Assert result.Should().BeEquivalentTo(expectedResult); }
public async Task GetAllExamsFromCourseForStudent_ShouldReturnExamsForStudentWithThatId() { // Arrange var expectedExamsDtoList = new List <ExamDto> { _examDto }; var course = _exam.Course; var courseDtoList = new List <CourseDto> { CourseTestUtils.GetCourseDetailsDto(CourseTestUtils.GetCourse().Id) }; var student = StudentTestUtils.GetStudent(); _mockCourseService.Setup(service => service.GetCourseById(course.Id)).ReturnsAsync(course); _mockStudentCourseService.Setup(service => service.GetCourses(student.Id)).ReturnsAsync(courseDtoList); _mockStudentService.Setup(service => service.GetStudentById(student.Id)).ReturnsAsync(student); var examsList = new List <Domain.Entities.Exam> { ExamTestUtils.GetExam() }; var mockExamsQueryable = examsList.AsQueryable().BuildMock(); _mockReadRepository.Setup(repo => repo.GetAll <Domain.Entities.Exam>()).Returns(mockExamsQueryable); _mockExamMapper.Setup(mapper => mapper.Map(_exam)).Returns(_examDto); // Act var actualExamsDtoList = await _examService.GetAllExamsFromCourseForStudent(course.Id, student.Id); // Assert actualExamsDtoList.Should().BeEquivalentTo(expectedExamsDtoList); }
public void Map_ShouldReturnGrade_WhenArgumentsAreGradeCreationDtoStudentAndExam() { // Act var result = gradeMapper.Map(gradeCreationDto, StudentTestUtils.GetStudent(), ExamTestUtils.GetExam()); // Assert result.Should().BeEquivalentTo(grade, options => options.Excluding(g => g.Id)); }
public void Map_ShouldReturnStudent_WhenArgumentsAreStudentDetailsDtoAndStudent() { // Arrange var student = StudentTestUtils.GetStudent(); // Act var result = this._studentMapper.Map(this._studentDetailsDto, student); // Assert result.Should().BeEquivalentTo(this._student); }
public void TestInitialize() { this._student1 = StudentTestUtils.GetStudent(); this._student2 = StudentTestUtils.GetStudent(); this._studentDto1 = StudentTestUtils.GetStudentDetailsDto(_student1.Id); this._studentDto2 = StudentTestUtils.GetStudentDetailsDto(_student2.Id); this._studentCreationDto = StudentTestUtils.GetStudentCreationDto(); this._mockReadRepository = new Mock <IReadRepository>(); this._mockWriteRepository = new Mock <IWriteRepository>(); this._mockStudentMapper = new Mock <IStudentMapper>(); _studentService = new StudentService(_mockReadRepository.Object, _mockWriteRepository.Object, _mockStudentMapper.Object); }
public void Setup() { client = new CustomWebApplicationFactory <Startup>().CreateClient(); student1 = StudentTestUtils.GetStudent(); student2 = StudentTestUtils.GetStudent2(); studentDetailsDto1 = StudentTestUtils.GetStudentDetailsDto(student1.Id); studentDetailsDto2 = StudentTestUtils.GetStudentDetailsDto(student2.Id); studentCreationDto = StudentTestUtils.GetStudentCreationDto(); course1 = CourseTestUtils.GetCourse(); course2 = CourseTestUtils.GetCourse2(); courseDetailsDto = CourseTestUtils.GetCourseDetailsDto(course1.Id); studentCourseCreationDto = StudentCourseTestUtils.GetStudentCourseCreationDto(course2.Id); }
public void Setup() { this._student = StudentTestUtils.GetStudent(); this._course = CourseTestUtils.GetCourse2(); this._courseDto = CourseTestUtils.GetCourseDetailsDto(_course.Id); this._studentCourse1 = StudentCourseTestUtils.GetStudentCourse(_student.Id, _course.Id); this._studentCourse2 = StudentCourseTestUtils.GetStudentCourse2(); this._studentCourseCreationDto = StudentCourseTestUtils.GetStudentCourseCreationDto(this._studentCourse1.CourseId); this._mockReadRepository = new Mock <IReadRepository>(); this._mockWriteRepository = new Mock <IWriteRepository>(); this._mockStudentCourseMapper = new Mock <IStudentCourseMapper>(); this._mockCourseMapper = new Mock <ICourseMapper>(); this._studentCourseService = new StudentCourseService(_mockReadRepository.Object, _mockWriteRepository.Object, _mockStudentCourseMapper.Object, _mockCourseMapper.Object); }
public async Task GetAllExamsFromCourseForStudent_ShouldThrowStudentNotAppliedToCourse() { // Arrange var course = _exam.Course; var emptyCourseDtoList = new List <CourseDto>(); var student = StudentTestUtils.GetStudent(); _mockCourseService.Setup(service => service.GetCourseById(course.Id)).ReturnsAsync(course); _mockStudentCourseService.Setup(service => service.GetCourses(student.Id)).ReturnsAsync(emptyCourseDtoList); _mockStudentService.Setup(service => service.GetStudentById(student.Id)).ReturnsAsync(student); // Act Func <Task> act = async() => await _examService.GetAllExamsFromCourseForStudent(course.Id, student.Id); // Assert act.Should().Throw <StudentNotAppliedToCourse>(student.Id.ToString(), course.Id.ToString()); }
public async Task GetStudentAvailableCourses_ShouldReturnAllCoursesWithYearLessOrEqualToStudentYear() { //Arrange List <CourseDto> courseDetailsDtos = new List <CourseDto>(); courseDetailsDtos.Add(courseDetailsDto1); courseDetailsDtos.Add(courseDetailsDto2); //Act var response = await client.GetAsync("api/students/" + StudentTestUtils.GetStudent().Id + "/available-courses"); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); List <CourseDto> coursesDetailsDtosReturned = JsonConvert.DeserializeObject <List <CourseDto> >(responseString); coursesDetailsDtosReturned.Should().BeEquivalentTo(courseDetailsDtos); }
public async Task GetAllExamsFromCourseForStudent_ShouldReturnExamsForStudentWithThatId() { //Arrange List <ExamDto> examDtosExpected = new List <ExamDto> { ExamTestUtils.GetExamDto(exam.Id) }; //Act var response = await client.GetAsync("api/students/" + StudentTestUtils.GetStudent().Id + "/courses/" + CourseTestUtils.GetCourse().Id + "/exams"); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); List <ExamDto> examsDetailsDtosActual = JsonConvert.DeserializeObject <List <ExamDto> >(responseString); examsDetailsDtosActual.Should().BeEquivalentTo(examDtosExpected); }
public async Task GetCheckedInStudent_ShouldReturnAllStudentThatCheckedInAtExam() { // Arrange var expectedStudents = new List <StudentFetchingGradeDto> { StudentTestUtils.GetStudentFetchingGradeDto(StudentTestUtils.GetStudent().Id, GradeTestUtils.GetInitialGradeDto(GradeTestUtils.GetInitialStateGrade().Id)), StudentTestUtils.GetStudentFetchingGradeDto(StudentTestUtils.GetStudent2().Id, GradeTestUtils.GetGradeWithValueDto(GradeTestUtils.GetGradeWithValue().Id, GradeTestUtils.GetGradeWithValue().Date)) }; // Act var response = await client.GetAsync("api/exams/" + exam.Id + "/checked-in-students"); // Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); List <StudentFetchingGradeDto> actualStudents = JsonConvert.DeserializeObject <List <StudentFetchingGradeDto> >(responseString); actualStudents.Should().BeEquivalentTo(expectedStudents, options => options.Excluding(s => s.Grade.Date)); }
public async Task GetAvailableCoursesForStudent_ShouldReturnAllCoursesWithYearLowerOrEqualToStudentYear() { //Arrange Student student = StudentTestUtils.GetStudent(); _mockStudentService.Setup(studentService => studentService.GetStudentById(student.Id)) .Returns(() => Task.FromResult(student)); var expectedCoursesDtoList = new List <CourseDto> { _courseDto1, _courseDto2 }; var courseList = new List <Course> { _course1, _course2 }; var mockCoursesQueryable = courseList.AsQueryable().BuildMock(); _mockReadRepository.Setup(repo => repo.GetAll <Course>()).Returns(mockCoursesQueryable); _mockCourseMapper.Setup(course => course.Map(_course1)).Returns(_courseDto1); _mockCourseMapper.Setup(course => course.Map(_course2)).Returns(_courseDto2); //Act var actualCoursesDtoList = await _courseService.GetAvailableCoursesForStudent(student.Id); //Assert actualCoursesDtoList.Should().BeEquivalentTo(expectedCoursesDtoList); }