public void PlayHandWhenInFinalStateShouldNotChangeGameState()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     roundState.PlayHand(0);
     haveStateMock.Verify(x => x.SetState(It.IsAny<BaseRoundState>()), Times.Never);
 }
 public void SetStateShouldChangeTheState()
 {
     var stateManager = new StateManager();
     var state = new FinalRoundState(stateManager);
     stateManager.SetState(state);
     Assert.AreEqual(state, stateManager.State);
 }
        public void CanChangeTrumpShouldReturnFalseWhenThePlayerIsFirstButTheStateDoesNotPermitChanging()
        {
            var haveStateMock = new Mock<IStateManager>();
            var roundState = new FinalRoundState(haveStateMock.Object);

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

            var canCloseGame = CloseGameActionValidator.CanCloseGame(false, roundState);
            Assert.IsFalse(canCloseGame);
        }
 public void CloseShouldNotChangeGameState()
 {
     // It is not allowed to close the game in this state
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     roundState.Close();
     haveStateMock.Verify(x => x.SetState(It.IsAny<BaseRoundState>()), Times.Never);
 }
 public void PlayingCardFromHandShouldBeValid()
 {
     var cards = new List<Card>() { new Card(CardSuit.Club, CardType.Ace) };
     var action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Club, CardType.Ace), Announce.None);
     var state = new FinalRoundState();
     var context = new PlayerTurnContext(state, new Card(CardSuit.Club, CardType.Jack), 0);
     
     Assert.IsTrue(validator.IsValid(action, context, cards));
 }
        public void PlayingCardThatsNotInHandShouldBeInvalid()
        {
            var cards = new List<Card>() { new Card(CardSuit.Diamond, CardType.Jack) };
            var action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Club, CardType.Jack), Announce.None);
            var state = new FinalRoundState();
            var context = new PlayerTurnContext(state, new Card(CardSuit.Club, CardType.Jack), 0);

            Assert.IsFalse(this.validater.IsValid(action, context, cards));
        }
 public void WhenInFinalStateItIsNotPossibleToCloseTheGame()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     Assert.IsFalse(roundState.CanClose);
 }
        public void ValidActionWithTrumpCardShouldBeEvaluatedCorrectly()
        {
            FinalRoundState endRound = new FinalRoundState();
            PlayerTurnContext context = new PlayerTurnContext(endRound, new Card(CardSuit.Spade, CardType.Jack), 0);
            context.FirstPlayedCard = new Card(CardSuit.Club, CardType.Nine);
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Spade, 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.Diamond, CardType.King),
                new Card(CardSuit.Spade, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsTrue(validator.IsValid(action, context, cards));
        }
        public void InvalidPlayerCardWithoutTrumpShouldBeEvaluаtedCorrectly()
        {
            FinalRoundState finalState = new FinalRoundState();
            PlayerTurnContext context = new PlayerTurnContext(finalState, new Card(CardSuit.Diamond, CardType.Jack), 0);
            context.FirstPlayedCard = new Card(CardSuit.Club, CardType.Ten);
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Spade, CardType.Queen), Announce.Twenty);
            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.Spade, CardType.Nine),
                new Card(CardSuit.Spade, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void ConstructorShouldSetProperties()
        {
            var haveStateMock = new Mock<IStateManager>();
            var state = new FinalRoundState(haveStateMock.Object);
            var trumpCard = new Card(CardSuit.Heart, CardType.Ten);
            const int CardsLeftInDeck = 10;

            var playerTurnContext = new PlayerTurnContext(state, trumpCard, CardsLeftInDeck, 0, 0);

            Assert.AreEqual(state, playerTurnContext.State);
            Assert.AreEqual(trumpCard, playerTurnContext.TrumpCard);
            Assert.AreEqual(CardsLeftInDeck, playerTurnContext.CardsLeftInDeck);
        }
 public void WhenInFinalStateRulesShouldBeObserved()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     Assert.IsTrue(roundState.ShouldObserveRules);
 }
 public void WhenInFinalStateNoMoreCardsShouldBeDrawn()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     Assert.IsFalse(roundState.ShouldDrawCard);
 }
 public void WhenInFinalStateItIsPossibleToAnnounce20Or40()
 {
     var haveStateMock = new Mock<IStateManager>();
     var roundState = new FinalRoundState(haveStateMock.Object);
     Assert.IsTrue(roundState.CanAnnounce20Or40);
 }
        public void TestInvalidMoveCardWithLowerValueWhenHaveBigger()
        {
            FinalRoundState finalState = new FinalRoundState();

            PlayerTurnContext context = new PlayerTurnContext(finalState, new Card(CardSuit.Diamond, CardType.Jack), 0);

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

            // You must play card with bigger value.
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, 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 TestInvalidPlayedCard()
        {
            FinalRoundState endState = new FinalRoundState();

            PlayerTurnContext context = new PlayerTurnContext(endState, new Card(CardSuit.Spade, CardType.Jack), 0);

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

            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Heart, CardType.Queen), 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.King),
                new Card(CardSuit.Spade, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void TestWithIncorrectTrumpCard()
        {
            FinalRoundState finalState = new FinalRoundState();

            PlayerTurnContext context = new PlayerTurnContext(finalState, new Card(CardSuit.Diamond, CardType.Jack), 0);

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

            // You have a needed suit card but played trump. False -> Must play Club
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Diamond, 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.King),
                new Card(CardSuit.Spade, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }
        public void TestValidMoveWithTrumpCard()
        {
            // Using this state to enter in context.State.ShouldObserveRules.
            FinalRoundState endRound = new FinalRoundState();

            PlayerTurnContext context = new PlayerTurnContext(endRound, new Card(CardSuit.Spade, CardType.Jack), 0);

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

            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Spade, 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.Diamond, CardType.King),
                new Card(CardSuit.Spade, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Nine)
            };

            Assert.IsTrue(validator.IsValid(action, context, cards));
        }
        public void TestOtherCardWhenNoHaveTrump()
        {
            FinalRoundState finalState = new FinalRoundState();

            PlayerTurnContext context = new PlayerTurnContext(finalState, new Card(CardSuit.Diamond, CardType.Jack), 0);

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

            // Have a club, but played Spade. False. Must play Club
            PlayerAction action = new PlayerAction(PlayerActionType.PlayCard, new Card(CardSuit.Spade, CardType.Queen), Announce.Twenty);
            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.Spade, CardType.Nine),
                new Card(CardSuit.Spade, CardType.Nine)
            };

            Assert.IsFalse(validator.IsValid(action, context, cards));
        }