public void it_should_return_food()
        {
            var scrapper = new XPathScrapper();
            var scrap = new Scrap
            {
                CaloriesXPath =  @"//*[@id=""prod-detail""]/section/section[2]/table/tbody/tr[2]/td[3]",
                ProteinXPath = @"//*[@id=""prod-detail""]/section/section[2]/table/tbody/tr[3]/td[3]",
                CarbohydrateXPath = @"//*[@id=""prod-detail""]/section/section[2]/table/tbody/tr[12]/td[3]",
                FatXPath = @"//*[@id=""prod-detail""]/section/section[2]/table/tbody/tr[4]/td[3]",
                ProductXPath = @"//*[@id=""subPageTitle""]"
            };

            var results = scrapper.Scrap(scrap, File.ReadAllText("Data/john-west.html"));
            var expected = new Food
            {
                Brand = "John West",
                Product = "Pole and Line Skipjack Tuna in Springwater 185g",
                Calories = 115,
                Protein = 26.4M,
                Fat = 0.9M,
                Carbohydrate = 0
            };

            Assert.Equal(expected.Calories, results.Food.Calories);
            Assert.Equal(expected.Protein, results.Food.Protein);
            Assert.Equal(expected.Fat, results.Food.Fat);
            Assert.Equal(expected.Carbohydrate, results.Food.Carbohydrate);
            Assert.Equal(expected.Product, results.Food.Product);
        }
 public ActionResult Edit(Scrap scrap)
 {
     _db.Update(scrap);
     return RedirectToAction("Index");
 }
 public ActionResult Add(Scrap scrap)
 {
     _db.Insert(scrap);
     return RedirectToAction("Index");
 }
 public ActionResult Delete(Scrap scrap)
 {
     _db.DeleteById<Scrap>(scrap.Id);
     return RedirectToAction("Index");
 }
        public ScrappedContent Scrap(Scrap scrap, string content)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(content);

            var food = new Food();

            if (!String.IsNullOrEmpty(scrap.BrandXPath))
            {
                Log("Brand");
                food.Brand = GetString(doc, scrap.BrandXPath);
            }

            if (!String.IsNullOrEmpty(scrap.ProductXPath))
            {
                Log("Product");
                food.Product = GetString(doc, scrap.ProductXPath);
            }

            if (!String.IsNullOrEmpty(scrap.CaloriesXPath))
            {
                Log("Calories");
                food.Calories = GetDecimal(doc, scrap.CaloriesXPath);
            }

            if (!String.IsNullOrEmpty(scrap.CarbohydrateXPath))
            {
                Log("Carbohydrate");
                food.Carbohydrate = GetDecimal(doc, scrap.CarbohydrateXPath);
            }

            if (!String.IsNullOrEmpty(scrap.ProteinXPath))
            {
                Log("Protein");
                food.Protein = GetDecimal(doc, scrap.ProteinXPath);
            }

            if (!String.IsNullOrEmpty(scrap.FatXPath))
            {
                Log("Fat");
                food.Fat = GetDecimal(doc, scrap.FatXPath);
            }

            return new ScrappedContent
            {
                Food = food,
                Messages = _log.ToString()
            };
        }