Ejemplo n.º 1
0
        public async Task <BaseResponse <MatchResponse> > Handle(DeleteMatchCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <MatchResponse>();
            var match    = _dbContext.Matches
                           .Where(m => m.IdUser == request.DeleteMatchRequest.IdUser)
                           .Where(m => m.IdAmigo == request.DeleteMatchRequest.IdUserAmigo);

            var matchAmigo = _dbContext.Matches
                             .Where(m => m.IdAmigo == request.DeleteMatchRequest.IdUser)
                             .Where(m => m.IdUser == request.DeleteMatchRequest.IdUserAmigo);

            if (!match.Any() || !matchAmigo.Any())
            {
                response.SetValidationErrors(new[] { "Pedido de Match não encontrado" });
            }
            else
            {
                var matchLista      = match.ToList();
                var matchAmigoLista = matchAmigo.ToList();

                _dbContext.Matches.Remove(matchLista[0]);
                _dbContext.Matches.Remove(matchAmigoLista[0]);

                await _dbContext.SaveChangesAsync(cancellationToken);

                response.SetIsOk(null);
            }

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(Application.Contracts.Match.DeleteMatchRequest deleteMatchRequest)
        {
            var command = new DeleteMatchCommand(deleteMatchRequest);
            var result  = await Mediator.Send(command);

            return(await ResponseBase(result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(DeleteMatchCommand command, int playWeekId)
        {
            await this.Mediator.Send(command);

            return(this.RedirectToAction(nameof(Details), new GetMatchesForPlayWeekQuery {
                PlayWeekId = playWeekId
            }));
        }
Ejemplo n.º 4
0
        public async Task Hanlde_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new DeleteMatchCommand {
                Id = 133
            };
            var sut = new DeleteMatchCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 5
0
        public async Task Hanlde_GivenValidRequest_ShouldDeleteMatch()
        {
            // Arrange
            var command = new DeleteMatchCommand {
                Id = 1
            };
            var sut = new DeleteMatchCommandHandler(this.deletableEntityRepository);

            // Act
            var matchId = await sut.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            matchId.ShouldBe(1);

            var matchModified = this.dbContext.Matches.SingleOrDefault(x => x.Id == matchId);

            matchModified.IsDeleted.ShouldBe(true);
        }