public Spontaneous.DataModel.ProductExtendedData Build(string htmlDecodedResponse) { log.Debug("[Build]."); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(htmlDecodedResponse); var prodnutritionsNodes = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='prodnutritions']"); List<Nutrition> nutritionTable = new List<Nutrition>(); //var prodnutritionscontainers = htmlDoc.DocumentNode.SelectNodes("//div[@class='prodnutritionscontainer']"); var prodnutritionslbls = htmlDoc.DocumentNode.SelectNodes("//div[@class='prodnutritionslbl']"); var prodnutritionsvalues = htmlDoc.DocumentNode.SelectNodes("//div[@class='prodnutritionsvalue']"); if (prodnutritionslbls != null) { for (int i = 0; i < prodnutritionslbls.Count; i++) { Nutrition nutrition = new Nutrition(); nutrition.Name = HttpUtility.HtmlDecode(prodnutritionslbls[i].InnerText); nutrition.Value = HttpUtility.HtmlDecode(prodnutritionsvalues[i].InnerText); nutritionTable.Add(nutrition); } } ProductExtendedData extendedData = new ProductExtendedData(); extendedData.RawHtmlResponse = htmlDecodedResponse; if(prodnutritionsNodes != null) extendedData.NutritionTableHtml = prodnutritionsNodes.OuterHtml; extendedData.NutritionTable = nutritionTable; if(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblSupplier']") != null) extendedData.Provider = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblSupplier']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblWeight']") != null) extendedData.Weight = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblWeight']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblCountry']") != null) extendedData.ProductionCountry = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblCountry']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblID']") != null) extendedData.ProductId = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblID']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblSupervision']") != null) extendedData.KosherType = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblSupervision']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblRoy']") != null) extendedData.KosherBy = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//span[@id='ctl00_PlaceHolderMain_ucPopupMasterLoader_ctlProductPage_lblRoy']").InnerText); if (htmlDoc.DocumentNode.SelectSingleNode("//div[@id='lblContains']") != null) extendedData.Ingredients = HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectSingleNode("//div[@id='lblContains']").InnerText); return extendedData; }
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); }