public async Task <IActionResult> Edit(int id, Lecture lecture) { if (!ModelState.IsValid) { var viewModel = new LectureFormViewModel { lecture = lecture }; return(View(viewModel)); } if (id != lecture.Id) { return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } try { await _serviceLecture.UpdateAsync(lecture); return(RedirectToAction(nameof(Index))); } catch (NotFoundException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } catch (DbConcurrencyException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public void UpdateAsync_ThrowsValidationException() { Mock.Setup(repo => repo.GetAsync(It.IsAny <int>())) .Returns(GetExceptionTest()); Assert.ThrowsAsync <ValidationException>(async() => await LectureService .UpdateAsync(_lectureDTO)); }
public async Task UpdateAsync_ValidCall() { await LectureService.UpdateAsync(_lectureDTO); Mock.Verify(m => m.Update(It.IsAny <Lecture>())); }