Ejemplo n.º 1
0
        public GameResponse Hit([Required][FromHeader(Name = "X-Token")] string token)
        {
            token = Crypto.Decrypt(token);
            var data = JsonConvert.DeserializeObject <GameData>(token);

            game.Hit(data);
            return(new GameResponse
            {
                Token = Crypto.Encrypt(JsonConvert.SerializeObject(data)),
                Data = this.game.GetclientView(data)
            });
        }
Ejemplo n.º 2
0
        public void GuestHitWins()
        {
            var dealerCards = GenerateCards(new int[] { 4, 6 }).ToList();
            var guestCards  = GenerateCards(new int[] { 3, 5 }).ToList();

            var randomIndexes = new int[] { 0, 0, 8 };
            var mockCards     = GenerateCards(randomIndexes).ToList();
            var game          = new GameFlow(new TestRandomEngine(dealerCards, guestCards, mockCards));
            var data          = game.Initialize();

            foreach (var item in randomIndexes)
            {
                game.Hit(data);
            }

            Assert.IsNotNull(data.Winner, "There should be a winner");
            Assert.AreEqual <Player?>(Player.Guest, data.Winner.Value, "The winner should be the Guest");
            Assert.IsTrue(data.GameOver, "The game is over");
            Assert.AreEqual <int>(12, data.CurrentDealerScore, "Dealer score should be 12 considering that the game is over");
            Assert.AreEqual <int>(21, data.CurrentGuestScore, "Guest score should be 21");
        }