Ejemplo n.º 1
0
        private void InnerTestReadDeck(string fileName, int expectedNumberOfRows, MagicDeckCard expectedCard)
        {
            var notification = new Mock <INotificationCenter>();
            var fullName     = Path.Combine(TestContext.DeploymentDirectory, fileName);
            var target       = new DecReader(notification.Object);
            var result       = target.ReadFileContentDec(fullName);

            Assert.AreEqual(expectedNumberOfRows, result.Count(), "Wrong number of rows");

            var found = result.Where(r => r.CardId == expectedCard.CardId &&
                                     r.Name == expectedCard.Name &&
                                     r.Quantity == expectedCard.Quantity &&
                                     r.Location == expectedCard.Location);
        }
Ejemplo n.º 2
0
        public IEnumerable <MagicDeckCard> ReadFileContentDec(string content)
        {
            var foundCards = new List <MagicDeckCard>();

            foreach (var line in content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var card = new MagicDeckCard();

                var match = mvidRegex.Match(line);
                if (match.Success)
                {
                    var id = match.Groups["mvid"];
                    if (id.Success)
                    {
                        card.CardId = id.Value;
                    }

                    card.Name     = match.Groups["name"].Value;
                    card.Quantity = int.Parse(match.Groups["quantity"].Value);

                    var location     = match.Groups["location"];
                    var locationText = location.Success ? location.Value : "Deck";
                    card.Location = locationText.ToLowerInvariant() == "deck" ? MagicDeckLocation.Mainboard : MagicDeckLocation.Sideboard;
                    foundCards.Add(card);
                }
            }

            var result         = foundCards.Where(f => !string.IsNullOrEmpty(f.CardId)).ToList();
            var cardsWithoutId = foundCards.Where(f => string.IsNullOrEmpty(f.CardId)).ToList();

            foreach (var card in cardsWithoutId)
            {
                var exists = result.Any(f => f.Name == card.Name && f.Location == card.Location);
                if (!exists)
                {
                    result.Add(card);
                }
            }

            return(result);
        }