예제 #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);
        }
예제 #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));
        }
예제 #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);
        }
예제 #4
0
        public async Task ReturnFailureForMissingName()
        {
            var baseMock  = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepo  = GamesRepositoryMock.Create().Object;
            var validator = new CreateGameValidator(baseMock.Object, gameRepo);

            var request = new CreateGame
            {
                LanguageId       = 1,
                UserId           = 1,
                ShowAdultContent = true
            };

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.GameNameRequired, result.Error);
        }
예제 #5
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);
        }
예제 #6
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));
        }
예제 #7
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock  = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepo  = GamesRepositoryMock.Create().Object;
            var validator = new CreateGameValidator(baseMock.Object, gameRepo);

            var request = new CreateGame
            {
                LanguageId       = 1,
                Name             = "Test",
                UserId           = 1,
                ShowAdultContent = true
            };

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            Assert.Null(result.Error);
            baseMock.Verify(x => x.Validate(request));
        }
예제 #8
0
        public async Task ReturnFailureForInvalidStatus(Common.Enums.GameStatusEnum gameStatus)
        {
            var baseMock     = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepoMock = GamesRepositoryMock.Create(
                gameStatus: gameStatus);
            var gameOwnerRuleMock = GameOwnerRuleMock.Create <CancelGame>();

            var validator = new CancelGameValidator(baseMock.Object, gameOwnerRuleMock.Object, gameRepoMock.Object);

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

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.GameNotFoundOrInactive, result.Error);
        }
예제 #9
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock          = BaseGameRequestsValidatorMock.CreateMock();
            var gameRepoMock      = GamesRepositoryMock.Create();
            var gameOwnerRuleMock = GameOwnerRuleMock.Create <CancelGame>();

            var validator = new CancelGameValidator(baseMock.Object, gameOwnerRuleMock.Object, gameRepoMock.Object);

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

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            baseMock.Verify(x => x.Validate(request));
            gameOwnerRuleMock.Verify(x => x.Validate(request));
        }
        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);
        }
예제 #11
0
        public async Task ReturnFailureForInactiveRound()
        {
            var baseMock          = BaseGameRequestsValidatorMock.CreateMock();
            var gameRoundRepoMock = GameRoundsRepositoryMock.Create(
                isRoundActive: false);
            var gameOwnerRuleMock = GameOrRoundOwnerRuleMock.Create <SkipRound>();

            var validator = new SkipRoundValidator(baseMock.Object, gameRoundRepoMock.Object, gameOwnerRuleMock.Object);

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

            var result = await validator.Validate(request);

            Assert.NotNull(result);
            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.InvalidGameRoundStatus, result.Error);
        }
예제 #12
0
        public async Task ReturnSuccessForValidData(GameRoundStatusEnum gameRoundStatus)
        {
            var baseMock          = BaseGameRequestsValidatorMock.CreateMock();
            var gameRoundRepoMock = GameRoundsRepositoryMock.Create(
                status: gameRoundStatus);
            var gameOwnerRuleMock = GameOrRoundOwnerRuleMock.Create <SkipRound>();

            var validator = new SkipRoundValidator(baseMock.Object, gameRoundRepoMock.Object, gameOwnerRuleMock.Object);

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

            var result = await validator.Validate(request);

            Assert.True(result.IsSuccessful);
            baseMock.Verify(x => x.Validate(request));
            gameOwnerRuleMock.Verify(x => x.Validate(request));
        }
예제 #13
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock      = BaseGameRequestsValidatorMock.CreateMock();
            var gameRoundRepo = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.InProgress).Object;
            var playerAnswersRepo        = PlayerAnswersRepositoryMock.Create().Object;
            var gameOrRoundOnwerRuleMock = GameOrRoundOwnerRuleMock.Create <EndSubmissions>();

            var validator = new EndSubmissionsValidator(baseMock.Object, gameRoundRepo, playerAnswersRepo, gameOrRoundOnwerRuleMock.Object);

            var request = new EndSubmissions
            {
                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));
        }
예제 #14
0
        public async Task ReturnFailureForInactiveAnsweringPlayer()
        {
            var baseMock          = BaseGameRequestsValidatorMock.CreateMock();
            var playerAnswersRepo = PlayerAnswersRepositoryMock.Create(
                isAnsweringPlayerActive: false).Object;
            var roundOnwerRuleMock  = RoundOwnerRuleMock.Create <SelectAnswer>();
            var gameRoundRepository = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.Selection).Object;

            var validator = new SelectAnswerValidator(baseMock.Object, roundOnwerRuleMock.Object, playerAnswersRepo, gameRoundRepository);

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

            var result = await validator.Validate(request);

            Assert.False(result.IsSuccessful);
            Assert.Equal(ValidatorErrors.Games.SelectedAnswerPlayerIsNotActive, result.Error);
        }
예제 #15
0
        public async Task ReturnSuccessForValidData()
        {
            var baseMock            = BaseGameRequestsValidatorMock.CreateMock();
            var playerAnswersRepo   = PlayerAnswersRepositoryMock.Create().Object;
            var roundOnwerRuleMock  = RoundOwnerRuleMock.Create <SelectAnswer>();
            var gameRoundRepository = GameRoundsRepositoryMock.Create(
                status: Common.Enums.GameRoundStatusEnum.Selection).Object;

            var validator = new SelectAnswerValidator(baseMock.Object, roundOnwerRuleMock.Object, playerAnswersRepo, gameRoundRepository);

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

            var result = await validator.Validate(request);

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