public void DealersSecondCardIsOpenedIfAllPlayersStand() { //Arrange ERoundCalls playerCall = ERoundCalls.Stand; bool isDealersSecondCardOpenAfterDeal = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Act foreach (EPlayers player in _blackjackGameRound.PlayerRoundStates.Keys) { _blackjackGameRound.PlayerCall(player, playerCall); } bool isDealersSecondCardOpenAfterAllPlayersStand = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Assert if (isDealersSecondCardOpenAfterDeal) { string errorMessage = "Dealer's second card is expected to be closed after the deal session and before players start making calls. However, the card is open!"; Assert.Fail(errorMessage); } if (_blackjackGameRound.PlayerRoundStates.Any(p => p.Value != EPlayerRoundState.Stand)) { string errorMessage = $"All player round states are expected to be {EPlayerRoundState.Stand}. However, not all players have this round state!"; Assert.Fail(errorMessage); } if (!isDealersSecondCardOpenAfterAllPlayersStand) { string errorMessage = "Dealer's second card is expected to be open after all players make a stand call. However, the card is closed!"; Assert.Fail(errorMessage); } }
public void Execute(EPlayers player, ERoundCalls call) { if (_playerRoundStates[player] == EPlayerRoundState.CanMakeHitCall) { switch (call) { case ERoundCalls.Hit: new GivePlayerAdditionalCardCommand(_cards, _playerCards).Execute(player); break; case ERoundCalls.Stand: _playerRoundStates[player] = EPlayerRoundState.Stand; break; default: return; } } }
public void PlayerIsAbleToMakeStandCall() { //Arrange ERoundCalls playerCall = ERoundCalls.Stand; int numberOfPlayerOneCards = _blackjackGameRound.PlayerCards[EPlayers.Player1].Count; //Act _blackjackGameRound.PlayerCall(EPlayers.Player1, playerCall); int numberOfPlayerOneCardsAfterStand = _blackjackGameRound.PlayerCards[EPlayers.Player1].Count; //Assert if (numberOfPlayerOneCards != 2 || numberOfPlayerOneCardsAfterStand != 2) { string errorMessage = Environment.NewLine + "Player one does not have expected number of cards before and after the stand call. " + Environment.NewLine + $"Expected number of cards before the stand call is {2}, actual number of cards before the stand call is {numberOfPlayerOneCards}" + Environment.NewLine + $"Expected number of cards after the stand call is {2}, actual number of cards after the stand call is {numberOfPlayerOneCardsAfterStand}"; Assert.Fail(errorMessage); } }
public void DealersSecondCardIsOpenedIfPlayerCallSessionsEndsWithAtLeastOneStandCall() { //Arrange ERoundCalls playerOneCall = ERoundCalls.Stand; ERoundCalls playerTwoCall = ERoundCalls.Stand; ERoundCalls playerThreeCall = ERoundCalls.Hit; bool isDealersSecondCardOpenAfterDeal = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Act _blackjackGameRound.PlayerCall(EPlayers.Player1, playerOneCall); _blackjackGameRound.PlayerCall(EPlayers.Player2, playerTwoCall); while (_blackjackGameRound.PlayersSumOfCards[EPlayers.Player3] < 21) { _blackjackGameRound.PlayerCall(EPlayers.Player3, playerThreeCall); } bool isDealersSecondCardOpenAfterAtLeastOnePlayerStandAndOtherPlayersExceedTwentyOne = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Assert if (isDealersSecondCardOpenAfterDeal) { string errorMessage = "Dealer's second card is expected to be closed after the deal session and before players start making calls. However, the card is open!"; Assert.Fail(errorMessage); } if (_blackjackGameRound.PlayerRoundStates.Any(p => p.Value != EPlayerRoundState.Stand && p.Value != EPlayerRoundState.ExceededTwentyOne)) { string errorMessage = $"All player round states are expected to be {EPlayerRoundState.Stand} or {EPlayerRoundState.ExceededTwentyOne}. However, not all players have these round state!"; Assert.Fail(errorMessage); } if (!isDealersSecondCardOpenAfterAtLeastOnePlayerStandAndOtherPlayersExceedTwentyOne) { string errorMessage = "Dealer's second card is expected to be open after at least one player makes a stand call and other players exceed twenty one. However, the card is closed!"; Assert.Fail(errorMessage); } }
public void DealersSecondCardIsNotOpenedIfAllPlayersExceedTwentyOne() { //Arrange ERoundCalls playerCall = ERoundCalls.Hit; bool isDealersSecondCardOpenAfterDeal = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Act foreach (EPlayers player in _blackjackGameRound.PlayerRoundStates.Keys) { while (_blackjackGameRound.PlayersSumOfCards[player] < 21) { _blackjackGameRound.PlayerCall(player, playerCall); } } bool isDealersSecondCardOpenAfterAllPlayersStand = _blackjackGameRound.DealersSecondPlayedCard.IsOpen; //Assert if (isDealersSecondCardOpenAfterDeal) { string errorMessage = "Dealer's second card is expected to be closed after the deal session and before players start making calls. However, the card is open!"; Assert.Fail(errorMessage); } if (_blackjackGameRound.PlayerRoundStates.Any(p => p.Value != EPlayerRoundState.ExceededTwentyOne)) { string errorMessage = $"All player round states are expected to be {EPlayerRoundState.ExceededTwentyOne}. However, not all players have this round state!"; Assert.Fail(errorMessage); } if (isDealersSecondCardOpenAfterAllPlayersStand) { string errorMessage = "Dealer's second card is expected to be closed after all players exceed twenty one. However, the card is open!"; Assert.Fail(errorMessage); } }