public void MissingForm() { ViewResult result = testController.PokerEvaluation(null) as ViewResult; PokerEvaluationViewModel viewModel = shucker.Shuck <PokerEvaluationViewModel>(result); Assert.IsTrue( viewModel != null && viewModel.ThrownException != null, "View model was generated incorrectly or exception was not recorded."); }
public void InvalidRank() { testForm["rank-player-1-card-1"] = "invalid"; ViewResult result = testController.PokerEvaluation(testForm) as ViewResult; PokerEvaluationViewModel viewModel = shucker.Shuck <PokerEvaluationViewModel>(result); Assert.IsTrue( viewModel != null && viewModel.ThrownException != null, "View model was generated incorrectly or exception was not recorded."); }
public void MissingSuit() { testForm.Remove("suit-player-1-card-1"); ViewResult result = testController.PokerEvaluation(testForm) as ViewResult; PokerEvaluationViewModel viewModel = shucker.Shuck <PokerEvaluationViewModel>(result); Assert.IsTrue( viewModel != null && viewModel.ThrownException != null, "View model was generated incorrectly or exception was not recorded."); }
public void BasicEvalWithWin() { testForm["rank-player-1-card-1"] = "eight"; ViewResult result = testController.PokerEvaluation(testForm) as ViewResult; PokerEvaluationViewModel viewModel = shucker.Shuck <PokerEvaluationViewModel>(result); Assert.IsTrue( viewModel != null && viewModel.Verdict != null && viewModel.Verdict.VerdictType == PokerHandVerdictType.WinByInTypeOrdering, "Result was null, empty or had the incorrect data."); }
public void BasicEval() { ViewResult result = testController.PokerEvaluation(testForm) as ViewResult; Assert.IsNotNull( result, "Result was either null or of the incorrect type."); PokerEvaluationViewModel viewModel = shucker.Shuck <PokerEvaluationViewModel>(result); Assert.IsTrue( viewModel != null && viewModel.Verdict != null && viewModel.TiedHands.Count == 2, "Contained view model was null, of the wrong type or had the incorrect data."); }
/// <summary> /// Processes a form that contains data about two poker hands that need to /// be evaluated and the data and view needed by the MVC framework to render /// this evaluation for the user. /// </summary> /// <param name="PokerHandsForm"> /// The form data that contains information about the hands being submitted /// for evaluation. Must not be null. /// </param> /// <returns> /// The view, coupled with the evaluation data needed to render that view that /// the MVC framework should use to display the results of evaluating the poker hands. /// </returns> public ActionResult PokerEvaluation(FormCollection PokerHandsForm) { PokerEvaluationViewModel viewModel = viewModelFactory(); PokerHand player1Hand = pokerHandFactory(); PokerHand player2Hand = pokerHandFactory(); try { if (PokerHandsForm == null) { throw new ArgumentNullException("PokerHandsForm"); } for (int handBeingProcessed = 1; handBeingProcessed <= 2; handBeingProcessed++) { PokerHand targetHand = handBeingProcessed == 1 ? player1Hand : player2Hand; String playerNameField = String.Format("player-{0}-name", handBeingProcessed.ToString()); if (!PokerHandsForm.AllKeys.Contains(playerNameField) || String.IsNullOrEmpty(PokerHandsForm[playerNameField]) || String.IsNullOrEmpty(PokerHandsForm[playerNameField].Trim())) { throw new Exception( String.Format( "No name present for player {0}.", handBeingProcessed.ToString())); } targetHand.PlayerName = PokerHandsForm[playerNameField]; for (int cardBeingProcessed = 1; cardBeingProcessed <= 5; cardBeingProcessed++) { Card card = cardFactory(); String cardRankField = String.Format( "rank-player-{0}-card-{1}", handBeingProcessed.ToString(), cardBeingProcessed.ToString()); String cardSuitField = String.Format( "suit-player-{0}-card-{1}", handBeingProcessed.ToString(), cardBeingProcessed.ToString()); if (!PokerHandsForm.AllKeys.Contains(cardRankField) || String.IsNullOrEmpty(PokerHandsForm[cardRankField])) { throw new Exception( String.Format( "Missing rank value for card {0} for player \"{1}.\"", cardBeingProcessed.ToString(), targetHand.PlayerName)); } if (!PokerHandsForm.AllKeys.Contains(cardSuitField) || String.IsNullOrEmpty(PokerHandsForm[cardSuitField])) { throw new Exception( String.Format( "Missing suit value for card {0} for player \"{1}.\"", cardBeingProcessed.ToString(), targetHand.PlayerName)); } CardRank rank = CardRank.Ace; if (!Enum.TryParse <CardRank>(PokerHandsForm[cardRankField], true, out rank)) { throw new Exception( String.Format( "Invalid card rank value \"{0}\".", PokerHandsForm[cardRankField])); } CardSuit suit = CardSuit.Clubs; if (!Enum.TryParse <CardSuit>(PokerHandsForm[cardSuitField], true, out suit)) { throw new Exception( String.Format( "Invalid card suit value \"{0}\".", PokerHandsForm[cardSuitField])); } card.Rank = rank; card.Suit = suit; targetHand.Cards.Add(card); } } viewModel.Verdict = pokerHandJudge.Judge(player1Hand, player2Hand); if (viewModel.Verdict.VerdictType == PokerHandVerdictType.Tie) { viewModel.TiedHands = new List <PokerHand>() { player1Hand, player2Hand } } ; else { viewModel.RunnerUpHand = viewModel.Verdict.WinningHand == player1Hand ? player2Hand : player1Hand; } } catch (Exception ex) { viewModel.ThrownException = ex; } return(View(viewModel)); }