public void BeginGame1Player_InProgress_MapsCorrectly() { var game = new BlackJackGame(defautlCardProvider, DealerNamedData, 1); game.AddPlayer(PlayerTed); game.SetPlayerStatusReady(PlayerTedId); game.DealHands(); var gameDto = MapperBlackJackGameDto.Map(game, PlayerTedId); var Ted = game.Players.Single(p => p.Identifier == PlayerTedId); var TedDto = gameDto.Players.Single(p => p.PlayerIdentifier == PlayerTedId); var dealer = game.Players.Single(p => p.Identifier == DealerDataId); var dealerDto = gameDto.Players.Single(p => p.PlayerIdentifier == DealerDataId); Assert.AreEqual(game.Players.Count(), gameDto.Players.Count); Assert.AreEqual(Ted.Hands.Count(), TedDto.Hands.Count); Assert.AreEqual(Ted.Hands.Single().Identifier, TedDto.Hands.Single().Identifier); Assert.AreEqual(Ted.Hands.Single().Actions, TedDto.Hands.Single().Actions); Assert.AreEqual(Ted.Hands.Single().PointValue, TedDto.Hands.Single().PointValue); Assert.AreEqual(2, TedDto.Hands.Single().CardCount); Assert.AreEqual(dealer.Hands.Count(), dealerDto.Hands.Count); Assert.AreEqual(dealer.Hands.Single().Identifier, dealerDto.Hands.Single().Identifier); Assert.AreEqual(dealer.Hands.Single().Actions, dealerDto.Hands.Single().Actions); Assert.AreEqual(dealer.Hands.Single().PointValue, dealerDto.Hands.Single().PointValue); Assert.AreEqual(2, dealerDto.Hands.Single().CardCount); }
public void Deal_SinglePlayerAndDealer_CurrectValues() { var game = new BlackJackGame(cardProvider, DealerNamedData, 2); var playerId = "8625cf04-b7e1"; var player2Id = "8625cf04-b7e2"; game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = playerId, userName = playerName }, HandIdentifierProvider, 1)); game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = player2Id, userName = playerName2 }, HandIdentifierProvider, 1)); game.SetPlayerStatusReady(playerId); game.SetPlayerStatusReady(player2Id); game.DealHands(); Assert.AreEqual(GameStatus.InProgress, game.Status); Assert.AreEqual(2, game.Players.Last().Hands.First().Cards.Count()); Assert.AreEqual(5, game.Players.First().Hands.First().PointValue); Assert.AreEqual(5, game.Players.Skip(1).Take(1).Single().Hands.Single().PointValue); Assert.AreEqual(5, game.Players.Last().Hands.First().PointValue); Assert.IsTrue(game.Players.First().Hands.First().Cards.First().FaceDown); Assert.IsFalse(game.Players.First().Hands.First().Cards.Last().FaceDown); Assert.IsTrue(game.Players.Skip(1).Take(1).Single().Hands.First().Cards.First().FaceDown); Assert.IsFalse(game.Players.Skip(1).Take(1).Single().Hands.First().Cards.Last().FaceDown); Assert.IsTrue(game.Players.Skip(2).Take(1).Single().Hands.First().Cards.First().FaceDown); Assert.IsFalse(game.Players.Skip(2).Take(1).Single().Hands.First().Cards.Last().FaceDown); }
public void Deal_ThenAddNewPlayer_ThrowInvalidOperationException() { var game = new BlackJackGame(cardProvider, DealerNamedData, 2); var player = new Avitar(playerName); var player2 = new Avitar(playerName2); var playerId = "8625cf04-b7e1"; var player2Id = "8625cf04-b7e2"; game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = playerId, userName = playerName }, HandIdentifierProvider, 1)); game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = player2Id, userName = playerName2 }, HandIdentifierProvider, 1)); game.SetPlayerStatusReady(playerId); game.SetPlayerStatusReady(player2Id); game.DealHands(); Assert.Throws <InvalidOperationException>(() => game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = "8625cf04-b7e2", userName = playerName }, HandIdentifierProvider, 1)) ); }
public void Deal_NullDeck_ThrowArgumentNullException() { var game = new BlackJackGame(cardProvider, DealerNamedData, 4); var player2Id = "8625cf04-b7e2"; game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = player2Id, userName = playerName }, HandIdentifierProvider, 1)); game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = player2Id, userName = playerName2 }, HandIdentifierProvider, 1)); Assert.Throws <ArgumentOutOfRangeException>(() => game.DealHands()); }
public void GameConplete1Player_Complete_MapsCorrectly() { var game = new BlackJackGame(defautlCardProvider, DealerNamedData, 1); game.AddPlayer(PlayerTed); game.SetPlayerStatusReady(PlayerTedId); game.DealHands(); var TedHandKey = game.CurrentPlayer.Hands.Single().Identifier; game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); game.PlayerHits(PlayerTedId, TedHandKey); Assert.Throws <InvalidOperationException>(() => game.PlayerHits(PlayerTedId, TedHandKey)); var gameDto = MapperBlackJackGameDto.Map(game, PlayerTedId); var Ted = game.Players.Single(p => p.Identifier == PlayerTedId); var TedDto = gameDto.Players.Single(p => p.PlayerIdentifier == PlayerTedId); var dealer = game.Players.Single(p => p.Identifier == DealerDataId); var dealerDto = gameDto.Players.Single(p => p.PlayerIdentifier == DealerDataId); Assert.AreEqual(game.Players.Count(), gameDto.Players.Count); Assert.AreEqual(Ted.Hands.Count(), TedDto.Hands.Count); Assert.AreEqual(Ted.Hands.Single().Identifier, TedDto.Hands.Single().Identifier); Assert.AreEqual(Ted.Hands.Single().PointValue, TedDto.Hands.Single().PointValue); Assert.AreEqual(10, TedDto.Hands.Single().CardCount); Assert.AreEqual(21, TedDto.Hands.Single().PointValue); Assert.AreEqual(dealer.Hands.Count(), dealerDto.Hands.Count); Assert.AreEqual(dealer.Hands.Single().Identifier, dealerDto.Hands.Single().Identifier); Assert.AreEqual(dealer.Hands.Single().PointValue, dealerDto.Hands.Single().PointValue); Assert.AreEqual(2, dealerDto.Hands.Single().CardCount); }
public void AfterDeal_PlayerHits_CurrectValues() { var playerOneId = "8625cf04-b7e2"; var game = new BlackJackGame(cardProvider, DealerNamedData, 1); game.AddPlayer(new BlackJackPlayer(new AvitarDto() { id = "8625cf04-b7e2", userName = playerName2 }, HandIdentifierProvider, 1)); game.SetPlayerStatusReady(playerOneId); game.DealHands(); Assert.AreEqual(2, game.Players.Last().Hands.First().Cards.Count()); Assert.AreEqual(5, game.Players.First().Hands.First().PointValue); Assert.AreEqual(5, game.Players.Last().Hands.First().PointValue); Assert.IsTrue(game.Players.First().Hands.First().Cards.First().FaceDown); Assert.IsFalse(game.Players.First().Hands.First().Cards.Last().FaceDown); Assert.IsTrue(game.Players.Last().Hands.First().Cards.First().FaceDown); Assert.IsFalse(game.Players.Last().Hands.First().Cards.Last().FaceDown); game.PlayerHits(playerOneId, HandIdentifierProvider.GenerateHandIds(1).Single()); Assert.AreEqual(3, game.Players.First().Hands.First().Cards.Count()); Assert.AreEqual(7, game.Players.First().Hands.First().PointValue); }