Beispiel #1
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();
        }
 public void Setup()
 {
     this._professor            = ProfessorTestUtils.GetProfessor();
     this._professorDetailsDto  = ProfessorTestUtils.GetProfessorDetailsDto(_professor.Id);
     this._professorCreatingDto = ProfessorTestUtils.GetProfessorCreatingDto();
     this._professorMapper      = new ProfessorMapper();
 }
Beispiel #3
0
 public void Setup()
 {
     client               = new CustomWebApplicationFactory <Startup>().CreateClient();
     professor1           = ProfessorTestUtils.GetProfessor();
     professor2           = ProfessorTestUtils.GetProfessor2();
     professorDetailsDto1 = ProfessorTestUtils.GetProfessorDetailsDto(professor1.Id);
     professorDetailsDto2 = ProfessorTestUtils.GetProfessorDetailsDto(professor2.Id);
     professorCreationDto = ProfessorTestUtils.GetProfessorCreatingDto();
 }
        public void Map_ShouldReturnProfessor_WhenArgumentsAreProfessorDetailsDtoAndProfessor()
        {
            // Arrange
            var professor = ProfessorTestUtils.GetProfessor();
            // Act
            var result = this._professorMapper.Map(this._professorDetailsDto, professor);

            // Assert
            result.Should().BeEquivalentTo(this._professor);
        }
Beispiel #5
0
 public void TestInitialize()
 {
     this._professor1           = ProfessorTestUtils.GetProfessor();
     this._professor2           = ProfessorTestUtils.GetProfessor();
     this._professorDetailsDto1 = ProfessorTestUtils.GetProfessorDetailsDto(_professor1.Id);
     this._professorDetailsDto2 = ProfessorTestUtils.GetProfessorDetailsDto(_professor2.Id);
     this._professorCreatingDto = ProfessorTestUtils.GetProfessorCreatingDto();
     this._mockReadRepository   = new Mock <IReadRepository>();
     this._mockWriteRepository  = new Mock <IWriteRepository>();
     this._mockProfessorMapper  = new Mock <IProfessorMapper>();
     _professorService          = new ProfessorService(_mockReadRepository.Object, _mockWriteRepository.Object,
                                                       _mockProfessorMapper.Object);
 }
        public async Task Create_ShouldReturnInstanceOfCourseDetailsDto()
        {
            // Arrange
            Professor professor = ProfessorTestUtils.GetProfessor();

            _mockCourseMapper.Setup(mapper => mapper.Map(_course1)).Returns(_courseDto1);
            _mockCourseMapper.Setup(mapper => mapper.Map(_courseCreatingDto)).Returns(_course1);
            _mockWriteRepository.Setup(repo => repo.AddNewAsync <Course>(_course1)).Returns(() => Task.FromResult(_course1));
            _mockProfessorService.Setup(professorService =>
                                        professorService.GetProfessorById(professor.Id)).Returns(() => Task.FromResult(professor));
            // Act
            CourseDto actualCourse = await _courseService.Create(professor.Id, _courseCreatingDto);

            // Assert
            actualCourse.Should().BeEquivalentTo(_courseDto1);
        }
Beispiel #7
0
        public async Task PostCourse_ShouldReturnCourseCreatedFromGivenBody()
        {
            //Arrange
            var contents = new StringContent(JsonConvert.SerializeObject(courseCreationDto), Encoding.UTF8, "application/json");

            //Act
            var response = await client.PostAsync("api/professors/" + ProfessorTestUtils.GetProfessor().Id + "/courses", contents);

            //Assert
            response.EnsureSuccessStatusCode();
            var responseString = await response.Content.ReadAsStringAsync();

            CourseDto courseDetailsDtoReturned = JsonConvert.DeserializeObject <CourseDto>(responseString);

            courseDetailsDtoReturned.Should().BeEquivalentTo(courseCreationDto, options =>
                                                             options.ExcludingMissingMembers());
        }
Beispiel #8
0
        public async Task GetAllProfessorCourses_ShouldReturnAllCourses()
        {
            //Arrange
            List <CourseDto> courseDetailsDtos = new List <CourseDto>();

            courseDetailsDtos.Add(courseDetailsDto1);
            courseDetailsDtos.Add(courseDetailsDto2);
            //Act
            var response = await client.GetAsync("api/professors/" + ProfessorTestUtils.GetProfessor().Id + "/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 GetAllForProfessor_ShouldReturnAllCourses()
        {
            //Arrange
            Professor professor = ProfessorTestUtils.GetProfessor();
            var       expectedCoursesDtoList = new List <CourseDto> {
                _courseDto1, _courseDto2
            };
            var courseList = new List <Course> {
                _course1, _course2
            };

            _mockProfessorService.Setup(professorService =>
                                        professorService.GetProfessorById(professor.Id)).Returns(() => Task.FromResult(professor));
            var mockCoursesQueryable = courseList.AsQueryable().Where(course => course.Professor == professor).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.GetAllForProfessor(professor.Id);

            //Assert
            actualCoursesDtoList.Should().BeEquivalentTo(expectedCoursesDtoList);
        }