示例#1
0
        public void Test(CoffeeType coffeeType, SugarLevel sugarLevel, Size size)
        {
            var money = coffeeType.Price();

            CoffeeMachine.SelectCoffee(coffeeType);
            CoffeeMachine.InsertMoney(money);
            CoffeeMachine.WorkStatus.Should().Be(WorkStatus.Customization);

            CoffeeMachine.SelectSugarLevel(sugarLevel);
            CoffeeMachine.SelectSize(size);
            CoffeeMachine.WorkStatus.Should().Be(WorkStatus.ReadyForMakingCoffee);

            CoffeeMachine.Run();
            CoffeeMachine.WorkStatus.Should().Be(WorkStatus.TakeYourCoffee);

            CoffeeMachine.GetChange().Should().Be(0);

            var coffee = CoffeeMachine.EjectCup();

            coffee.Should().BeEquivalentTo(new Coffee(coffeeType, sugarLevel, size));
            CoffeeMachine.WorkStatus.Should().Be(WorkStatus.InsertMoneyOrSelectCoffee);
            CoffeeMachine.Size.Should().Be(Size.Unknown);
            CoffeeMachine.SugarLevel.Should().Be(SugarLevel.Unknown);
            CoffeeMachine.CoffeeType.Should().Be(CoffeeType.Unknown);
        }
示例#2
0
 public override void Run()
 {
     if (WorkStatus != WorkStatus.ReadyForMakingCoffee)
     {
         throw new CoffeeMachineException("You can't start making coffee. First, select Coffee Type, Size and Sugar level");
     }
     Balance   -= CoffeeType.Price();
     WorkStatus = WorkStatus.TakeYourCoffee;
 }
示例#3
0
 public override void SelectCoffee(CoffeeType coffeeType)
 {
     if (coffeeType == CoffeeType.Unknown)
     {
         throw new CoffeeMachineException("You must select correct coffee type!");
     }
     CoffeeType = coffeeType;
     WorkStatus = Balance >= CoffeeType.Price() ? WorkStatus.Customization : WorkStatus.InsertMoneyOrSelectCoffee;
 }
示例#4
0
 public override void SelectCoffee(CoffeeType coffeeType)
 {
     if (WorkStatus == WorkStatus.TakeYourCoffee)
     {
         throw new CoffeeMachineException("You can't select coffee type. First, take a cup from the coffee machine");
     }
     CoffeeType = coffeeType;
     WorkStatus = Balance >= CoffeeType.Price() ? WorkStatus.Customization : WorkStatus.InsertMoneyOrSelectCoffee;
 }
 public override void InsertMoney(int moneyAmount)
 {
     if (moneyAmount < 0)
     {
         throw new CoffeeMachineException("Amount must be a positive number");
     }
     Balance   += moneyAmount;
     WorkStatus = CoffeeType != CoffeeType.Unknown && Balance >= CoffeeType.Price()
         ? WorkStatus.Customization
         : WorkStatus.InsertMoneyOrSelectCoffee;
 }
示例#6
0
 public override void Run()
 {
     if (WorkStatus == WorkStatus.TakeYourCoffee)
     {
         throw new CoffeeMachineException("You can't start making coffee. First, take a cup from the coffee machine");
     }
     if (WorkStatus == WorkStatus.InsertMoneyOrSelectCoffee)
     {
         throw new CoffeeMachineException("You can't start making coffee. First, select Coffee Type, Size and Sugar level");
     }
     Balance   -= CoffeeType.Price();
     WorkStatus = WorkStatus.TakeYourCoffee;
 }
 public virtual void Run()
 {
     if (WorkStatus == WorkStatus.TakeYourCoffee)
     {
         throw new CoffeeMachineException("You can't start making coffee. First, take a cup from the coffee machine");
     }
     if (WorkStatus != WorkStatus.ReadyForMakingCoffee)
     {
         throw new CoffeeMachineException("You can't start making coffee. First, select Coffee Type, Size and Sugar level");
     }
     Balance   -= CoffeeType.Price();
     WorkStatus = WorkStatus.TakeYourCoffee;
 }
示例#8
0
        public override void InsertMoney(int moneyAmount)
        {
            if (moneyAmount + Balance < 0)
            {
                throw new CoffeeMachineException("Amount must be a positive number");
            }
            if (WorkStatus == WorkStatus.TakeYourCoffee)
            {
                throw new CoffeeMachineException("You can't insert money. First, take a cup from the coffee machine.");
            }

            Balance   += moneyAmount;
            WorkStatus = CoffeeType != CoffeeType.Unknown && Balance >= CoffeeType.Price()
                ? WorkStatus.Customization
                : WorkStatus.InsertMoneyOrSelectCoffee;
        }