Ejemplo n.º 1
0
        /// <summary>
        ///     Makes sure that when a jack is cut, a score comes back
        ///     Also verify that the count of the hands returned is correct
        /// </summary>
        public async Task TestGetHandWithJack()
        {
            try
            {
                string url = BuildUrl("/cribbage/getrandomhand/true/46,17,10,35,43,44,1,38,14,3,7,50,10");
                HttpResponseMessage response = await _client.GetAsync(url);

                AssertTrue(response.IsSuccessStatusCode);
                if (response.IsSuccessStatusCode)
                {
                    string jsonResponse = await response.Content.ReadAsStringAsync();

                    GetRandomHandResponse handResponse = JsonConvert.DeserializeObject <GetRandomHandResponse>(jsonResponse);
                    AssertEqual(6, handResponse.PlayerCards.Count);
                    AssertEqual(6, handResponse.ComputerCards.Count);
                    AssertEqual(2, handResponse.ComputerCribCards.Count);
                    AssertTrue(handResponse.HisNobs);
                }
            }
            catch (Exception e)
            {
                OutputError("FAILED " + e.Message);
                throw (e);
            }

            OutputInfo("PASSED");
        }
Ejemplo n.º 2
0
        public async Task TestGetHandAsync()
        {
            try
            {
                string url = BuildUrl("/cribbage/getrandomhand/true");
                HttpResponseMessage response = await _client.GetAsync(url);

                Debug.Assert(response.IsSuccessStatusCode);
                if (response.IsSuccessStatusCode)
                {
                    var settings = new JsonSerializerSettings
                    {
                        Formatting = Formatting.None,
                    };
                    string jsonResponse = await response.Content.ReadAsStringAsync();

                    GetRandomHandResponse hand = JsonConvert.DeserializeObject <GetRandomHandResponse>(jsonResponse, settings);
                    AssertTrue(hand != null, "Error deserializing GetRandomHandResponse");
                    AssertTrue(hand.ComputerCards.Count == 6, "Computer needs 6 cards");
                    AssertTrue(hand.PlayerCards.Count == 6, "Player needs 6 cards");
                    AssertTrue(hand.ComputerCribCards.Count == 2, "Computer needs 2 cards to give to Crib");
                    foreach (var card in hand.ComputerCards)
                    {
                        AssertTrue(card.Owner == Owner.Computer, "Card needs to be owned by computer");
                    }
                    foreach (var card in hand.PlayerCards)
                    {
                        AssertTrue(card.Owner == Owner.Player, "Card needs to be owned by Player");
                    }

                    AssertTrue(hand.HisNobs == (hand.SharedCard.Ordinal == CardOrdinal.Jack), "if you cut a jack, Nobs must be true");
                }
            }
            catch (Exception e)
            {
                OutputError(e.Message);
            }

            OutputInfo("PASSED");
        }