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 Run(int id) { var scrap = _db.GetById<Scrap>(id); ViewBag.Errors = String.Empty; ScrappedContent scrappedContent = new ScrappedContent(); try { string content = String.Empty; using (var client = new WebClient()) { content = client.DownloadString(scrap.Url); } var scrapper = new XPathScrapper(); scrappedContent = scrapper.Scrap(scrap, content); } catch (Exception ex) { ViewBag.Errors = ex.ToString(); } ViewBag.Id = scrap.Id; scrap.Preview = scrappedContent.Food; _db.Update(scrap); return View(scrappedContent); }