Ejemplo n.º 1
0
        public void Deserialize_UnknownTagThrowsWhenStrictModeEnabled()
        {
            string xml = @"
                <HOPS>
                    <HOP>
                        <NAME>Goldings, East Kent</NAME>
                        <VERSION>1</VERSION>
                        <ALPHA>5.0</ALPHA>
                        <AMOUNT>0.0638</AMOUNT>
                        <USE>Dry Hop</USE>
                        <TIME>60.0</TIME>
                        <NOTES>Great all purpose UK hop for ales, stouts, porters</NOTES>
                    </HOP>
                    <UNKNOWN_TAG>UNKNOWN TAG</UNKNOWN_TAG>
                </HOPS>";

            Mock <IStreamFactory> streamFactory = new Mock <IStreamFactory>();

            using (MemoryStream ms = CommonUtilities.GetTestXmlStream(xml))
            {
                streamFactory.Setup(f => f.GetFileStream(It.IsAny <string>(), It.IsAny <FileMode>())).Returns(ms);

                IBeerXMLSerializer s = new XDocumentBeerXMLSerializer()
                {
                    StreamFactory = streamFactory.Object, StrictModeEnabled = true
                };

                // test is successful if this does not throw
                Hops step = (Hops)s.Deserialize(It.IsAny <string>());
            }
        }
Ejemplo n.º 2
0
        private void AddHopsIngredient(Hops hops)
        {
            HopsIngredientDataModel hopsIngredient = HopsUtility.CreateHopsIngredient(hops, CurrentRecipe.RecipeId);

            hopsIngredient.Amount           = m_settings.HopsAmount;
            hopsIngredient.PropertyChanged += CurrentRecipe.Ingredient_PropertyChanged;
            CurrentRecipe.HopsIngredients.Add(hopsIngredient);
        }
Ejemplo n.º 3
0
 public static HopsIngredientDataModel CreateHopsIngredient(Hops hopsInfo, int recipeId)
 {
     HopsIngredientDataModel hopsIngredient = null;
     using (SQLiteConnection connection = DatabaseUtility.GetNewConnection())
     {
         hopsIngredient = CreateHopsIngredient(hopsInfo, recipeId, connection);
         connection.Close();
     }
     return hopsIngredient;
 }
Ejemplo n.º 4
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            string msg = null;
            var    h   = new Hops();

            h.Name        = NameTextBox.Text;
            h.Country     = CountryTextBox.Text;
            h.Substitutes = SubstTextBox.Text;
            h.Purpose     = PurposeComboBox.Text;


            if (!ParseMaxMinAcid(h.AlphaAcid, AlphaAcidTextBox.Text))
            {
                msg = "Please state a valid float value for Alpha acid";
            }

            if (!ParseMaxMinAcid(h.BetaAcid, BetaAcidTextBox.Text))
            {
                msg = "Please state a valid float value for Beta acid";
            }


            if (!ParseMaxMinAcid(h.CoHumulone, coHumTextBox.Text))
            {
                msg = "Please state a valid float value for cohumulone";
            }

            if (msg != null)
            {
                MessageBox.Show(msg);
                return;
            }

            try {
                Repo.AddHops(h);

                RefreashListview();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message);
            }


            // Reset GUI
            AddButton.Content = "Add";

            NameTextBox.Text      = String.Empty;
            coHumTextBox.Text     = String.Empty;
            BetaAcidTextBox.Text  = String.Empty;
            AlphaAcidTextBox.Text = String.Empty;
            CountryTextBox.Text   = String.Empty;
            SubstTextBox.Text     = String.Empty;
            PurposeComboBox.Text  = String.Empty;
        }
        public void GetBitternessTest()
        {
            Hops fuggles = new Hops("Fuggles", new HopsCharacteristics(4.50f, 2.00f), "Test Notes", "UK");
            HopsIngredient fugglesInRecipe = new HopsIngredient(fuggles) { Amount = 1f, Form = HopsForm.Leaf, Use = HopsUse.Boil, FlavorType = HopsFlavorType.Bittering, Time = 60 };

            Hops goldings = new Hops("Goldings", new HopsCharacteristics(5.00f, 3.50f), "Test Notes", "UK");
            HopsIngredient goldingsInRecipe = new HopsIngredient(goldings) { Amount = 1f, Form = HopsForm.Pellet, Use = HopsUse.Boil, FlavorType = HopsFlavorType.Aroma, Time = 15 };

            List<HopsIngredient> hopsUsed = new List<HopsIngredient>() { fugglesInRecipe, goldingsInRecipe };
            int bitterness = BitternessUtility.GetBitterness(hopsUsed, 5f, 1.054f);
            Assert.AreEqual(23, bitterness);
        }
Ejemplo n.º 6
0
    float CalculateIBUs(int hopIndex, float hopQuantity, float waterVolume, float hoptime, float wortGravity)
    {
        float IBUout         = 0;
        Hops  hops           = companyInventory.availableHops[hopIndex];
        float alphaacids     = hops.alphaacids;
        float aaRating       = (alphaacids * hopQuantity * 1000) / (waterVolume * 1000);
        float bignessFactor  = 1.65f * Mathf.Pow(0.000125f, (wortGravity - 1f));
        float boilTimeFactor = (1 - Mathf.Exp(-0.04f * hoptime)) / 4.15f;

        IBUout = aaRating * boilTimeFactor * bignessFactor; //This is all from https://realbeer.com/hops/research.html and should be roughly correct
        return(IBUout);
    }
Ejemplo n.º 7
0
        public IActionResult Update(string oid, [FromBody] Hops hops)
        {
            var hopsDb = _hopsRepository.Find(x => x.Oid == new Guid(oid));

            hopsDb.Name        = hops.Name;
            hopsDb.Description = hops.Description;
            hopsDb.Link        = hops.Link;
            hopsDb.Vendor      = hops.Vendor;

            _hopsRepository.Update(hopsDb);

            _unitOfWork.Complete();
            return(Ok(hopsDb));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor for Packet
 /// </summary>
 /// <param name="Src">Source-Node</param>
 /// <param name="Dest">Destination-Node</param>
 /// <param name="T">TTL</param>
 /// <param name="ExpRes">Expected Result</param>
 public Packet(Hardwarenode Src, Hardwarenode Dest,
               int T, bool ExpRes)
 {
     Source      = Src;
     Destination = Dest;
     if (Source == null || Destination == null)
     {
         Result.ErrorId   = Result.Errors.SourceDestinationNull;
         Result.Res       = Result.ResultStrings[(int)Result.ErrorId];
         Result.SendError = true;
     }
     Ttl            = T;
     ExpectedResult = ExpRes;
     Hops.Add(Source);
 }
Ejemplo n.º 9
0
        public void Hops_Valid_NonEmpty()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 10
0
        public void Hops_Invalid_BadType()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Sends this packet to the destination.
        /// </summary>
        /// <returns>The Returnpacket if sending to destination was successfull or null</returns>
        public Packet Send()
        {
            ValidationInfo valInfo = new ValidationInfo
            {
                NextNodeIp = null,
                Res        = Result,
                Source     = Source as Workstation
            };

            while (!Hops[Hops.Count - 1].Equals(Destination) && valInfo.Res.ErrorId == 0 && Ttl > 0)
            {
                List <Hardwarenode> nextNodes = Hops[Hops.Count - 1].Send(Destination, tags, valInfo);
                if (nextNodes != null)
                {
                    if (nextNodes[nextNodes.Count - 1].Receive(tags, valInfo, Destination))
                    {
                        Ttl--;
                    }
                    foreach (Hardwarenode n in nextNodes)
                    {
                        Hops.Add(n);
                    }
                }
            }
            Result = valInfo.Res;
            if (!Hops[Hops.Count - 1].Equals(Destination) && Ttl == 0)
            {
                //TTL Error
                Result.ErrorId   = Result.Errors.TtlError;
                Result.Res       = Result.ResultStrings[(int)Result.ErrorId];
                Result.SendError = true;
            }
            if (Result.ErrorId == 0 && tags.Count != 0)
            {
                //Layer Error
                Result.ErrorId    = Result.Errors.CustomLayerError;
                Result.Res        = String.Format(Result.ResultStrings[(int)Result.ErrorId], tags.Keys.First());
                Result.LayerError = new CustomLayer(tags.Keys.First(), 0);
                Result.SendError  = false;
            }
            if (Result.ErrorId == 0)
            {
                return(new Packet(Destination, Source, Ttl, ExpectedResult));
            }
            return(null);
        }
Ejemplo n.º 12
0
        internal static HopsIngredientDataModel CreateHopsIngredient(Hops hopsInfo, int recipeId, SQLiteConnection connection)
        {
            using (SQLiteCommand insertCommand = connection.CreateCommand())
            {
                insertCommand.CommandText = "INSERT INTO HopsIngredients (amount, time, type, form, use, hopsInfo) VALUES(0, 0, 'Bittering', 'Leaf', 'Boil', (SELECT id FROM Hops WHERE name = @name))";
                insertCommand.Parameters.AddWithValue("name", hopsInfo.Name);
                insertCommand.ExecuteNonQuery();
            }
            HopsIngredientDataModel hopsIngredient = new HopsIngredientDataModel(hopsInfo, DatabaseUtility.GetLastInsertedRowId(connection));

            using (SQLiteCommand insertJunctionCommand = connection.CreateCommand())
            {
                insertJunctionCommand.CommandText = "INSERT INTO HopsInRecipe (hopsIngredient, recipe) VALUES(@hopsIngredientId, @recipeId)";
                insertJunctionCommand.Parameters.AddWithValue("hopsIngredientId", hopsIngredient.HopsId);
                insertJunctionCommand.Parameters.AddWithValue("recipeId", recipeId);
                insertJunctionCommand.ExecuteNonQuery();
            }
            return hopsIngredient;
        }
Ejemplo n.º 13
0
        public void AddHops(Hops aHop)
        {
            var hopInRepoFound = hopses.Any(x => x.Name == aHop.Name);

            if (hopInRepoFound)
            {
                // Try to remove it if we find it.
                var hopInRepo = hopses.FirstOrDefault(x => x.Name == aHop.Name);
                hopses.Remove(hopInRepo);
                // Always add whatever has been updated. This will cause duplicate data in some situations.
                // This implies that name is not allowed to be changed during update. Improvement ... TODO
                hopses.Add(aHop);
            }
            else
            {
                hopses.Add(aHop);
            }
            Persist();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Recipe"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="style">The style.</param>
        /// <param name="brewer">The brewer.</param>
        /// <param name="batchSize">Size of the batch.</param>
        /// <param name="boilSize">Size of the boil.</param>
        /// <param name="boilTime">The boil time.</param>
        /// <param name="hops">The hops.</param>
        /// <param name="fermentables">The fermentables.</param>
        /// <param name="miscs">The miscs.</param>
        /// <param name="yeasts">The yeasts.</param>
        /// <param name="waters">The waters.</param>
        /// <param name="mash">The mash.</param>
        /// <param name="name">The name.</param>
        /// <param name="version">The version.</param>
        public Recipe(
            RecipeType type,
            Style style,
            string brewer,
            double batchSize,
            double boilSize,
            double boilTime,
            Hops hops,
            Fermentables fermentables,
            Miscs miscs,
            Yeasts yeasts,
            Waters waters,
            Mash mash,
            string name,
            int version = Constants.DEFAULT_BEER_XML_VERSION) : base(name, version)
        {
            Validation.ValidateGreaterThanZero(batchSize);
            Validation.ValidateGreaterThanZero(boilSize);
            Validation.ValidateGreaterThanZero(boilTime);
            Validation.ValidateNotNull(style);
            Validation.ValidateNotNull(hops);
            Validation.ValidateNotNull(fermentables);
            Validation.ValidateNotNull(miscs);
            Validation.ValidateNotNull(yeasts);
            Validation.ValidateNotNull(waters);
            Validation.ValidateNotNull(mash);

            this.Type         = type;
            this.Style        = style;
            this.Brewer       = brewer;
            this.Batch_Size   = batchSize;
            this.Boil_Size    = boilSize;
            this.Boil_Time    = boilTime;
            this.Hops         = hops;
            this.Fermentables = fermentables;
            this.Miscs        = miscs;
            this.Yeasts       = yeasts;
            this.Waters       = waters;
            this.Mash         = mash;
        }
Ejemplo n.º 15
0
        public string ToMarkdown()
        {
            var sb = new StringBuilder();

            sb.Append(this.GenerateHeader());

            sb.AppendLine();
            sb.AppendLine("## Grain");
            sb.AppendLine();
            if (Grains.Any())
            {
                sb.AppendLine("| Name | Amount %|");
                sb.AppendLine("| ---- | ------: |");
                foreach (var grain in Grains)
                {
                    sb.AppendLine(grain.ToMarkdown());
                }
                sb.AppendLine();
            }
            if (Hops.Any())
            {
                sb.AppendLine("## Hops");
                sb.AppendLine();
                sb.AppendLine("| Name | Amount | Time |");
                sb.AppendLine("| ---- | -----: | ---: |");
                foreach (var hop in Hops)
                {
                    sb.AppendLine(hop.ToMarkdown());
                }
                sb.AppendLine();
            }
            sb.AppendLine("## Yeast");
            sb.AppendLine(Yeast);
            sb.AppendLine();
            sb.AppendLine("## Notes");
            sb.AppendLine(Notes);

            return(sb.ToString());
        }
Ejemplo n.º 16
0
 public void RemoveHops(Hops aHop)
 {
     hopses.Remove(aHop);
     Persist();
 }
Ejemplo n.º 17
0
 internal static IEnumerable<HopsIngredientDataModel> GetHopsIngredientsForRecipe(int recipeId, SQLiteConnection connection)
 {
     using (SQLiteCommand selectIngredientsCommand = connection.CreateCommand())
     {
         selectIngredientsCommand.CommandText = "SELECT HopsIngredients.id, HopsIngredients.amount, HopsIngredients.time, HopsIngredients.type, HopsIngredients.form, Hops.name, Hops.alpha, HopsIngredients.use, Hops.notes, Hops.beta, Hops.hsi, Hops.origin, HopsIngredients.dryHopTime FROM HopsIngredients " +
             "JOIN HopsInRecipe ON HopsInRecipe.hopsIngredient = HopsIngredients.id AND HopsInRecipe.recipe = @recipeId " +
             "JOIN Hops ON Hops.id = HopsIngredients.hopsInfo";
         selectIngredientsCommand.Parameters.AddWithValue("recipeId", recipeId);
         using (SQLiteDataReader reader = selectIngredientsCommand.ExecuteReader())
         {
             while (reader.Read())
             {
                 HopsCharacteristics characteristics = new HopsCharacteristics(reader.GetFloat(6), reader.GetFloat(9)) { Hsi = reader.GetFloat(10) };
                 Hops hopsInfo = new Hops(reader.GetString(5), characteristics, reader.GetString(8), reader.GetString(11));
                 string dryHopTimeValue = reader[12].ToString();
                 int? dryHopTime = dryHopTimeValue.IsNullOrEmpty() ? null : (int?) int.Parse(dryHopTimeValue);
                 yield return new HopsIngredientDataModel(hopsInfo, reader.GetInt32(0))
                 {
                     Amount = reader.GetFloat(1),
                     Time = reader.GetInt32(2),
                     FlavorType = EnumConverter.Parse<HopsFlavorType>(reader[3].ToString()),
                     Form = EnumConverter.Parse<HopsForm>(reader[4].ToString()),
                     Use = EnumConverter.Parse<HopsUse>(reader.GetString(7)),
                     DryHopTime = dryHopTime
                 };
             }
         }
     }
 }
Ejemplo n.º 18
0
 private void AddHopsIngredient(Hops hops)
 {
     HopsIngredientDataModel hopsIngredient = HopsUtility.CreateHopsIngredient(hops, CurrentRecipe.RecipeId);
     hopsIngredient.Amount = m_settings.HopsAmount;
     hopsIngredient.PropertyChanged += CurrentRecipe.Ingredient_PropertyChanged;
     CurrentRecipe.HopsIngredients.Add(hopsIngredient);
 }
Ejemplo n.º 19
0
 public IActionResult Insert([FromBody] Hops hops)
 {
     _hopsRepository.Insert(hops);
     _unitOfWork.Complete();
     return(Ok(hops));
 }
 public HopsIngredientDataModel(Hops hopsInfo, int hopsId)
 {
     m_hopsInfo = hopsInfo;
     m_hopsId = hopsId;
 }
Ejemplo n.º 21
0
        private void HopsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Hops var = (Hops)HopsComboBox.SelectedItem;

            AlphaAcidTextBox.Text = var.AlphaAcid.GetAphaAcid().ToString();
        }
Ejemplo n.º 22
0
        public void Hops_Valid_Empty()
        {
            Hops hops = new Hops();

            Assert.IsTrue(hops.IsValid());
        }
Ejemplo n.º 23
0
 public HopsIngredient(Hops hopsInfo)
 {
     m_hopsInfo = hopsInfo;
 }
Ejemplo n.º 24
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Hops var = (Hops)HopsComboBox.SelectedItem;

            hop = new HopAddition();

            if (var == null)
            {
                MessageBox.Show("Please select a hop in the drop down menu");
                return;
            }
            hop.Hop = var;

            var stage = (HopAdditionStage)StageComboBox.SelectedItem;

            hop.Stage = stage;

            int timeMinutes;

            if (int.TryParse(TimeDurationTextBox.Text, out timeMinutes))
            {
                hop.Duration = timeMinutes;
            }
            else
            {
                MessageBox.Show(String.Format("Unable to interpreter {0} as a integer value. Please provide a correct integer value in Time", TimeDurationTextBox.Text));
            }


            float amount;

            if (float.TryParse(AmountTextBox.Text, out amount))
            {
                if (UnitCheckBox.IsChecked == false)
                {
                    hop.Bitterness = (int)Math.Round(amount, 0);
                    hop.AmountUnit = HopAmountUnitE.IBU;
                }
                else
                {
                    hop.Amount     = Math.Round(amount, 2);
                    hop.AmountUnit = HopAmountUnitE.GRAMS_PER_LITER;
                }
            }
            else
            {
                MessageBox.Show(String.Format("Unable to interpreter {0} as a float value. Please provide a correct float value in Part", AmountTextBox.Text));
            }


            float alphaAcid;

            if (float.TryParse(AlphaAcidTextBox.Text, out alphaAcid))
            {
                HopAcids acid = new HopAcids();
                acid.Min      = alphaAcid;
                hop.AlphaAcid = acid;
            }
            else
            {
                MessageBox.Show(String.Format("Unable to interpreter {0} as a float value. Please provide a correct float value in Part", AlphaAcidTextBox.Text));
            }

            this.Close();
        }