Ejemplo n.º 1
0
        public async Task ReturnFailureForInvalidCardAndPlayerCombination()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var playersRepo   = PlayersRepositoryMock.Create().Object;
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.InProgress).Object;
            var cardsRepo = CreatePlayerCardsRepoMock(
                isCardLinkedWithUser: false);
            var questionCardRepo  = CreateQuestionCardRepoMock();
            var playerAnswersRepo = CreatePlayerAnswersRepository();

            var validator = new SubmitAnswerValidator(baseMock.Object, playersRepo, gameRoundRepo, cardsRepo, questionCardRepo, playerAnswersRepo);

            var request = new SubmitAnswer
            {
                GameRoundId  = MockConstants.RoundId,
                UserId       = 1,
                GameId       = 1,
                PlayerCardId = 1
            };

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.CardNotLinkedWithPlayer, result.Error);
        }
Ejemplo n.º 2
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var playersRepo   = PlayersRepositoryMock.Create().Object;
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.InProgress).Object;
            var cardsRepo         = CreatePlayerCardsRepoMock();
            var questionCardRepo  = CreateQuestionCardRepoMock();
            var playerAnswersRepo = CreatePlayerAnswersRepository();

            var validator = new SubmitAnswerValidator(baseMock.Object, playersRepo, gameRoundRepo, cardsRepo, questionCardRepo, playerAnswersRepo);

            var request = new SubmitAnswer
            {
                GameRoundId  = MockConstants.RoundId,
                UserId       = 1,
                GameId       = 1,
                PlayerCardId = 1
            };

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            baseMock.Verify(x => x.Validate(request));
        }
Ejemplo n.º 3
0
        public async Task ReturnFailureForMissingSecondPlayerCard()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var playersRepo   = PlayersRepositoryMock.Create().Object;
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.InProgress).Object;
            var cardsRepo        = CreatePlayerCardsRepoMock();
            var questionCardRepo = CreateQuestionCardRepoMock(
                isMultiChoiceQuestion: true);
            var playerAnswersRepo = CreatePlayerAnswersRepository();

            var validator = new SubmitAnswerValidator(baseMock.Object, playersRepo, gameRoundRepo, cardsRepo, questionCardRepo, playerAnswersRepo);

            var request = new SubmitAnswer
            {
                GameRoundId  = MockConstants.RoundId,
                UserId       = 1,
                GameId       = 1,
                PlayerCardId = 1
            };

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.SecondPlayerCardIdRequired, result.Error);
        }
Ejemplo n.º 4
0
        public async Task ReturnFailureForUserThatAlreadyJoined()
        {
            var baseMock    = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepo    = GamesRepositoryMock.Create().Object;
            var playersRepo = PlayersRepositoryMock.Create(
                playerExists: true).Object;
            var validator = new JoinGameValidator(baseMock.Object, gameRepo, playersRepo);

            var request = new JoinGame
            {
                GameId = 1,
                UserId = 1
            };

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.UserAlreadyJoined, result.Error);
        }
Ejemplo n.º 5
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock    = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepo    = GamesRepositoryMock.Create().Object;
            var playersRepo = PlayersRepositoryMock.Create(
                playerExists: false).Object;
            var validator = new JoinGameValidator(baseMock.Object, gameRepo, playersRepo);

            var request = new JoinGame
            {
                GameId = 1,
                UserId = 1
            };

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            baseMock.Verify(x => x.Validate(request));
        }
Ejemplo n.º 6
0
        public async Task ReturnSuccessForValidData()
        {
            var gameRoundRepoMock = GameRoundsRepositoryMock.Create();
            var playersRepoMock   = PlayersRepositoryMock.Create();

            var rule = new RoundOwnerRule(gameRoundRepoMock.Object, playersRepoMock.Object);

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

            var result = await rule.Validate(request);

            Assert.NotNull(result);
            Assert.True(result.IsSuccessful);
            Assert.Null(result.Error);
        }
Ejemplo n.º 7
0
        public async Task ReturnFailureForInvalidUser()
        {
            var gameRoundRepoMock = GameRoundsRepositoryMock.Create(
                isRoundOwner: false);
            var playersRepoMock = PlayersRepositoryMock.Create();

            var rule = new RoundOwnerRule(gameRoundRepoMock.Object, playersRepoMock.Object);

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

            var result = await rule.Validate(request);

            Assert.NotNull(result);
            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.InvalidUserAction, result.Error);
        }
        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));
        }