private ProductBasicData BuildProductBasicData(HtmlNode productNode)
        {
            log.DebugFormat("[BuildProductBasicData] OuterHtml= {0}.", productNode.OuterHtml);
            //throw new NotImplementedException();
            ProductBasicData returnValue = new ProductBasicData();

            //should be transfered to barcode, but last digitals of the barcode is productId
            returnValue.Barcode = productNode.Attributes.First(c => c.OriginalName == "DdPiD").Value;
            returnValue.ProductId = productNode.Attributes.First(c => c.OriginalName == "DdPiD").Value;
            returnValue.pbcatid = productNode.Attributes.First(c => c.OriginalName == "pbcatid").Value;
            returnValue.qty = productNode.Attributes.First(c => c.OriginalName == "qty").Value;
            returnValue.iq = productNode.Attributes.First(c => c.OriginalName == "iq").Value;
            returnValue.inb = productNode.Attributes.First(c => c.OriginalName == "inb").Value;

            //returnValue.ImageSource = productNode.SelectSingleNode("//img[@src]").Attributes.FirstOrDefault(c=> c.Name == "src").Value;

            returnValue.ImageSource = productNode.SelectNodes("child::*/child::div/child::img").First().Attributes.First(c => c.Name == "src").Value;
            returnValue.EffectivePrice = productNode.SelectSingleNode("child::*/child::div/child::div/child::div/child::span").InnerText;

            //returnValue.EffectivePrice = productNode.SelectSingleNode("//span[@id='spnEffectivePrice']").InnerText;
            //returnValue.Description = HttpUtility.HtmlDecode(productNode.SelectSingleNode("//div[@class='ProdBoxSupplierText']").InnerText);

            returnValue.Description = HttpUtility.HtmlDecode(productNode.SelectSingleNode("child::*/child::div/child::div/child::a").InnerText);
            returnValue.ProductName = HttpUtility.HtmlDecode(productNode.SelectSingleNode("child::*/child::div/child::div/child::a").InnerText);
            log.DebugFormat("[BuildProductBasicData] fetched product={0}.", returnValue.ToString());
            return returnValue;
        }
Example #2
0
        public void AddAndGetTest()
        {
            MongoEntityRepositoryBase<ProductBasicData> mongoRepository = new MongoEntityRepositoryBase<ProductBasicData>(m_Testdb);
            //arrange
            ProductBasicData entity = new ProductBasicData()
            {
                ProductId = "1111",
                EffectivePrice = "10",
                Barcode = "121211",
                Description = "SomeDescription",
                ExtendedData = new ProductExtendedData(),
                //Image = "urlToImage",
                ImageSource = "http:\\someDomain.dan",
                inb = "inb",
                iq = "iq",
                pbcatid = "pbcatid",
                ProductName = "productName",
                qty = "2"
            };

            //act
            mongoRepository.Add(entity);
            var fetchedEntity = mongoRepository.GetSingle(entity.Barcode);

            //assert
            Assert.IsNotNull(fetchedEntity);
            Assert.AreEqual(fetchedEntity.Barcode, entity.Barcode);
            Assert.AreEqual(fetchedEntity.Description, entity.Description);
            Assert.AreEqual(fetchedEntity.EffectivePrice, entity.EffectivePrice);
            Assert.AreEqual(fetchedEntity.Image, entity.Image);
            Assert.AreEqual(fetchedEntity.ImageSource, entity.ImageSource);
            Assert.AreEqual(fetchedEntity.inb, entity.inb);
            Assert.AreEqual(fetchedEntity.iq, entity.iq);
            Assert.AreEqual(fetchedEntity.pbcatid, entity.pbcatid);
            Assert.AreEqual(fetchedEntity.ProductId, entity.ProductId);
            Assert.AreEqual(fetchedEntity.ProductName, entity.ProductName);
            Assert.AreEqual(fetchedEntity.qty, entity.qty);
        }
Example #3
0
        public void ExtendedData_PropertyTest()
        {
            //arrange
            var extendedData =  new ProductExtendedData();
            extendedData.AlergensWarnings = "AlergensWarnings";
            List<Nutrition> nutr = new List<Nutrition>();
            nutr.Add(new Nutrition() { Name = "Calcium", Value = "Calcium" });
            nutr.Add(new Nutrition() { Name = "Carbohydrate", Value = "carb" });
            //extendedData.Calcium = "Calcium";
            //extendedData.Carbohydrate = "carb";

            MongoEntityRepositoryBase<ProductBasicData> mongoRepository = new MongoEntityRepositoryBase<ProductBasicData>(m_Testdb);
            ProductBasicData entity = new ProductBasicData()
            {
                ProductId = "1111",
                EffectivePrice = "10",
                Barcode = "121211",
                Description = "SomeDescription",
                ExtendedData = extendedData,
                //Image = "urlToImage",
                ImageSource = "http:\\someDomain.dan",
                inb = "inb",
                iq = "iq",
                pbcatid = "pbcatid",
                ProductName = "productName",
                qty = "2"
            };
            mongoRepository.Add(entity);

            //act
            var fetchedEntity = mongoRepository.GetSingle(entity.Barcode);
            var fetchedExtendedData = fetchedEntity.ExtendedData;
            //assert
            Assert.IsNotNull(fetchedExtendedData);
            Assert.AreEqual(fetchedExtendedData.AlergensWarnings, extendedData.AlergensWarnings);
            Assert.AreEqual(fetchedExtendedData.NutritionTable.First(c=> c.Name == "Calcium").Value , extendedData.NutritionTable.First(c=> c.Name == "Calcium").Value);
            Assert.AreEqual(fetchedExtendedData.NutritionTable.First(c => c.Name == "Carbohydrate").Value, extendedData.NutritionTable.First(c => c.Name == "Carbohydrate").Value);
        }
Example #4
0
 private string GetProductExampleHTML(ProductBasicData productBasicData)
 {
     var htmWithExtendedData = File.ReadAllText(@"..\..\..\GraberTests\TestData\ExtendedData.txt");
     return htmWithExtendedData;
 }
Example #5
0
        public void ProductFetcher_ExtendedData_Test()
        {
            //arrange
            ProductBasicData product = new ProductBasicData() { ProductId = "1485019" };
            ProductFetcher fetcher = new ProductFetcher();

            //act
            string htmlDecodedResponse = fetcher.GetProductExtendedData(product);

            //File.Create(@"c:\Temp\ExtendedData.txt");
            using(var writer = File.CreateText(@"c:\Temp\ExtendedData.txt"))
            {
                writer.Write(htmlDecodedResponse);
            }

            //assert
            Assert.IsNotNull(htmlDecodedResponse);
            Assert.IsTrue(htmlDecodedResponse.Contains(product.ProductId));
        }
Example #6
0
        public void ProductDataExtendedDataBuilderTest()
        {
            //arrange
            ProductBasicData productBasicData = new ProductBasicData();
            string htmlDecodedResponse = GetProductExampleHTML(productBasicData);
            ProductDataExtendedDataBuilder builder = new ProductDataExtendedDataBuilder();

            //act
            ProductExtendedData extendedData = builder.Build(htmlDecodedResponse);

            //assert
            Assert.IsNotNull(extendedData);
            Assert.IsNotNull(extendedData.NutritionTable);
            Assert.AreEqual(8, extendedData.NutritionTable.Count);
            Assert.IsFalse(string.IsNullOrEmpty(extendedData.RawHtmlResponse));
            Assert.AreEqual("1485019", extendedData.ProductId);
            Assert.AreEqual("200 גרם", extendedData.Weight);
            Assert.AreEqual("ישראל", extendedData.ProductionCountry);
            //Assert.AreEqual("117", extendedData.Energy);
            //Assert.AreEqual("11.5", extendedData.Proteins);
            //Assert.AreEqual("6.5", extendedData.Carbohydrate);
            //Assert.AreEqual("5", extendedData.fa);
        }