void SetupHops() { IHop hop = new Hop("Saaz"); hop.AddOilCharacteristics(new HopOilCharacteristics { Carophyllene = 20M, Farnesene = 20M, Humulene = 20M, Myrcene = 20M, OtherAcids = 20M, PercentageOfTotalWeight = 20, TotalAlphaAcid = 5M }); IList<IHop> hops = new List<IHop> { hop }; hopVMs = new List<IHopViewModel> { new HopViewModel(hops[0]) }; _stockItemsRepository.Expect(x => x.GetHops()).Return(hops).Repeat.Any(); }
public void ShouldBeAbleToSetTheWeightOfHops() { var hop = new Hop("Saaz"); var recipe = new Recipe(); recipe.AddHop(hop, new Weight(10, MassUnit.Grams), 60); Assert.AreEqual(new Weight(10, MassUnit.Grams), recipe.GetTotalHopWeight()); }
public void ShouldBeAbleToAddHopOilCharacteristics() { var hop = new Hop("Saaz"); var hopOilCharacteristics = new HopOilCharacteristics() { PercentageOfTotalWeight = 10, Farnesene = 20, Carophyllene = 30, Myrcene = 15, Humulene = 15, OtherAcids = 20 }; hop.AddOilCharacteristics(hopOilCharacteristics); Assert.AreEqual(hopOilCharacteristics, hop.GetCharacteristics()); }
private void GetHops() { var hops = new List<Hop>(); var baseUrl = "http://www.wellhopped.co.uk/"; var result = new System.Net.WebClient().DownloadString(string.Format("{0}Variety.asp", baseUrl)); var doc = new HtmlDocument(); doc.LoadHtml(result); var nameXPath = "td[2]"; var linkXPath = "td[2]/a[1]"; var aaXPath = "td[3]"; var hopTable = doc.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table[1]/tr[2]/td[2]/table[2]"); int iter = 2; HtmlNode row = hopTable.SelectSingleNode("tr[" + iter + "]"); while (row != null) { var name = row.SelectSingleNode(nameXPath).InnerText.Replace("\r\n", "").Trim(); string detailsLink = null; try { detailsLink = row.SelectSingleNode(linkXPath).Attributes["href"].Value.Trim(); } catch (Exception) { } var alphaAcid = row.SelectSingleNode(aaXPath).InnerText.Replace("\r\n", ""); alphaAcid = alphaAcid.Replace("%", String.Empty); var alphaAcidRange = alphaAcid.Split('-'); var hop = new Hop(name); if (detailsLink != null) { var resultDetails = new System.Net.WebClient().DownloadString(string.Format("{0}{1}", baseUrl, detailsLink)); var docDetails = new HtmlDocument(); docDetails.LoadHtml(resultDetails); hop.Description = docDetails.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table/tr[2]/td[2]/table/tr[4]/td[2]").InnerText; var analyticsTable = docDetails.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table[1]/tr[2]/td[2]/table[3]/tr/td[2]/table[1]"); var oilsTable = docDetails.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table[1]/tr[2]/td[2]/table[3]/tr/td[4]/table[1]"); try { hop.AddOilCharacteristics(new HopOilCharacteristics { Carophyllene = Convert.ToDecimal( oilsTable.SelectSingleNode("tr[2]/td[2]").InnerText.Replace("%","")), Farnesene = Convert.ToDecimal( oilsTable.SelectSingleNode("tr[3]/td[2]").InnerText.Replace("%", "")), Humulene = Convert.ToDecimal( oilsTable.SelectSingleNode("tr[4]/td[2]").InnerText.Replace("%", "")), Myrcene = Convert.ToDecimal( oilsTable.SelectSingleNode("tr[5]/td[2]").InnerText.Replace("%", "")), OtherAcids = Convert.ToDecimal( oilsTable.SelectSingleNode("tr[6]/td[2]").InnerText.Replace("%", "")), PercentageOfTotalWeight = GetAverageFromTextRange( analyticsTable.SelectSingleNode("tr[6]/td[2]"). InnerText), TotalAlphaAcid = GetTotalAlphaAcid(alphaAcidRange) }); } catch(Exception ex) { } } hops.Add(hop); row = hopTable.SelectSingleNode("tr[" + iter++ + "]"); } hops.ForEach(x => _repository.Save(x)); }
private void GetHopsOld() { GetHopsBYO(); var hops = new List<Hop>(); var result = new System.Net.WebClient().DownloadString("http://www.trystan.org/res/beer/hops.html"); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(result); var hopTable = doc.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table[2]"); if (hopTable != null) { int iter = 2; HtmlNode row = hopTable.SelectSingleNode("tr[" + iter + "]"); while (row != null) { var name = row.SelectSingleNode("td[1]").InnerText.Replace("\\r\\n", "").Trim(); var hop = new Hop(name); var matchingBYOHop = hopsBYO.FirstOrDefault(x => x.Name.Contains(name)); decimal alphaAcid = 0; if (matchingBYOHop != null) { alphaAcid = matchingBYOHop.GetAlphaAcid(); hop.Description = matchingBYOHop.Description; } hop.AddOilCharacteristics(new HopOilCharacteristics { Carophyllene = Convert.ToDecimal(row.SelectSingleNode("td[5]").InnerText), Farnesene = row.SelectSingleNode("td[6]").InnerText == "--" ? 0M : Convert.ToDecimal(row.SelectSingleNode("td[6]").InnerText), Humulene = Convert.ToDecimal(row.SelectSingleNode("td[4]").InnerText), Myrcene = Convert.ToDecimal(row.SelectSingleNode("td[3]").InnerText), OtherAcids = Convert.ToDecimal(row.SelectSingleNode("td[7]").InnerText), PercentageOfTotalWeight = Convert.ToDecimal(row.SelectSingleNode("td[2]").InnerText), TotalAlphaAcid = alphaAcid }); hops.Add(hop); row = hopTable.SelectSingleNode("tr[" + iter++ + "]"); } } hops.ForEach(x => _repository.Save(x)); }
private void GetHopsBYO() { hopsBYO = new List<Hop>(); for (int x = 1; x < 25; x++) { var result = new System.Net.WebClient().DownloadString("http://byo.com/resources/hops?style=" + x + ""); //result = result.Remove(0, 123); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(result); int i = 1; bool isTable = true; while (isTable) { var hopTable = doc.DocumentNode.SelectSingleNode( "/html[1]/body[1]/table[1]/tr[4]/td[2]/div[3]/table[1]/tbody[1]/tr[" + i + "]"); if (hopTable != null) { var name = hopTable.SelectSingleNode("td[1]").InnerText.Replace("\\r\\n", "").Trim(); var alphaAcid = hopTable.SelectSingleNode("td[2]").InnerText.Replace("\r\n", ""); alphaAcid = alphaAcid.Replace("%", String.Empty); var alphaAcidRange = alphaAcid.Split('-'); var description = hopTable.SelectSingleNode("td[4]").InnerText.Trim(); var hop = new Hop(name); hop.Description = description; hop.AddOilCharacteristics(new HopOilCharacteristics { Carophyllene = 20M, Farnesene = 20M, Humulene = 20M, Myrcene = 20M, OtherAcids = 20M, PercentageOfTotalWeight = 20, TotalAlphaAcid = GetTotalAlphaAcid(alphaAcidRange) }); if (hopsBYO.FirstOrDefault(h => h.Name == name) == null) hopsBYO.Add(hop); i = i + 2; } else { isTable = false; } } } //hopsBYO.ForEach(x => _repository.Save(x)); }
public void HopsShouldAlwaysHaveAName() { var hop = new Hop("Saaz"); Assert.AreEqual("Saaz", hop.Name); }
private static Recipe SimpleRecipe() { var grain1 = new StockFermentable("Wheat", 1.045M); var hop = new Hop("Saaz"); var recipe = new Recipe(); recipe.SetBrewLength(1.Gallons()); recipe.AddFermentable(grain1, 1.Pound(), 1.045M); recipe.AddHop(hop, new Weight(10M, MassUnit.Grams), 60, 12.5M); return recipe; }
public void ShouldThrowAnExceptionIfOilPercentagesDoNotAddUp() { var hop = new Hop("Saaz"); var hopOilCharacteristics = new HopOilCharacteristics() { PercentageOfTotalWeight = 10, Farnesene = 20, Carophyllene = 20, Myrcene = 15, Humulene = 15, OtherAcids = 20 }; try { hop.AddOilCharacteristics(hopOilCharacteristics); } catch (Exception) { Assert.Pass(); } Assert.Fail("Hop oils failed validation."); }
public void ShouldHandleGramsAndKilograms() { var hop1 = new Hop("Saaz 1"); var hop2 = new Hop("Saaz 2"); var recipe = new Recipe(); recipe.AddHop(hop1, new Weight(10, MassUnit.Grams), 60); recipe.AddHop(hop2, new Weight(1, MassUnit.KiloGrams), 60); Assert.AreEqual(new Weight(1010, MassUnit.Grams), recipe.GetTotalHopWeight()); }