private static double ConvertToMilliliters(double amount, IngredientUnit unit, double partAmount) { switch (unit) { case IngredientUnit.Dash: return(amount * 1); case IngredientUnit.Teaspoon: return(amount * 5); case IngredientUnit.Splash: return(amount * 25); case IngredientUnit.Pint: return(amount * 473.18); case IngredientUnit.Drop: return(amount * 0.5); case IngredientUnit.Litre: return(amount * 1000); case IngredientUnit.Part: return(amount * partAmount); default: return(0); } }
internal Ingredient(String key, List <IngredientChoice> choiceKeys, double amountQuantity, IngredientUnit amountUnit, String name) { _choiceKeys = choiceKeys; Key = key; AmountQuantity = amountQuantity; AmountUnit = amountUnit; Name = name; _partAmount = 0; }
public static int GetPrice(this IngredientUnit ingredient) { if (!(ingredientPriceList.Keys.Contains(ingredient))) { throw new Exception("Ingredient Not Found!"); } return(ingredientPriceList[ingredient]); }
private void TestQuantityInmL(IngredientUnit unit, int amountQuantity, int partAmount, double expectedAmountQuantity) { String ingredientKey = "IngredientKey"; String ingredientName = "Ingredient Name"; Ingredient ingredient = new Ingredient(ingredientKey, amountQuantity, unit, ingredientName); ingredient.SetPartAmount(partAmount); Assert.AreEqual(expectedAmountQuantity, ingredient.AmountQuantityInmL); }
public void IngredientSingleIngredientChoiceConstructorTest() { String ingredientKey = "IngredientKey"; double amountQuantity = 10; IngredientUnit unit = IngredientUnit.Bottle; String ingredientName = "Ingredient Name"; Ingredient ingredient = new Ingredient(ingredientKey, amountQuantity, unit, ingredientName); Assert.AreEqual(ingredientKey, ingredient.Key); Assert.AreEqual(amountQuantity, ingredient.AmountQuantity); Assert.AreEqual(unit, ingredient.AmountUnit); Assert.AreEqual(ingredientName, ingredient.Name); }
private void TestParsing(String xmlString, String key, double quantity, IngredientUnit unit) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlString); Ingredient result = Ingredient.CreateFromXml(doc.LastChild, new Dictionary <String, String> { { key, "test name" }, }); Assert.AreEqual(key, result.Key); Assert.AreEqual(quantity, result.AmountQuantity); Assert.AreEqual(unit, result.AmountUnit); Assert.AreEqual("test name", result.Name); }
public void IngredientGetAvailableKeysNoChoicesTest() { String ingredientKey = "IngredientKey"; double amountQuantity = 10; IngredientUnit unit = IngredientUnit.Bottle; String ingredientName = "Ingredient Name"; List <IngredientChoice> choices = new List <IngredientChoice>(); Ingredient ingredient = new Ingredient(ingredientKey, choices, amountQuantity, unit, ingredientName); IEnumerable <String> result = ingredient.GetAvailableKeys(new List <String> { "IngredientChoice1", "IngredientChoice2", "IngredientChoice3", }); Assert.AreEqual(0, result.Count()); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { IngredientUnit unit = (IngredientUnit)value; FieldInfo field = value.GetType().GetField(unit.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])field.GetCustomAttributes( typeof(DescriptionAttribute), false); if (attributes != null && attributes.Length > 0) { return(attributes[0].Description); } else { return(unit.ToString()); } }
public void IngredientFullConstructorTest() { String ingredientKey = "IngredientKey"; List <IngredientChoice> choices = new List <IngredientChoice> { new IngredientChoice("IngredientChoice1", "Ingredient Choice One"), new IngredientChoice("IngredientChoice2", "Ingredient Choice Two"), new IngredientChoice("IngredientChoice3", "Ingredient Choice Three"), }; double amountQuantity = 10; IngredientUnit unit = IngredientUnit.Bottle; String ingredientName = "Ingredient Name"; Ingredient ingredient = new Ingredient(ingredientKey, choices, amountQuantity, unit, ingredientName); Assert.AreEqual(ingredientKey, ingredient.Key); Assert.AreEqual(amountQuantity, ingredient.AmountQuantity); Assert.AreEqual(unit, ingredient.AmountUnit); Assert.AreEqual(ingredientName, ingredient.Name); }
public void IngredientGetAvailableKeysOneChoiceTest() { String ingredientKey = "IngredientKey"; double amountQuantity = 10; IngredientUnit unit = IngredientUnit.Bottle; String ingredientName = "Ingredient Name"; List <IngredientChoice> choices = new List <IngredientChoice> { new IngredientChoice("IngredientChoice1", "Ingredient Choice One"), }; Ingredient ingredient = new Ingredient(ingredientKey, choices, amountQuantity, unit, ingredientName); IEnumerable <String> result = ingredient.GetAvailableKeys(new List <String> { "IngredientChoice1", "IngredientChoice2", "IngredientChoice3", }); Assert.AreEqual(1, result.Count()); Assert.IsTrue(result.Any(d => d.Equals(choices[0].Key))); }
internal Ingredient(String key, double amountQuantity, IngredientUnit amountUnit, String name) : this(key, new List <IngredientChoice> { new IngredientChoice(key, name) }, amountQuantity, amountUnit, name) { }
public static Ingredient CreateFromXml(XmlNode ingredientNode, Dictionary <String, String> userNameLookup) { IngredientUnit unit = IngredientUnit.Part; switch (ingredientNode.Attributes["Unit"].Value) { case "(ice)": case "ice": unit = IngredientUnit.Ice; break; case "(piece)": case "piece": unit = IngredientUnit.Piece; break; case "part": unit = IngredientUnit.Part; break; case "dash": unit = IngredientUnit.Dash; break; case "teaspoon": unit = IngredientUnit.Teaspoon; break; case "splash": unit = IngredientUnit.Splash; break; case "(whipped_cream)": unit = IngredientUnit.Whipped_Cream; break; case "pint": unit = IngredientUnit.Pint; break; case "scoop": unit = IngredientUnit.Scoop; break; case "half": unit = IngredientUnit.Half; break; case "pinch": unit = IngredientUnit.Pinch; break; case "drop": unit = IngredientUnit.Drop; break; case "bottle": unit = IngredientUnit.Bottle; break; case "litre": unit = IngredientUnit.Litre; break; default: break; } if (ingredientNode.LocalName.Equals("Ingredient")) { if (!userNameLookup.Keys.Contains(ingredientNode.Attributes["Key"].Value)) { return(null); } return(new Ingredient(ingredientNode.Attributes["Key"].Value, Double.Parse(ingredientNode.Attributes["Quantity"].Value), unit, userNameLookup[ingredientNode.Attributes["Key"].Value])); } else { List <IngredientChoice> choices = new List <IngredientChoice>(); foreach (XmlNode choice in ingredientNode.ChildNodes) { if (!userNameLookup.Keys.Contains(choice.Attributes["Key"].Value)) { return(null); } choices.Add(new IngredientChoice(choice.Attributes["Key"].Value, userNameLookup[choice.Attributes["Key"].Value])); } return(new Ingredient(ingredientNode.Attributes["Key"].Value, choices, Double.Parse(ingredientNode.Attributes["Quantity"].Value), unit, ingredientNode.Attributes["Key"].Value)); } }
public Ingredient(IngredientUnit unit) : base() { Unit = unit; InStoreAmount = 0; }
public Cocktail withIngredient(IngredientUnit ingredientUnit, double amount) { price += (ingredientUnit.GetPrice() * amount); return(this); }
public Cocktail withIngredient(IngredientUnit ingredientUnit) { return(withIngredient(ingredientUnit, 1)); }