public ActionResult <ChapterDto> Update(int chapterId, [FromBody] UpdateChapterCommand command) { command.ChapterId = chapterId; return(updateChapterCommandHandler.Handle(command) .OnBoth((result) => { return responseHandler.GetResponse(result); })); }
public async Task <IActionResult> Put([FromRoute] Guid chapterId, [FromBody] UpdateChapterCommand updateChapterCommand) { using (var scope = _tracer.BuildSpan("UpdateChapter").StartActive(finishSpanOnDispose: true)) { updateChapterCommand.SetId(chapterId); var response = await _mediator.Send(updateChapterCommand); //catch if failure return(Ok(response)); } }
public async Task <ActionResult> UpdateChapter( [FromRoute] ChapterReference reference, [FromBody] UpdateChapterRequest request, CancellationToken cancellationToken) { var command = new UpdateChapterCommand(reference.SagaId, reference.ChapterId, request.Content); try { await _sender.Send(command, cancellationToken); } catch (ChapterNotFoundException e) { return(NotFound(e.Message)); } return(NoContent()); }
public async Task Handle_ValidChapterData_ChapterShouldNotFound() { //Arrange var chapterId = Guid.NewGuid(); var command = new UpdateChapterCommand() { Name = "anonymousName", EnglishLevel = (int)EnglishLevel.Beginner }; command.SetId(chapterId); _chapterRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Chapter> >())) .ReturnsAsync(false); //Act //Assert await Assert.ThrowsAsync <InvalidOperationException>(() => _chapterCommandHandler.Handle(command, CancellationToken.None)); _autoMocker.VerifyAll(); }
public async Task Handle_ValidChapterData_ShouldSuccess() { //Arrange var chapterId = Guid.NewGuid(); var command = new UpdateChapterCommand() { Name = "anonymousName", EnglishLevel = (int)EnglishLevel.Beginner }; command.SetId(chapterId); _chapterRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Chapter> >())) .ReturnsAsync(true); _chapterRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <Chapter>())) .ReturnsAsync(true); //Act var result = await _chapterCommandHandler.Handle(command, CancellationToken.None); //Assert Assert.Equal(chapterId, result); _autoMocker.VerifyAll(); }