Esempio n. 1
0
        public int SetToasts(int numToasts)
        {
            if (numToasts > 2)
            {
                throw new Exception("The maximum number of toasts is 2.");
            }

            Toaster          toaster = db.Toasters.FirstOrDefault();
            PantryController pantry  = new PantryController();

            if (pantry.HowManyBreads() >= 0)
            {
                toaster.NumToasts = pantry.GetBreads(numToasts);
            }

            db.Entry(toaster).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(toaster.NumToasts);
        }
Esempio n. 2
0
        public void GetStatus_ShouldBeFullStatusPantry()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(91);

            Assert.IsTrue(controller.GetStatus() == PantryStatus.Full, "Pantry full of breads");
        }
Esempio n. 3
0
        public void GetStatus_ShouldBeNormalStatusPantry()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(49);

            Assert.IsTrue(controller.GetStatus() == PantryStatus.Normal, "Pantry normal number of breads");
        }
Esempio n. 4
0
        public void GetStatus_ShouldBeAlmostEmptyStatusPantry()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(6);

            Assert.IsTrue(controller.GetStatus() == PantryStatus.AlmostEmpty, "Pantry almost empty of breads");
        }
Esempio n. 5
0
        public void HasBread_ShouldHaveBread()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(0);
            controller.BuyToSupermarket(20);

            Assert.IsTrue(controller.HasBread(), "Pantry has bread");
        }
Esempio n. 6
0
        public void PutBreads_ShouldReturn50BreadsInPantry()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(50);

            int howmanybreads = controller.HowManyBreads();

            Assert.IsTrue(howmanybreads == 50, "There are 50 breads in pantry");
        }
Esempio n. 7
0
        public void BuyToSupermarket()
        {
            var controller = new IToast.Controllers.PantryController();

            int breadsToBuy = 20;

            int howManyBreadsBeforeBuying = controller.HowManyBreads();

            controller.BuyToSupermarket(breadsToBuy);

            int howManyBreadsAfterBuying = controller.HowManyBreads();

            Assert.AreEqual(howManyBreadsAfterBuying - howManyBreadsBeforeBuying, breadsToBuy, "Buying " + breadsToBuy + " breads correctly");
        }
Esempio n. 8
0
        public void GetBreads_ShouldTwoBreadsMinus()
        {
            var controller = new IToast.Controllers.PantryController();

            controller.PutBreads(50);

            int toasts = 2;

            int howManyBreadsBeforeToasting = controller.HowManyBreads();

            controller.GetBreads(toasts);

            int howManyBreadsAfterToasting = controller.HowManyBreads();

            Assert.AreEqual(howManyBreadsBeforeToasting - howManyBreadsAfterToasting, toasts);
        }
Esempio n. 9
0
        public void HowManyBreads_ShouldReturnMoreThanOneBread()
        {
            var controller = new IToast.Controllers.PantryController();

            Assert.IsTrue(controller.HowManyBreads() > 0, "True, has more almost one bread");
        }