Exemplo n.º 1
0
        public async Task <ActionResult> RemovePlayer(Guid teamId, [FromBody] RemovePlayerCommand buyPlayerCommand)
        {
            buyPlayerCommand.TeamId = teamId;
            await _commandHandler.RemovePlayer(buyPlayerCommand);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <RemovePlayerResponse> Handle(RemovePlayerRequest request, CancellationToken cancellationToken)
        {
            var query = new GetPlayerByIdQuery()
            {
                Id = request.PlayerId
            };
            var player = await this.queryExecutor.Execute(query);

            if (player == null)
            {
                return new RemovePlayerResponse()
                       {
                           Data = null
                       }
            }
            ;
            var command = new RemovePlayerCommand()
            {
                Parameter = player
            };
            var removedPlayer = await this.commandExecutor.Execute(command);

            return(new RemovePlayerResponse()
            {
                Data = this.mapper.Map <Domain.Models.Player>(removedPlayer)
            });
        }
    }
Exemplo n.º 3
0
        public async Task Handle_GivenValidRequest_ShouldAddPlayerToTeam()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "Foo5"
            };

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            this.dbContext.Add(new PlayerTeam {
                TeamId = 1, PlayerId = "Foo5"
            });
            this.dbContext.SaveChanges();

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

            // Assert
            affectedRows.ShouldBeGreaterThan(0);

            var isPlayerRemoved = this.dbContext.PlayerTeams.Any(x => x.PlayerId == "Foo5" && x.TeamId == 1 && !x.IsDeleted);

            isPlayerRemoved.ShouldBe(false);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RemovePlayer(RemovePlayerCommand command)
        {
            await this.Mediator.Send(command);

            return(this.RedirectToAction(nameof(Modify), new ModifyTeamQuery {
                Id = command.TeamId
            }));
        }
Exemplo n.º 5
0
        public void Handle(RemovePlayerCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Player player = dbContext.Players.SingleOrDefault(l => l.Id == command.PlayerId);

                dbContext.Players.Remove(player);
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "InvalidId"
            };

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Exemplo n.º 7
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowOwnerOfAMustTransferOwnerShipBeforeLeavingTeamException()
        {
            // Arrange
            var command = new RemovePlayerCommand {
                TeamId = 1, PlayerId = "Foo1"
            };

            this.dbContext.PlayerTeams.Add(new PlayerTeam {
                PlayerId = "Foo5", TeamId = 1
            });
            this.dbContext.SaveChanges();

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");
            var sut = new RemovePlayerCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <OwnerOfAMustTransferOwnerShipBeforeLeavingTeamException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Leave(RemovePlayerCommand command)
        {
            await this.Mediator.Send(command);

            return(this.LocalRedirect("/"));
        }
        public ActionResult RemovePlayer(RemovePlayerCommand command)
        {
            HandleCommand(command, Json("Player removed"));

            return(RedirectToAction("PlayersManage"));
        }
        public CommandResult <SwissTournamentContext> ProcessCommand(SwissTournamentContext context, RemovePlayerCommand command)
        {
            // Don't allow a player not in the tournament to drop
            if (!context.Players.Contains(command.Player))
            {
                return(new CommandRejectedResult <SwissTournamentContext>(context, "Player not in tournament"));
            }

            // Don't allow a player that has already dropped to drop
            if (command.Player.RoundDropped.HasValue)
            {
                return(new CommandRejectedResult <SwissTournamentContext>(context, "Player already dropped"));
            }

            // If the tournament hasn't started, remove the player from the list of players.
            // Otherwise flag the player as dropped
            if (context.State == TournamentState.TournamentCreated)
            {
                return(new CommandAcceptedResult <SwissTournamentContext>(
                           new SwissTournamentContext(
                               context,
                               players: context
                               .Players
                               .Except(command.Player)
                               )
                           ));
            }
            else
            {
                return(new CommandAcceptedResult <SwissTournamentContext>(
                           new SwissTournamentContext(
                               context,
                               players: context
                               .Players
                               .Replace(command.Player, new Player(command.Player.Identifier, context.ActiveRound))
                               )
                           ));
            }
        }
Exemplo n.º 11
0
        public async Task <ActionResult> Remove(RemovePlayerCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
Exemplo n.º 12
0
        public async Task <CommandResult> Remove(Guid id)
        {
            var removeCommand = new RemovePlayerCommand();

            return(await _mediator.EnviarComando(removeCommand));
        }