Example #1
0
        public void TestMyMagicCollectionCsvRead()
        {
            var targetFileName = Path.Combine(TestContext.DeploymentDirectory, "CsvTest " + Guid.NewGuid().ToString() + ".csv");
            var referenceFile  = GetType().Assembly.LoadEmbeddedResourceTextFile("TestMyMagicCollectionCsvWrite.csv");

            File.WriteAllText(targetFileName, referenceFile, Encoding.UTF8);

            var target = new MyMagicCollectionCsv();
            var found  = target.ReadFile(targetFileName);

            Assert.AreEqual("My collection", found.Name);
            Assert.AreEqual(2, found.Cards.Count);

            Assert.AreEqual("card id 1", found.Cards[0].CardId);
            Assert.AreEqual("card id 2", found.Cards[1].CardId);
        }
Example #2
0
        public void ReadFile(string fileName)
        {
            var loader = new MyMagicCollectionCsv();

            _magicCollection = loader.ReadFile(fileName);

            if (_magicCollection != null)
            {
                _cards = new ObservableCollection <MagicBinderCardViewModel>(_magicCollection.Cards
                                                                             .Select(c =>
                {
                    MagicCardDefinition definition;
                    if (StaticMagicData.CardDefinitionsByCardId.TryGetValue(c.CardId, out definition))
                    {
                        return(new MagicBinderCardViewModel(definition, c));
                    }
                    else
                    {
                        return(null);
                    }
                }).Where(c => c != null));
            }
            else
            {
                _cards = new ObservableCollection <MagicBinderCardViewModel>();
            }

            // Now wrap every card with a view model:

            foreach (var card in _cards)
            {
                card.PriceChanged += Card_PriceChanged;
            }

            _sortedCards = Cards.ToDictionary(c => c.RowId);
            _fileName    = fileName;

            CalculateTotals();
        }