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