public ActionResult Delete(int chapterId)
        {
            var command = new DeleteChapterCommand(chapterId);

            return(deleteChapterCommandHandler.Handle(command)
                   .OnBoth((result) =>
            {
                return responseHandler.GetSimpleResponse(result);
            }));
        }
        public async Task Handle_ValidChapterData_ChapterShouldNotFound()
        {
            //Arrange
            var chapterId = Guid.NewGuid();
            var command   = new DeleteChapterCommand(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();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> DeleteChapter(
            [FromRoute] ChapterReference reference,
            CancellationToken cancellationToken)
        {
            var command = new DeleteChapterCommand(reference.SagaId, reference.ChapterId);

            try
            {
                await _sender.Send(command, cancellationToken);
            }
            catch (ChapterNotFoundException e)
            {
                return(NotFound(e.Message));
            }

            return(NoContent());
        }
        public async Task Handle_ValidChapterData_ShouldSuccess()
        {
            //Arrange
            var chapterId = Guid.NewGuid();
            var command   = new DeleteChapterCommand(chapterId);

            _chapterRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Chapter> >()))
            .ReturnsAsync(true);
            _chapterRepositoryMock.Setup(x => x.DeleteAsync(It.IsAny <ISpecification <Chapter> >()))
            .ReturnsAsync(true);

            _sendEndpointProviderMock = _autoMocker.GetMock <ISendEndpointProvider>();
            _sendEndpointProviderMock.Setup(x => x.GetSendEndpoint(It.IsAny <Uri>()))
            .Returns(Task.FromResult(_sendEndpointMock.Object));
            //TODO: How to mock?
            //_sendEndpointProviderMock.Setup(x => x.Send(It.IsAny<DeleteChapterMessage>(), It.IsAny<CancellationToken>()));
            //Act

            var result = await _chapterCommandHandler.Handle(command, CancellationToken.None);

            //Assert
            Assert.True(result);
            _autoMocker.VerifyAll();
        }