public void SplitHandTest()
        {
            BlackJackHand hand = new BlackJackHand(false);
            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Jack));
            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Queen));
            Assert.IsTrue(hand.IsSplittingAllowed);

            BlackJackHand handSplitted = hand.SplitHand();
            Assert.IsNotNull(handSplitted);
            Assert.AreNotSame(handSplitted, hand);

            Assert.IsFalse(hand.IsSplittingAllowed);
            Assert.IsFalse(handSplitted.IsSplittingAllowed);

            try
            {
                hand.SplitHand();
                Assert.Fail("Should have thrown InvalidGameException as hand is already splitted.");
            }
            catch (InvalidGameActionException igaEx)
            {
            }
        }
Beispiel #2
0
 /// <summary>
 /// Splits hand of the player.
 /// </summary>
 /// <param name="hand">Hand being splitted.</param>
 /// <exception cref="InvalidOperationException">Thrown when hand is not in state when it's allowed to split. Check IsSplitAllowed property to check whether splitting is allowed or not.</exception>
 public void Split(BlackJackHand hand)
 {
     if (!this.IsSplitted)
     {
         if (hand.IsSplittingAllowed)
         {
             SplittedHand = hand.SplitHand();
         }
         else
         {
             throw new InvalidGameActionException("Splitting not allowed for the hand.");
         }
     }
     else
     {
         throw new InvalidGameActionException("Splitting is only allowed once at start of the game.");
     }
 }