public void Setup() { mockConsoleIO = new ConsoleIOMock(); Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); ops = new BlackjackOperations(mockConsoleIO); }
public void play_a_simulated_game_dealer_wins() { //Dependencies.randomSeeds.ConstantValue = 1235; Dependencies.randomInstance.ConstantValue = new Random(1235); Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); mockConsoleIO.LoadReadValue("H"); mockConsoleIO.LoadReadValue("S"); BlackjackGame game = new BlackjackGame(); string playerName = "Billy Joel"; Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(playerName); IDeck deck = BlackjackOperations.GetAndShuffleNewDeck(); game.play(deck, dealer, player); int i = 0; Assert.AreEqual($"Player {playerName}, Score=14", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=4", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"{Hand.FACEDOWN},Four of Clubs", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Enter Action H)it, S)tand, B)ust:", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Hit", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=20", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts,Six of Spades", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Enter Action H)it, S)tand, B)ust:", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Stand", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Action=Hit", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"{Hand.FACEDOWN},Four of Clubs,Seven of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Action=Stand", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer wins!", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=20", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts,Six of Spades", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=21", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"King of Clubs,Four of Clubs,Seven of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Dependencies.consoleIO.reset(); Dependencies.randomSeeds.reset(); Dependencies.randomInstance.reset(); }
public void parse_action_valid_single_char_typed_lowercase_custom() { Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); mockConsoleIO.LoadReadValue("h"); mockConsoleIO.LoadReadValue("s"); mockConsoleIO.LoadReadValue("b"); IPlayer player = new HumanPlayer(); PlayerAction action = player.NextAction(null); Assert.AreEqual(PlayerAction.Hit, action); action = player.NextAction(null); Assert.AreEqual(PlayerAction.Stand, action); action = player.NextAction(null); Assert.AreEqual(PlayerAction.Busted, action); Assert.AreEqual(3, mockConsoleIO.GetConsoleWrites().Count); Dependencies.consoleIO.reset(); }