public async Task InsertDelete_SingleStudyGroup_ReturnsNoContent() { // arrange var userForCreationDto = new UserForCreationDto() { FirstName = "Markus", LastName = "Christen", Email = "*****@*****.**", Biography = "this is a test", DegreeProgram = "Testing", StartDate = "HS20" }; var postRequestUser = CreateHttpRequest(HttpMethod.Post, "/users/", userForCreationDto); var postResponseUser = await Client.SendAsync(postRequestUser); try { var studyGroupForCreationDto = new StudyGroupForCreationDto() { Purpose = "Test study group", ModuleId = -1 }; var postRequestStudyGroup = CreateHttpRequest(HttpMethod.Post, "/studygroups/", studyGroupForCreationDto); // act var postResponseStudyGroup = await Client.SendAsync(postRequestStudyGroup); var fetchedStudyGroup = await GetRequestData <StudyGroupDto>(postResponseStudyGroup); // assert Assert.Equal(HttpStatusCode.Created, postResponseStudyGroup.StatusCode); Assert.Equal(studyGroupForCreationDto.Purpose, fetchedStudyGroup.Purpose); Assert.NotNull(fetchedStudyGroup.Module); Assert.NotNull(fetchedStudyGroup.User); // arrange var queryForStudyGroup = postResponseStudyGroup.Headers.Location.PathAndQuery; var deleteRequestStudyGroup = CreateHttpRequest(HttpMethod.Delete, queryForStudyGroup); // act var deleteResponseStudyGroup = await Client.SendAsync(deleteRequestStudyGroup); // assert Assert.Equal(HttpStatusCode.OK, deleteResponseStudyGroup.StatusCode); } finally { // clean up var queryForUser = postResponseUser.Headers.Location.PathAndQuery; var deleteRequestUser = CreateHttpRequest(HttpMethod.Delete, queryForUser); var deleteResponseUser = await Client.SendAsync(deleteRequestUser); deleteResponseUser.EnsureSuccessStatusCode(); } }
public async Task Insert_InvalidStudyGroup_ReturnsBadRequest() { // arrange var studyGroupForCreationDto = new StudyGroupForCreationDto() { Purpose = "", ModuleId = -1 }; var postRequest = CreateHttpRequest(HttpMethod.Post, "/studygroups/", studyGroupForCreationDto); // act var response = await Client.SendAsync(postRequest); // assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public async Task <ActionResult <StudyGroupDto> > CreateStudyGroup( StudyGroupForCreationDto studyGroupForCreationDto) { var studyGroup = _mapper.Map <StudyGroup>(studyGroupForCreationDto); var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value.Substring(6); studyGroup.UserId = userId; studyGroup.CreationDate = DateTime.UtcNow; var studyGroupEntity = await _studyGroupRepository.Insert(studyGroup); var studyGroupDto = _mapper.Map <StudyGroupDto>(studyGroupEntity); return(CreatedAtRoute("GetStudyGroup", new { studyGroupId = studyGroupDto.Id }, studyGroupDto)); }