/// <summary> /// Inserting coints to the machine. Saving them in order buffer /// </summary> /// <param name="amount">Amount of coins inserted</param> /// <returns></returns> public Money InsertCoin(Money amount) { if (!MoneyHelper.ValidateInsertedCoin(amount)) { throw new ArgumentException("Coin not supported"); } var _backedBuffer = _moneyHolder.GetBufferedAmount(); try { _moneyHolder.AddBufferedAmount(amount); return(_moneyHolder.GetBufferedAmount()); } catch (Exception ex) { // in case of calculation failed revert buffer to previous state // and throw exception _moneyHolder.SetBuffedAmount(_backedBuffer); throw ex; } }