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 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(); }