public async Task UpdatePersonForGroup_ShouldReturnNoContentStatusAndUpdatedPersonShouldHasNewValue_WhenModelIsValid() { var group = await CreateGroupAndReturnDto("Group 1"); var person = await CreatePersonAndReturnDto(group.Id, "Jan Kowalski", 2000); var model = new SavePersonModel() { FullName = "New name", Year = 2001 }; var payload = GetPayload(model); var response = await Client.PutAsync($"api/groups/{group.Id}/people/{person.Id}", payload); response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.NoContent); var getUpdatedPersonResponse = await Client.GetAsync($"api/groups/{group.Id}/people/{person.Id}"); var responseString = await getUpdatedPersonResponse.Content.ReadAsStringAsync(); var updatedPerson = JsonConvert.DeserializeObject <PersonDto>(responseString); getUpdatedPersonResponse.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK); updatedPerson.FullName.ShouldBeEquivalentTo(model.FullName); updatedPerson.Year.ShouldBeEquivalentTo(model.Year); }
private async Task <HttpResponseMessage> CreatePerson(int groupId, string fullName, int year) { var model = new SavePersonModel() { FullName = fullName, Year = year, }; var payload = GetPayload(model); var response = await Client.PostAsync($"api/groups/{groupId}/people", payload); return(response); }
public async Task UpdatePersonForGroup_ShouldReturnBadRequest_WhenModelIsInvalid() { var group = await CreateGroupAndReturnDto("Group 1"); var person = await CreatePersonAndReturnDto(group.Id, "Jan Kowalski", 2000); var model = new SavePersonModel() { FullName = "New name", Year = 0 }; var payload = GetPayload(model); var response = await Client.PutAsync($"api/groups/{group.Id}/people/{person.Id}", payload); response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.BadRequest); }
public JsonResult SavePerson(SavePersonModel person) { //TODO: save new person to database and return new person's id return(Json(new { PersonId = 42 })); }