public VMachine( Wallet wallet, Inventory stock, PricesProvider pricesProvider, IChangeCalculator changeCalculator ) { State = new ReadyToSellProduct(wallet, stock, pricesProvider, this); _changeCalculator = changeCalculator; }
public ReadyToSellProduct( Wallet wallet, Inventory inventory, PricesProvider pricesProvider, VMachine machine ) { InsertedCoins = new List <Coin>(); Wallet = wallet; Inventory = inventory; PricesProvider = pricesProvider; VendingMachine = machine; }
public override void InsertCoins(IEnumerable <Coin> coins) { InsertedCoins.AddRange(coins); var productCost = PricesProvider.GetPrice(SelectedProduct); var diff = productCost - InsertedCoins.Sum(x => (int)x); if (diff > 0) { throw new NotSufficientAmountException("Insufficient amount!", string.Format("{0:N2} Euro", (decimal)diff / 100)); } VendingMachine.State = new ReadyToProcessOrder(this); }