コード例 #1
0
        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 }));
            }
        }
コード例 #2
0
        public void UpdateAsync_ThrowsValidationException()
        {
            Mock.Setup(repo => repo.GetAsync(It.IsAny <int>()))
            .Returns(GetExceptionTest());

            Assert.ThrowsAsync <ValidationException>(async() => await LectureService
                                                     .UpdateAsync(_lectureDTO));
        }
コード例 #3
0
        public async Task UpdateAsync_ValidCall()
        {
            await LectureService.UpdateAsync(_lectureDTO);

            Mock.Verify(m => m.Update(It.IsAny <Lecture>()));
        }