Inheritance: FermentableBase
Esempio n. 1
0
        public void Fermentable_Invalid_CombinationErrorCode()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Dry_Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Ibu_Gal_Per_Lb = 5;
            ferm.Moisture       = 5;

            ValidationCode errorCode = ValidationCode.SUCCESS;

            ValidationCode expected = ValidationCode.HOPPED_FERMENTABLE_EXTRACT_ONLY | ValidationCode.GRAIN_DETAILS_ONLY_GRAIN_TYPE;

            ferm.IsValid(ref errorCode);

            Assert.AreEqual(expected, errorCode);
        }
        public async Task <ActionResult <FermentableType> > PostFermentableType(FermentableType fermentableType)
        {
            _context.FermentableType.Add(fermentableType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFermentableType", new { id = fermentableType.FermentableTypeId }, fermentableType));
        }
        public async Task <IActionResult> PutFermentableType(int id, FermentableType fermentableType)
        {
            if (id != fermentableType.FermentableTypeId)
            {
                return(BadRequest());
            }

            _context.Entry(fermentableType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FermentableTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public static IEnumerable <Fermentable> GetAvailableFermentables(SQLiteConnection connection)
        {
            SQLiteCommand selectFermentablesCommand = connection.CreateCommand();

            selectFermentablesCommand.CommandText = "SELECT name, yield, yieldByWeight, color, origin, notes, diastaticPower, type, maltCategory, gravityPoint FROM Fermentables";
            using SQLiteDataReader reader         = selectFermentablesCommand.ExecuteReader();
            while (reader.Read())
            {
                string          name                = reader.GetString(0);
                string          yieldValue          = reader[1].ToString();
                float?          yield               = !yieldValue.IsNullOrEmpty() ? (float?)float.Parse(yieldValue) : null;
                string          yieldByWeightValue  = reader[2].ToString();
                float?          yieldByWeight       = !yieldByWeightValue.IsNullOrEmpty() ? (float?)float.Parse(yieldByWeightValue) : null;
                float           color               = reader.GetFloat(3);
                string          origin              = reader.GetString(4);
                string          notes               = reader.GetString(5);
                string          diastaticPowerValue = reader[6].ToString();
                float?          diastaticPower      = !diastaticPowerValue.IsNullOrEmpty() ? (float?)float.Parse(diastaticPowerValue) : null;
                FermentableType type                = EnumConverter.Parse <FermentableType>(reader.GetString(7));
                string          maltCategoryValue   = reader[8].ToString();
                MaltCategory?   maltCategory        = !maltCategoryValue.IsNullOrEmpty() ? (MaltCategory?)EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null;
                int             gravityPoint        = reader.GetInt32(9);

                var characteristics = new FermentableCharacteristics(yield, color, diastaticPower)
                {
                    YieldByWeight = yieldByWeight,
                    Type          = type,
                    MaltCategory  = maltCategory,
                    GravityPoint  = gravityPoint
                };
                yield return(new Fermentable(name, characteristics, notes, origin));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Type")] FermentableType fermentableType)
        {
            if (id != fermentableType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fermentableType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FermentableTypeExists(fermentableType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fermentableType));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Type")] FermentableType fermentableType)
        {
            if (ModelState.IsValid)
            {
                fermentableType.Id = Guid.NewGuid();
                _context.Add(fermentableType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(fermentableType));
        }
Esempio n. 7
0
        public void Fermentable_Valid()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            Assert.IsTrue(ferm.IsValid());
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Fermentable"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="amountInKg">The amount in kg.</param>
        /// <param name="yieldPercent">The yield percent.</param>
        /// <param name="colorInLovibond">The color in lovibond.</param>
        /// <param name="version">The version.</param>
        public Fermentable(
            string name,
            FermentableType type,
            double amountInKg,
            double yieldPercent,
            double colorInLovibond,
            int version = Constants.DEFAULT_BEER_XML_VERSION) : base(name, version)
        {
            Validation.ValidateGreaterThanZero(amountInKg);
            Validation.ValidatePercentileRange(yieldPercent);
            Validation.ValidateGreaterThanZero(colorInLovibond);

            this.Type   = type;
            this.Amount = amountInKg;
            this.Yield  = yieldPercent;
            this.Color  = colorInLovibond;
        }
Esempio n. 9
0
        public void Fermentable_Invalid_Extract_InvalidParam_CoarseFineDiff()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Coarse_Fine_Diff = 5;

            Assert.IsFalse(ferm.IsValid());
        }
Esempio n. 10
0
        public void Fermentable_Valid_Extract_RecommendedMash_False()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Recommended_Mash = false;

            Assert.IsTrue(ferm.IsValid());
        }
Esempio n. 11
0
        public void Fermentable_Invalid_Extract_InvalidParam_DiastaticPower()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Diastatic_Power = 5;

            Assert.IsFalse(ferm.IsValid());
        }
Esempio n. 12
0
        public void Fermentable_Valid_ErrorCode()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            ferm.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Esempio n. 13
0
        public void Fermentable_Invalid_NonExtract_IBU()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Grain;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Ibu_Gal_Per_Lb = 5;

            ValidationCode errorCode = ValidationCode.SUCCESS;

            Assert.IsFalse(ferm.IsValid(ref errorCode));
            Assert.AreEqual(ValidationCode.HOPPED_FERMENTABLE_EXTRACT_ONLY, errorCode);
        }
Esempio n. 14
0
        public void Fermentable_Invalid_Extract_InvalidParam_CorrectErrorCode()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Protein = 5;

            ValidationCode errorCode = ValidationCode.SUCCESS;

            ferm.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.GRAIN_DETAILS_ONLY_GRAIN_TYPE, errorCode);
        }
Esempio n. 15
0
        /// <summary>
        /// Adds a fermentable item to the data set.
        /// </summary>
        public Fermentable AddFermentable(string name, FermentableType fermentableType, string notes)
        {
            Fermentable fermentable = new Fermentable(name, fermentableType);

            fermentable.Notes = notes;

            return fermentable;

            //<NAME>Barley Hulls</NAME>
            // <VERSION>1</VERSION>
            // <TYPE>Adjunct</TYPE>
            // <AMOUNT>0.0000000</AMOUNT>
            // <YIELD>0.0000000</YIELD>
            // <COLOR>0.0000000</COLOR>
            // <ADD_AFTER_BOIL>FALSE</ADD_AFTER_BOIL>
            // <ORIGIN>US</ORIGIN>
            // <SUPPLIER></SUPPLIER>
            // <NOTES>Hulls are introduced to improve the speed of lautering when making high gravity or high adjunct beers.
            //Hulls are neutral in flavor, body and color, and are inert
            //Good for wheat beers, Wits, and others that have high protein mashes.</NOTES>
            // <COARSE_FINE_DIFF>1.5000000</COARSE_FINE_DIFF>
            // <MOISTURE>4.0000000</MOISTURE>
            // <DIASTATIC_POWER>120.0000000</DIASTATIC_POWER>
            // <PROTEIN>11.7000000</PROTEIN>
            // <MAX_IN_BATCH>5.0000000</MAX_IN_BATCH>
            // <RECOMMEND_MASH>FALSE</RECOMMEND_MASH>
            // <IBU_GAL_PER_LB>0.0000000</IBU_GAL_PER_LB>
            // <DISPLAY_AMOUNT>0.0 oz</DISPLAY_AMOUNT>
            // <INVENTORY>0.0 oz</INVENTORY>
            // <POTENTIAL>1.0000000</POTENTIAL>
            // <DISPLAY_COLOR>0.0 SRM</DISPLAY_COLOR>
            // <EXTRACT_SUBSTITUTE></EXTRACT_SUBSTITUTE>
        }