Exemplo n.º 1
0
        public async Task <StartGameRoundResult> Handle(StartGameRound request, CancellationToken cancellationToken)
        {
            using (var transaction = repositoryTransactionsFactory.CreateTransaction())
            {
                var validatorResult = await validator.Validate(request);

                if (!validatorResult.IsSuccessful)
                {
                    return(new StartGameRoundResult(validatorResult.Error));
                }

                var started = await gameRoundsRepository
                              .UpdateGameRoundStatus(request.GameRoundId, Common.Enums.GameRoundStatusEnum.InProgress);

                if (!started)
                {
                    return(new StartGameRoundResult(GameErrors.GameRoundCouldNotBeStarted));
                }

                var checkpoint = await gameCheckpointUpdater.Update(request.GameId, nameof(StartGameRound));

                transaction.CommitTransaction();

                return(new StartGameRoundResult());
            }
        }
        public async Task ReturnFailureForInvalidRoundStatus()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var playersRepo   = PlayersRepositoryMock.Create().Object;
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.Finished).Object;
            var gameOrRoundOnwerRuleMock = GameOrRoundOwnerRuleMock.Create <StartGameRound>();

            var validator = new StartGameRoundValidator(baseMock.Object, playersRepo, gameRoundRepo, gameOrRoundOnwerRuleMock.Object);

            var request = new StartGameRound
            {
                GameRoundId = 1,
                UserId      = 1,
                GameId      = 1
            };

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.InvalidGameRoundStatus, result.Error);
        }
        public async Task ReturnSuccessForValidData()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var playersRepo   = PlayersRepositoryMock.Create().Object;
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.Pending).Object;
            var gameOrRoundOnwerRuleMock = GameOrRoundOwnerRuleMock.Create <StartGameRound>();

            var validator = new StartGameRoundValidator(baseMock.Object, playersRepo, gameRoundRepo, gameOrRoundOnwerRuleMock.Object);

            var request = new StartGameRound
            {
                GameRoundId = 1,
                UserId      = 1,
                GameId      = 1
            };

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            baseMock.Verify(x => x.Validate(request));
            gameOrRoundOnwerRuleMock.Verify(x => x.Validate(request));
        }