Пример #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Use")] HopUse hopUse)
        {
            if (id != hopUse.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hopUse);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HopUseExists(hopUse.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hopUse));
        }
Пример #2
0
        public void DeserializeHop_CorrectUse_WithUnderscore()
        {
            HopUse use = HopUse.Dry_Hop;

            string xml = $@"
                <HOP>
                    <NAME>Goldings, East Kent</NAME>
                    <VERSION>1</VERSION>
                    <ALPHA>5.0</ALPHA>
                    <AMOUNT>0.0638</AMOUNT>
                    <USE>{EnumUtilities.ConvertEnumToString(use)}</USE>
                    <TIME>60.0</TIME>
                    <NOTES>Great all purpose UK hop for ales, stouts, porters</NOTES>
                </HOP>";

            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
                };

                Hop hop = (Hop)s.Deserialize(It.IsAny <string>());

                Assert.AreEqual(use, hop.Use);
            }
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,Use")] HopUse hopUse)
        {
            if (ModelState.IsValid)
            {
                hopUse.Id = Guid.NewGuid();
                _context.Add(hopUse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hopUse));
        }
Пример #4
0
        public Hop(
            string name,
            double alpha,
            double weightInKg,
            HopUse use,
            int timeInMin,
            int version = Constants.DEFAULT_BEER_XML_VERSION) : base(name, version)
        {
            Validation.ValidatePercentileRange(alpha);
            Validation.ValidateGreaterThanZero(weightInKg);
            Validation.ValidateGreaterThanZero(timeInMin);

            this.Alpha  = alpha;
            this.Weight = weightInKg;
            this.Use    = use;
            this.Time   = timeInMin;
        }