public async Task <IHttpActionResult> UpdateAsync([FromBody] CursusToUpdateDto dto) { var cursusFromDto = Mapper.Map <Cursus>(dto); var cursus = await _cursusService.UpdateAsync(cursusFromDto); if (cursus == null) { return(BadRequest("Geen cursus gevonden")); } var resultDto = Mapper.Map <CursusToDetailsDto>(cursus); return(Ok(resultDto)); }
public async Task UpdateWithValidReturnsCreatedResult() { // ARRANGE var newTitle = "new title"; var cursusToUpdate = CursusBuilder.GetCursus(1, "test", newTitle); var inputDto = new CursusToUpdateDto { Id = 1, Titel = newTitle, Code = cursusToUpdate.Code }; _cursusService.Setup(x => x.UpdateAsync(It.IsAny <Cursus>())) .Returns(Task.FromResult(cursusToUpdate)); // Act var result = await _cursussenController.UpdateAsync(inputDto); var objectResult = result as OkNegotiatedContentResult <CursusToDetailsDto>; // Assert Assert.IsNotNull(objectResult); Assert.IsTrue(objectResult.Content.Titel.Equals(newTitle)); }