public async Task Test4Put() { TeamMutateModel mutateModel = new TeamMutateModel { Name = "TestMetaUpdated", Description = "This is a meta created by the unit test" }; TeamsController controller = new TeamsController(_context, null); IActionResult result = await controller.Put(this.id, mutateModel); NoContentResult ok = result as NoContentResult; Assert.NotNull(ok); Assert.Equal(204, ok.StatusCode); }
public async Task <IActionResult> Put([FromRoute] Guid id, [FromBody] TeamMutateModel teamMutate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Team team = await this.teamsRepository.GetOne(id); if (team == null || id != team.Id) { return(BadRequest()); } if (!string.IsNullOrEmpty(teamMutate.Name)) { team.Name = teamMutate.Name; } if (teamMutate.Description != null) { team.Description = teamMutate.Description; } team.UpdatedAt = teamMutate.UpdatedAt; try { await teamsRepository.UpdateAsync(team); } catch (DbUpdateConcurrencyException) { if (!await teamsRepository.EntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }