public void PlayHandWithMoreThan2CardsLeftShouldNotChangeTheState()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     roundState.PlayHand(4);
     haveStateMock.Verify(x => x.SetState(It.IsAny<BaseRoundState>()), Times.Never);
 }
 public void PlayHandWith2CardsLeftShouldChangeTheStateToTwoCardsLeftRoundState()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     roundState.PlayHand(2);
     haveStateMock.Verify(x => x.SetState(It.IsAny<TwoCardsLeftRoundState>()), Times.Once);
 }
 public void CloseShouldMoveTheGameToTheFinalRoundState()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     roundState.Close();
     haveStateMock.Verify(x => x.SetState(It.IsAny<FinalRoundState>()), Times.Once);
 }
        public void CanChangeTrumpShouldReturnTrueWhenThePlayerIsFirstTheStatePermitsChangingAndNineOfTrumpsIsPresent()
        {
            var haveStateMock = new Mock<IStateManager>();
            var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);

            var canChangeTrump = ChangeTrumpActionValidator.CanChangeTrump(true, roundState, TrumpThatCanBeChanged, PlayerCards);
            Assert.IsTrue(canChangeTrump);
        }
        public void CanCloseGameShouldReturnTrueWhenThePlayerIsFirsAndTheStatePermitsClosing()
        {
            var haveStateMock = new Mock<IStateManager>();
            var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);

            var canCloseGame = CloseGameActionValidator.CanCloseGame(true, roundState);
            Assert.IsTrue(canCloseGame);
        }
        public void CanChangeTrumpShouldReturnFalseWhenThePlayerIsNotFirstButTheStatePermitsChanging()
        {
            var haveStateMock = new Mock<IStateManager>();
            var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);

            var canChangeTrump = ChangeTrumpActionValidator.CanChangeTrump(false, roundState, TrumpThatCanBeChanged, PlayerCards);
            Assert.IsFalse(canChangeTrump);
        }
        public void PlayerChangesTrumpWithQueen_ShouldBeInvalid()
        {
            var cards = new List<Card>() { new Card(CardSuit.Club, CardType.Queen) };
            var action = new PlayerAction(PlayerActionType.ChangeTrump, new Card(CardSuit.Club, CardType.Queen), Announce.None);
            var round = new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer);
            var state = new MoreThanTwoCardsLeftRoundState(round);
            var context = new PlayerTurnContext(state, new Card(CardSuit.Club, CardType.Jack), 0);

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void FourtyAnnounce_ShouldBeValid()
        {
            var cards = new List<Card>() { new Card(CardSuit.Club, CardType.Queen), new Card(CardSuit.Club, CardType.King) };
            var announce = Announce.Fourty;
            var action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Club, CardType.Queen), announce);
            var round = new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer);
            var state = new MoreThanTwoCardsLeftRoundState(round);
            var context = new PlayerTurnContext(state, new Card(CardSuit.Club, CardType.Jack), 0);
            validator.IsValid(action, context, cards);

            Assert.AreEqual(Announce.Fourty, announce);
        }
        public void AnnouncingAtFirstHandShouldBeValid()
        {
            MoreThanTwoCardsLeftRoundState stateOfMiddle = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Heart, CardType.King), Announce.Twenty);
            PlayerTurnContext context = new PlayerTurnContext(stateOfMiddle, new Card(CardSuit.Spade, CardType.Jack), 6);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Queen),
                new Card(CardSuit.Heart, CardType.King),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Club, CardType.King),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            validator.IsValid(action, context, cards);
            Assert.AreEqual(Announce.None, action.Announce);
        }
        public void TestAnnounceFourty()
        {
            MoreThanTwoCardsLeftRoundState stateOfMiddle = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));

            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Spade, CardType.King), Announce.Fourty);
            PlayerTurnContext context = new PlayerTurnContext(stateOfMiddle, new Card(CardSuit.Spade, CardType.Jack), 6);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Queen),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Club, CardType.King),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            // a card is played. Just to avoid context.AmITheFirstPlayer;
            context.FirstPlayedCard = new Card(CardSuit.Club, CardType.King);

            validator.IsValid(action, context, cards);
            Assert.AreEqual(Announce.Fourty, action.Announce);
        }
        public void TestWrongChangeTrumpIfYouHaveNotNeededCard()
        {
            MoreThanTwoCardsLeftRoundState midle = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));

            PlayerTurnContext context = new PlayerTurnContext(midle, new Card(CardSuit.Diamond, CardType.Jack), 6);

            PlayerAction action = new PlayerAction(PlayerActionType.ChangeTrump, new Card(CardSuit.Club, CardType.Nine), Announce.None);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Queen),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Club, CardType.Ace),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Ace)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void ValidChangeOfTrumpCardShouldBeEvaluatedCorrectly()
        {
            MoreThanTwoCardsLeftRoundState midle = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));
            PlayerTurnContext context = new PlayerTurnContext(midle, new Card(CardSuit.Diamond, CardType.Ten), 6);
            PlayerAction action = new PlayerAction(PlayerActionType.ChangeTrump, new Card(CardSuit.Club, CardType.Nine), Announce.None);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Queen),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Club, CardType.Ace),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsTrue(validator.IsValid(action, context, cards));
        }
        public void PlayingWithCardThatIsNotInHandShouldBeInvalid()
        {
            MoreThanTwoCardsLeftRoundState middleState = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Diamond, CardType.Ace), Announce.None);
            PlayerTurnContext context = new PlayerTurnContext(middleState, new Card(CardSuit.Spade, CardType.Jack), 6);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Ten),
                new Card(CardSuit.Heart, CardType.King),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Club, CardType.King),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void FourtyAnnounceWhenPlayerIsNotFirstShouldChangeAnnounceToNone()
        {
            var cards = new List<Card>() { new Card(CardSuit.Club, CardType.Queen), new Card(CardSuit.Club, CardType.King), new Card(CardSuit.Heart, CardType.Jack) };
            var announce = Announce.Fourty;
            var action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Heart, CardType.Jack), announce);
            var round = new GameRound(new Player(), new Player(), PlayerPosition.SecondPlayer);
            var state = new MoreThanTwoCardsLeftRoundState(round);
            var context = new PlayerTurnContext(state, new Card(CardSuit.Club, CardType.Jack), 0);
            this.validater.IsValid(action, context, cards);

            Assert.AreEqual(Announce.None, action.Announce);
        }
 public void InTheMiddleOfTheGameCardShouldBeDrawn()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     Assert.IsTrue(roundState.ShouldDrawCard);
 }
        public void TestSimpleValidAction()
        {
            // PlayerActionValidater validato2r = new PlayerActionValidater();
            MoreThanTwoCardsLeftRoundState middleState = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));

            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Heart, CardType.King), Announce.None);
            PlayerTurnContext context = new PlayerTurnContext(middleState, new Card(CardSuit.Spade, CardType.Jack), 6);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Ten),
                new Card(CardSuit.Heart, CardType.King),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Club, CardType.King),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsTrue(validator.IsValid(action, context, cards));
        }
        public void TestInvalidClosingGameInMiddleRound()
        {
            MoreThanTwoCardsLeftRoundState middle = new MoreThanTwoCardsLeftRoundState(new GameRound(new Player(), new Player(), PlayerPosition.FirstPlayer));

            PlayerTurnContext context = new PlayerTurnContext(middle, new Card(CardSuit.Diamond, CardType.Jack), 6);

            context.FirstPlayedCard = new Card(CardSuit.Club, CardType.King);

            // Cannot Close game because it's already played a card.
            PlayerAction action = new PlayerAction(PlayerActionType.CloseGame, new Card(CardSuit.Club, CardType.Nine), Announce.None);
            IList<Card> cards = new List<Card>()
            {
                new Card(CardSuit.Spade, CardType.Queen),
                new Card(CardSuit.Spade, CardType.King),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Club, CardType.Ace),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
 public void InTheMiddleOfTheGameItIsPossibleToCloseTheGame()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     Assert.IsTrue(roundState.CanClose);
 }
 public void InTheMiddleOfTheGameRulesShouldNotBeObserved()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new MoreThanTwoCardsLeftRoundState(haveStateMock.Object);
     Assert.IsFalse(roundState.ShouldObserveRules);
 }