public async Task Update_ShouldReturnInstanceOfCourseDetailsDto()
        {
            // Arrange
            _mockCourseMapper.Setup(mapper => mapper.Map(_course1.Id, _courseCreatingDto)).Returns(_courseDto1);
            _mockReadRepository.Setup(repo => repo.GetByIdAsync <Course>(_course1.Id)).ReturnsAsync(_course1);
            // Act
            CourseDto actualCourse = await _courseService.Update(_course1.Id, _courseCreatingDto);

            // Assert
            actualCourse.Should().BeEquivalentTo(_courseDto1);
        }
Exemple #2
0
        public async Task GetCourseById_ShouldReturnCourseWithGivenId()
        {
            //Act
            var response = await client.GetAsync("api/courses/" + course1.Id);

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

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

            courseDetailsDtoReturned.Should().BeEquivalentTo(courseDetailsDto1);
        }
        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);
        }
Exemple #4
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());
        }