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 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);
        }
Exemple #3
0
 public void Setup()
 {
     this._course            = CourseTestUtils.GetCourse();
     this._courseDetailsDto  = CourseTestUtils.GetCourseDetailsDto(this._course.Id);
     this._courseCreatingDto = CourseTestUtils.GetCourseCreatingDto();
     this._courseMapper      = new CourseMapper();
 }
Exemple #4
0
        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();
        }
Exemple #5
0
 public void Setup()
 {
     client            = new CustomWebApplicationFactory <Startup>().CreateClient();
     course1           = CourseTestUtils.GetCourse();
     course2           = CourseTestUtils.GetCourse2();
     courseDetailsDto1 = CourseTestUtils.GetCourseDetailsDto(course1.Id);
     courseDetailsDto2 = CourseTestUtils.GetCourseDetailsDto(course2.Id);
     courseCreationDto = CourseTestUtils.GetCourseCreatingDto();
 }
Exemple #6
0
        public void Map_ShouldReturnCourse_WhenArgumentsAreCourseDetailsDtoAndCourse()
        {
            // Arrange
            var course = CourseTestUtils.GetCourse();
            // Act
            var result = this._courseMapper.Map(this._courseDetailsDto, course);

            // Assert
            result.Should().BeEquivalentTo(this._course);
        }
        public void Map_ShouldReturnExam_WhenArgumentsAreExamCreatingDtoAndCourse()
        {
            // Act
            var result = this._examMapper.Map(this._examCreatingDto, CourseTestUtils.GetCourse());

            // Assert
            result.Should().Match <Domain.Entities.Exam>((obj) =>
                                                         obj.Date == this._exam.Date &&
                                                         obj.Course == this._exam.Course);
        }
 public void TestInitialize()
 {
     this._course1             = CourseTestUtils.GetCourse();
     this._course2             = CourseTestUtils.GetCourse();
     this._courseDto1          = CourseTestUtils.GetCourseDetailsDto(_course1.Id);
     this._courseDto2          = CourseTestUtils.GetCourseDetailsDto(_course2.Id);
     this._courseCreatingDto   = CourseTestUtils.GetCourseCreatingDto();
     this._mockReadRepository  = new Mock <IReadRepository>();
     this._mockWriteRepository = new Mock <IWriteRepository>();
     this._mockCourseMapper    = new Mock <ICourseMapper>();
     _mockProfessorService     = new Mock <IProfessorService>();
     _mockStudentService       = new Mock <IStudentService>();
     _courseService            = new CourseService(_mockReadRepository.Object, _mockWriteRepository.Object,
                                                   _mockCourseMapper.Object, _mockProfessorService.Object, _mockStudentService.Object);
 }
        public async Task getAllExamsForACourse_ShouldReturnExamsForThatCourse()
        {
            List <ExamDto> examDtosExpected = new List <ExamDto> {
                ExamTestUtils.GetExamDto(exam.Id)
            };
            var response = await client.GetAsync("api/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);
        }