Ejemplo n.º 1
0
 public void DeletePost(int id)
 {
     DeletePostCommand.Execute(new
     {
         Id = id
     });
 }
Ejemplo n.º 2
0
        private dynamic DeletePost(DeletePostCommand deletePostCommand)
        {
            _commandInvokerFactory.Handle <DeletePostCommand, CommandResult>(deletePostCommand);
            string returnURL = Request.Headers.Referrer;

            return(Response.AsRedirect(returnURL));
        }
Ejemplo n.º 3
0
        public async Task ShouldRequireMinimunFields()
        {
            await RunAsDefaultUserAsync();

            var command = new DeletePostCommand();

            FluentActions.Invoking(() => SendAsync(command))
            .Should().Throw <ValidationException>();
        }
        public async Task <IActionResult> DeletePost([FromRoute] int id)
        {
            var command = new DeletePostCommand()
            {
                Id = id
            };

            return(Ok(await mediator.Send(command)));
        }
Ejemplo n.º 5
0
    public void DeletePost(int id)
    {
        bool authorIsCaller = IsPostAuthorMatch <bool> .Execute(new { post.Author });

        if (authorIsCaller)
        {
            DeletePostCommand.Execute(new { Id = id });
        }
    }
Ejemplo n.º 6
0
 public virtual async Task <IActionResult> Delete(int id)
 {
     return(await Runsafely(async() =>
     {
         var deletePostCommand = new DeletePostCommand(id);
         var commandResult = await _mediator.Send(deletePostCommand);
         return commandResult ? Ok() : BadRequest();
     }));
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> Delete(int id)
        {
            var deletepostCommand = new DeletePostCommand()
            {
                PostId = id
            };
            await _mediator.Send(deletepostCommand);

            return(NoContent());
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Delete(int id, DeletePostCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await _mediator.Send(command);

            return(NoContent());
        }
Ejemplo n.º 9
0
        private void ConfirmDelete(int postID)
        {
            var page = (AdminPage)Page;

            if (page != null)
            {
                var command = new DeletePostCommand(Repository, postID, page.SearchEngine);
                command.Execute();
                BindList();
            }
        }
Ejemplo n.º 10
0
 public ResultDto DeletePost(long id)
 {
     return(Result(() =>
     {
         var command = new DeletePostCommand
         {
             PostId = id,
         };
         CommandDispatcher.Send(command);
     }));
 }
Ejemplo n.º 11
0
 public CommandsController(
     ApplicationDbContext context,
     HashtagFinder hashtagFinder,
     IHostingEnvironment appEnvironment, UserManager <ApplicationUser> userManager)
 {
     _userManager       = userManager;
     _putLikeCommand    = new PutLikeCommand(context);
     _followCommand     = new FollowCommand(context);
     _createPostCommand = new CreatePostCommand(context, hashtagFinder, appEnvironment);
     _deletePostCommand = new DeletePostCommand(context, appEnvironment);
 }
        public void ShouldNotCallHandleIfPostNotExist()
        {
            dbSetPost.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Posts).Returns(dbSetPost.Object);

            DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object);
            DeletePostCommand        deletePostCommand        = new DeletePostCommand(id);

            Func <Task> act = async() => await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken());

            act.Should().Throw <NotFoundException>();
        }
        public async Task ShouldCallHandle()
        {
            dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post)));
            context.Setup(x => x.Posts).Returns(dbSetPost.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1));

            DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object);
            DeletePostCommand        deletePostCommand        = new DeletePostCommand(id);

            var result = await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> DeleteAsync([FromRoute] Guid postId)
        {
            var command = new DeletePostCommand(postId);

            var deleted = await _mediator.Send(command);

            if (!deleted)
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public void ShouldNotCallHandleIfNotSavedChanges()
        {
            dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post)));
            context.Setup(x => x.Posts).Returns(dbSetPost.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0));

            DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object);
            DeletePostCommand        deletePostCommand        = new DeletePostCommand(id);

            Func <Task> act = async() => await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken());

            act.Should().Throw <RestException>();
        }
Ejemplo n.º 16
0
        public void ShouldThrowNotFoundWhenPostIdIsIncorrect()
        {
            //arrange
            var deletepostCommand = new DeletePostCommand {
                Id = Guid.NewGuid()
            };

            //act

            //assert
            FluentActions.Invoking(() =>
                                   SendAsync(deletepostCommand)).Should().Throw <NotFoundException>();
        }
Ejemplo n.º 17
0
        public void Handler_GivenInvalidPostId_ThrowsException()
        {
            // Arrange
            var invalidPostId = 99;

            // Act
            var command = new DeletePostCommand {
                Id = invalidPostId
            };
            var handler = new DeletePostCommand.DeletePostCommandHandler(Context);

            // Assert
            Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Delete Post.
        /// </summary>
        /// <param name="id">Post identifier</param>
        /// <returns>Delete current post and redirect to page with posts.</returns>
        public async Task <IActionResult> Delete(int id, string returnUrl = default)
        {
            var postCommand = new DeletePostCommand {
                Id = id
            };
            await _mediator.Send(postCommand);

            if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
            {
                return(RedirectToAction("Index", "Posts"));
            }
            else
            {
                return(RedirectToAction(returnUrl));
            }
        }
Ejemplo n.º 19
0
        public async Task Handler_GivenValidPostId_ShouldRemovePost()
        {
            // Arrange
            var validPostId = 2;

            // Act
            var command = new DeletePostCommand {
                Id = validPostId
            };
            var handler = new DeletePostCommand.DeletePostCommandHandler(Context);
            await handler.Handle(command, CancellationToken.None);

            // Assert
            var entity = Context.Posts.Find(command.Id);

            entity.ShouldBeNull();
        }
        public async Task <ResponseModel <bool> > Handle(DeletePostCommand request, CancellationToken cancellationToken)
        {
            var response = new ResponseModel <bool>()
            {
                Status       = HttpStatusCode.InternalServerError,
                IsSuccessful = false,
                Result       = false,
                Errors       = default
            };

            try
            {
                var post = await _postRepository.GetById(request.Id);

                if (post is null)
                {
                    _logger.LogWarning($"{request.Id} is deleted");
                    return(_customExceptionBuilder.BuildEntityNotFoundException(response, request.Id, ErrorTypes.EntityNotFound));
                }

                await _postRepository.DeleteAsync(post);

                response.Status       = HttpStatusCode.OK;
                response.IsSuccessful = true;
                response.Result       = true;

                return(response);
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, e.StackTrace, "Method : DeletePostCommandHandler - Handle");
            }

            response.Errors = new List <ErrorResponse>()
            {
                new ErrorResponse()
                {
                    Reason  = 500,
                    Message = "An unexpected error occured"
                }
            };

            return(response);
        }
        public async Task <IActionResult> Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiBadRequestResponse(ModelState)));
            }

            var command  = new DeletePostCommand(id);
            var handler  = _factory.Build(command);
            var response = await handler.Execute();

            if (response.Success)
            {
                return(Ok(id));
            }
            else
            {
                return(BadRequest(new ApiResponse(500)));
            }
        }
 public ICommandHandler <DeletePostCommand, CommandResponse> Build(DeletePostCommand command)
 {
     return(new DeletePostCommandHandler(_serviceProvider.GetService <IPostsRepository>(), command));
 }
Ejemplo n.º 23
0
        public async Task <bool> Delete(long id)
        {
            DeletePostCommand command = new DeletePostCommand(id);

            return(await _bus.SendCommandAsync(command));
        }
Ejemplo n.º 24
0
 public async Task <ActionResult> Delete(
     [FromRoute] DeletePostCommand command)
 => await this.Send(command);
Ejemplo n.º 25
0
 public async Task <ActionResult> Delete([FromBody] DeletePostCommand command)
 => Ok(await Handle(command));
Ejemplo n.º 26
0
 public async Task Delete([FromBody] DeletePostCommand command) =>
 await new DeletePostCommandHandler(persistence).Handle(command);
Ejemplo n.º 27
0
 private dynamic DeletePost(DeletePostCommand deletePostCommand)
 {
     _commandInvokerFactory.Handle<DeletePostCommand, CommandResult>(deletePostCommand);
     string returnURL = Request.Headers.Referrer;
     return Response.AsRedirect(returnURL);
 }
 public Task Delete(
     [FromRoute] DeletePostCommand command)
 => Mediator.Send(command);
Ejemplo n.º 29
0
 public async Task Handle(DeletePostCommand cmd)
 {
     await _blogRepository.Delete(cmd.Id);
 }
Ejemplo n.º 30
0
        public async Task <ActionResult <bool> > DeletePostAsync([FromBody] DeletePostCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(result)));
        }
Ejemplo n.º 31
0
        public async Task <IActionResult> Delete(DeletePostCommand command)
        {
            var result = await mediator.Send(command);

            return(RedirectToAction(nameof(Index)));
        }