Exemplo n.º 1
0
 public IngredientUsage(Ingredient ingredient, IngredientForm form, Amount amount, string prepnote)
 {
     Ingredient = ingredient;
     Form = form;
     Amount = amount;
     PrepNote = prepnote;
 }
Exemplo n.º 2
0
 public IngredientUsage(Ingredient ingredient, IngredientForm form, Amount amount, String prepnote)
 {
     Ingredient = ingredient;
     Form       = form;
     Amount     = amount;
     PrepNote   = prepnote;
 }
Exemplo n.º 3
0
        public void TestFormConverter()
        {
            //Form conversions (Unit ingredients)
             var unitIng = new Ingredient() {ConversionType = UnitType.Unit, UnitWeight = 200}; //Ingredient sold by units (unit weighs 200g)
             var unitIng_UnitForm = new IngredientForm() {FormAmount = new Amount(50, Units.Gram), ConversionMultiplier = 1, FormUnitType = Units.Unit}; //Form expressed in units (unit in this form weighs 50g)
             var unitIng_WeightForm = new IngredientForm() {ConversionMultiplier = 1, FormUnitType = Units.Ounce}; //Form expressed by weight
             var unitIng_VolForm = new IngredientForm() {FormUnitType = Units.Cup, ConversionMultiplier = 1, FormAmount = new Amount(20, Units.Gram)}; //Each cup weighs 20g)

             var unitIng_UnitUsage = new IngredientUsage() {Amount = new Amount(4, Units.Unit), Form = unitIng_UnitForm, Ingredient = unitIng};
             var unitIng_WeightUsage = new IngredientUsage() {Amount = new Amount(300, Units.Gram), Form = unitIng_WeightForm, Ingredient = unitIng};
             var unitIng_VolUsage = new IngredientUsage() {Amount = new Amount(160, Units.Tablespoon), Form = unitIng_VolForm, Ingredient = unitIng}; //10 cups

             var unitIng_UnitAmt = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_UnitUsage);
             var unitIng_WeightAmt = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_WeightUsage);
             var unitIng_VolAmt = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_VolUsage);

             Assert.AreEqual(1.0f, unitIng_UnitAmt.SizeHigh); //4 units in this form should convert to 1 unit of ingredient
             Assert.AreEqual(Units.Unit, unitIng_UnitAmt.Unit);

             Assert.AreEqual(2.0f, unitIng_WeightAmt.SizeHigh); //300g of this form should convert to 1.5 units of ingredient, however we round up to whole units
             Assert.AreEqual(Units.Unit, unitIng_WeightAmt.Unit);

             //TODO: Fix
             //Assert.AreEqual(1.0f, unitIng_VolAmt.SizeHigh); //10 cups of this form should convert to 1 unit of ingredient
             //Assert.AreEqual(Units.Unit, unitIng_VolAmt.Unit);

             //Form conversions (Volume ingredients)
             var volIng = new Ingredient() {ConversionType = UnitType.Volume}; //Ingredient sold by volume
             var volIng_UnitForm = new IngredientForm() {FormUnitType = Units.Unit, ConversionMultiplier = 1, FormAmount = new Amount(5, Units.Teaspoon)};
             var volIng_WeightForm = new IngredientForm() {FormUnitType = Units.Ounce, ConversionMultiplier = 1, FormAmount = new Amount(2, Units.Teaspoon)};

             var volIng_UnitUsage = new IngredientUsage() {Amount = new Amount(2, Units.Unit), Form = volIng_UnitForm, Ingredient = volIng};
             var volIng_WeightUsage = new IngredientUsage() {Amount = new Amount(0.25f, Units.Pound), Form = volIng_WeightForm, Ingredient = volIng}; //4oz

             var volIng_UnitAmt = FormConversion.GetNativeAmountForUsage(volIng, volIng_UnitUsage);
             var volIng_WeightAmt = FormConversion.GetNativeAmountForUsage(volIng, volIng_WeightUsage);

             Assert.AreEqual(10.0f, volIng_UnitAmt.SizeHigh);
             Assert.AreEqual(Units.Teaspoon, volIng_UnitAmt.Unit);

             Assert.AreEqual(8.0f, volIng_WeightAmt.SizeHigh);
             Assert.AreEqual(Units.Teaspoon, volIng_WeightAmt.Unit);

             //Form conversions (Weight ingredients)
             var weightIng = new Ingredient() {ConversionType = UnitType.Weight}; //Ingredient sold by weight
             var weightIng_UnitForm = new IngredientForm() {ConversionMultiplier = 1, FormUnitType = Units.Unit, FormAmount = new Amount(100, Units.Gram)};
             var weightIng_VolForm = new IngredientForm() {ConversionMultiplier = 1, FormUnitType = Units.Cup, FormAmount = new Amount(50, Units.Gram)};

             var weightIng_UnitUsage = new IngredientUsage() {Amount = new Amount(5, Units.Unit), Form = weightIng_UnitForm, Ingredient = weightIng};
             var weightIng_VolUsage = new IngredientUsage() {Amount = new Amount(144, Units.Teaspoon), Form = weightIng_VolForm, Ingredient = weightIng}; //3 cups

             var weightIng_UnitAmt = FormConversion.GetNativeAmountForUsage(weightIng, weightIng_UnitUsage);
             var weightIng_VolAmt = FormConversion.GetNativeAmountForUsage(weightIng, weightIng_VolUsage);

             Assert.AreEqual(500.0f, weightIng_UnitAmt.SizeHigh);
             Assert.AreEqual(Units.Gram, weightIng_UnitAmt.Unit);

             Assert.AreEqual(150.0f, weightIng_VolAmt.SizeHigh);
             Assert.AreEqual(Units.Gram, weightIng_VolAmt.Unit);
        }
Exemplo n.º 4
0
 public IngredientUsage(Ingredient ingredient, IngredientForm form, Amount amount, string preparationNote)
 {
     this.Ingredient = ingredient;
     this.Form = form;
     this.Amount = amount;
     this.PreparationNote = preparationNote;
 }
Exemplo n.º 5
0
        public static IngredientBinding Create(Guid ingId, Guid recipeId, Single? qty, Units usageUnit, UnitType convType, Int32 unitWeight,
            Units formUnit, Single equivAmount, Units equivUnit)
        {
            var rawUnit = KitchenPC.Unit.GetDefaultUnitType(convType);

             if (qty.HasValue && rawUnit != usageUnit)
             {
            if (UnitConverter.CanConvert(usageUnit, rawUnit))
            {
               qty = UnitConverter.Convert(qty.Value, usageUnit, rawUnit);
            }
            else
            {
               var ing = new Ingredient
               {
                  Id = ingId,
                  ConversionType = convType,
                  UnitWeight = unitWeight
               };

               var form = new IngredientForm
               {
                  FormUnitType = formUnit,
                  FormAmount = new Amount(equivAmount, equivUnit),
                  IngredientId = ingId
               };

               var usage = new Ingredients.IngredientUsage
               {
                  Form = form,
                  Ingredient = ing,
                  Amount = new Amount(qty.Value, usageUnit)
               };

               try
               {
                  var newAmt = FormConversion.GetNativeAmountForUsage(ing, usage);
                  qty = UnitConverter.Convert(newAmt.SizeHigh, newAmt.Unit, rawUnit); //Ingredient graph only stores high amounts
               }
               catch (Exception e)
               {
                  throw new DataLoadException(e);
               }
            }
             }

             return new IngredientBinding
             {
            RecipeId = recipeId,
            IngredientId = ingId,
            Qty = qty.HasValue ? (float?) Math.Round(qty.Value, 3) : null,
            Unit = rawUnit
             };
        }
Exemplo n.º 6
0
 public InvalidFormException(Ingredient ing, IngredientForm form)
 {
     Ingredient = ing;
      Form = form;
 }
 public InvalidFormException(Ingredient ingredient, IngredientForm form)
 {
     this.Ingredient = ingredient;
     this.Form = form;
 }
 public void AddForm(IngredientForm form)
 {
     this.forms.Add(form);
 }
 public IngredientUsageCreator WithForm(IngredientForm form)
 {
     this.Usage.Form = form;
     return this;
 }
Exemplo n.º 10
0
 public void AddForm(IngredientForm form)
 {
     this.forms.Add(form);
 }
Exemplo n.º 11
0
 public bool TryGetValue(NameIngredientPair key, out IngredientForm value)
 {
     return pairs.TryGetValue(key, out value);
 }
Exemplo n.º 12
0
 public void Add(NameIngredientPair key, IngredientForm value)
 {
     pairs.Add(key, value);
 }