Ejemplo n.º 1
0
        public Dictionary <string, IArticle> ReadArticlesFromFile(string filePath)
        {
            var logger = LogManager.GetLogger(typeof(CSVReader));

            try
            {
                var textLines = File.ReadAllLines(filePath);
                var result    = new Dictionary <string, IArticle>();
                int index     = 1;
                foreach (var textLine in textLines.Skip(1))
                {
                    try
                    {
                        var article = CSVTextHelper.GetArticleFromString(textLine, index);
                        if (article == null)
                        {
                            continue;
                        }
                        var key = ArticleKeyGenerator.GetKeyFromArticle(article);
                        if (result.ContainsKey(key))
                        {
                            IWheel wheel = article as IWheel;
                            if (wheel == null)
                            {
                                continue;
                            }

                            result.Remove(key);
                            result.Add(key, article);
                        }
                        result.Add(key, article);
                        index++;
                    }
                    catch (Exception e)
                    {
                        logger.Info("Couldnt read line: " + textLine + " Möglicherweise Double Parse Fehler", e);
                    }
                }
                return(result);
            }
            catch (IOException exception)
            {
                logger.Error("Unerwarteter Fehler: ", exception);
                throw new FileNotReadyException();
            }
        }
Ejemplo n.º 2
0
        public void TestReadArticlePositiveCase()
        {
            var articleToTest = CSVTextHelper.GetArticleFromString(TEST_LINE, 1);

            Assert.AreEqual(1, articleToTest.Id);
            Assert.AreEqual("B20050XKIKT207", articleToTest.ArticleId);
            Assert.AreEqual("KINGSTIR KT207  200    -50 2 PR    ", articleToTest.Description);
            Assert.AreEqual("", articleToTest.Description2);
            Assert.AreEqual(10.01, articleToTest.Price);
            Assert.AreEqual(0, articleToTest.Price4);
            Assert.AreEqual(10.01, articleToTest.AvgPrice);
            Assert.AreEqual(0, articleToTest.AnonymPrice);
            Assert.AreEqual(19.6, articleToTest.RvoPrice);
            Assert.AreEqual(2, articleToTest.Availability);
            Assert.AreEqual("", articleToTest.ManufactorerNumber);
            Assert.AreEqual("http://media1.tyre24.de/images/tyre/nopic_nobr-NTI2NzY=-w300-h300-br1.jpg", articleToTest.ImageLink);
            Assert.AreEqual("http://media1.tyre24.de/images/tyre/nopic_nobr-NTI2NzY=-w112-h150-br1.jpg", articleToTest.ImageTnLink);
            Assert.AreEqual("http://www.tyre24.de/item/profil/id/184098/allow/NTI2NzY=", articleToTest.InfoLink);
            Assert.AreEqual("KINGSTIRE", articleToTest.Manufactorer);
            Assert.AreEqual("http://www.tyre24.de/reifen/profi?search=ID184098", articleToTest.DirectLink);
            Assert.AreEqual("http://media3.tyre24.de/tyrelabel/0/0/0-h300-w300.jpg", articleToTest.TyreLabelLink);
        }