private static StudentTestResponse CreateResponseStudent(Student student) { CourseTestResponse courseDto = null; if (student.Course != null) { courseDto = new CourseTestResponse { Name = student.Course.Name }; } var studentDto = new StudentTestResponse { Id = student.Id, Name = student.Name, Course = courseDto }; return(studentDto); }
public async Task ShouldAddNewStudent() { // arrange var newStudent = new StudentTestCreateRequest() { CourseId = 1, Name = studentName }; const string request = url; var studentJson = JsonConvert.SerializeObject(newStudent); var content = new StringContent(studentJson, Encoding.UTF8, contentType); StudentTestResponse response; // act using (var client = fixture.Server.CreateClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", fixture.AuthenticationToken); httpResponse = await client.PostAsync(request, content); response = await httpResponse.Content.ReadAsAsync <StudentTestResponse>(); } var student = await GetStudentByName(studentName); var studentDto = new StudentTestResponse() { Id = student.Id, Name = student.Name, Course = null }; // assert httpResponse.EnsureSuccessStatusCode(); response.Should().BeEquivalentTo(studentDto); }