protected override IEnumerable <ICard> PopulateCards(IHearthstoneCardParser parser)
 {
     using (var reader = File.OpenText(Path.Combine(_hostingEnvironment.ContentRootPath, "App_Data/cards.json")))
     {
         var    cardSets = JObject.Parse(reader.ReadToEnd());
         JToken cards;
         if (cardSets.TryGetValue("Basic", out cards) && cards.Type == JTokenType.Array)
         {
             foreach (var card in cards)
             {
                 var parsedCard = parser.Parse(card.ToString());
                 if (parsedCard != null)
                 {
                     yield return(parsedCard);
                 }
             }
         }
         if (cardSets.TryGetValue("Classic", out cards) && cards.Type == JTokenType.Array)
         {
             foreach (var card in cards)
             {
                 var parsedCard = parser.Parse(card.ToString());
                 if (parsedCard != null)
                 {
                     yield return(parsedCard);
                 }
             }
         }
         if (cardSets.TryGetValue("Curse of Naxxramas", out cards) && cards.Type == JTokenType.Array)
         {
             foreach (var card in cards)
             {
                 var parsedCard = parser.Parse(card.ToString());
                 if (parsedCard != null)
                 {
                     yield return(parsedCard);
                 }
             }
         }
         if (cardSets.TryGetValue("Goblins vs Gnomes", out cards) && cards.Type == JTokenType.Array)
         {
             foreach (var card in cards)
             {
                 var parsedCard = parser.Parse(card.ToString());
                 if (parsedCard != null)
                 {
                     yield return(parsedCard);
                 }
             }
         }
     }
 }
Example #2
0
        public void ShouldContainExpectedProperties()
        {
            var card = _parser.Parse(_cardData);

            card.ShouldNotBeNull();
            card.Id.ShouldBe("EX1_066");
            card.ShouldBeOfType(typeof(MinionCard));
        }
        private IEnumerable<ICard> GetCardsForCardType(IHearthstoneCardParser parser, JObject cardSets, string type)
        {
            List<ICard> parsedCards = new List<ICard>();
            JToken cards;

            if (cardSets.TryGetValue(type, out cards) && cards.Type == JTokenType.Array)
            {
                foreach (var card in cards)
                {
                    var parsedCard = parser.Parse(card.ToString());
                    if (parsedCard != null)
                    {
                        parsedCards.Add(parsedCard);
                    }
                }
            }

            return parsedCards;
        }
        protected override IEnumerable <ICard> PopulateCards(IHearthstoneCardParser parser)
        {
            using (var reader = File.OpenText(HttpContext.Current.Server.MapPath("~/App_Data/cards.json")))
            {
                JObject cardSets = JObject.Parse(reader.ReadToEnd());
                //JToken cards;
                List <string> acceptedCards = new List <string>()
                {
                    "Basic", "Classic", "Curse of Naxxramas", "Goblins vs Gnomes"
                };
                foreach (KeyValuePair <string, JToken> cardList in cardSets)
                {
                    string cardsType = cardList.Key;
                    if (acceptedCards.Contains(cardsType))
                    {
                        foreach (var card in cardList.Value)
                        {
                            var parsedCard = parser.Parse(card.ToString());
                            if (parsedCard != null)
                            {
                                if (string.IsNullOrEmpty(parsedCard.PlayerClass))
                                {
                                    parsedCard.PlayerClass = "Neutral";
                                }
                                yield return(parsedCard);
                            }
                        }
                    }
                }

                /*if (cardSets.TryGetValue("Basic", out cards) && cards.Type == JTokenType.Array)
                 * {
                 *  foreach (var card in cards)
                 *  {
                 *      var parsedCard = parser.Parse(card.ToString());
                 *      if (parsedCard != null)
                 *      {
                 *          yield return parsedCard;
                 *      }
                 *  }
                 * }
                 * if (cardSets.TryGetValue("Classic", out cards) && cards.Type == JTokenType.Array)
                 * {
                 *  foreach (var card in cards)
                 *  {
                 *      var parsedCard = parser.Parse(card.ToString());
                 *      if (parsedCard != null)
                 *      {
                 *          yield return parsedCard;
                 *      }
                 *  }
                 * }
                 * if (cardSets.TryGetValue("Curse of Naxxramas", out cards) && cards.Type == JTokenType.Array)
                 * {
                 *  foreach (var card in cards)
                 *  {
                 *      var parsedCard = parser.Parse(card.ToString());
                 *      if (parsedCard != null)
                 *      {
                 *          yield return parsedCard;
                 *      }
                 *  }
                 * }
                 * if (cardSets.TryGetValue("Goblins vs Gnomes", out cards) && cards.Type == JTokenType.Array)
                 * {
                 *  foreach (var card in cards)
                 *  {
                 *      var parsedCard = parser.Parse(card.ToString());
                 *      if (parsedCard != null)
                 *      {
                 *          yield return parsedCard;
                 *      }
                 *  }
                 * }*/
            }
        }
 protected override void Because()
 {
     _card = _parser.Parse(_cardData);
 }