public async Task GetDetailsDtoById_ShouldReturnInstanceOfStudentDetailsDto() { // Arrange _mockReadRepository.Setup(repo => repo.GetByIdAsync <Student>(_student1.Id)).ReturnsAsync(_student1); _mockStudentMapper.Setup(mapper => mapper.Map(_student1)).Returns(_studentDto1); // Act StudentDetailsDto actualStudent = await _studentService.GetDetailsDtoById(_student1.Id); // AssertB actualStudent.Should().BeEquivalentTo(_studentDto1); }
public async Task Create_ShouldReturnInstanceOfStudentDetailsDto() { // Arrange _mockStudentMapper.Setup(mapper => mapper.Map(_student1)).Returns(_studentDto1); _mockStudentMapper.Setup(mapper => mapper.Map(_studentCreationDto)).Returns(_student1); _mockWriteRepository.Setup(repo => repo.AddNewAsync <Student>(_student1)).Returns(() => Task.FromResult(_student1)); // Act StudentDetailsDto actualStudent = await _studentService.Create(_studentCreationDto); // Assert actualStudent.Should().BeEquivalentTo(_studentDto1); }
public async Task GetStudentById_ShouldReturnStudentWithGivenId() { //Act var response = await client.GetAsync("api/students/" + student1.Id); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); StudentDetailsDto studentDetailsDtoReturned = JsonConvert.DeserializeObject <StudentDetailsDto>(responseString); studentDetailsDtoReturned.Should().BeEquivalentTo(studentDetailsDto1); }
public async Task PostStudent_ShouldReturnStudentCreatedFromGivenBody() { //Arrange var contents = new StringContent(JsonConvert.SerializeObject(studentCreationDto), Encoding.UTF8, "application/json"); //Act var response = await client.PostAsync("api/students", contents); //Assert response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); StudentDetailsDto studentsDetailsDtoReturned = JsonConvert.DeserializeObject <StudentDetailsDto>(responseString); studentsDetailsDtoReturned.Should().BeEquivalentTo(studentCreationDto, options => options.ExcludingMissingMembers()); }