コード例 #1
0
        /// <summary>
        /// Accept the payment already inserted and then dispense the change. Dispense amount can't be greater than paymentAmount.
        ///
        /// Note: The accept and payment is in one method call to prevent change being dispense without accepting the payment first :)
        /// </summary>
        /// <param name="change">The change to return.</param>
        /// <returns>True if success. Else false.</returns>
        public bool TryAcceptPaymentAndDispenseChange(int change)
        {
            if (change > PaymentAmount)
            {
                _logger.LogError("Cannot return change that is more than the payment amount.");
                return(false);
            }

            var coinsToReturn = _coinReturnAlgorithm.Calculate(_coinInventory, change);

            if (coinsToReturn == null)
            {
                _logger.LogError("Change required is not possible using coins in current inventory.");
                return(false);
            }
            return(TryAcceptPayment() ? (TryDispenseChange(coinsToReturn) ? true : false) : false);
        }
コード例 #2
0
 public void Calculate_CoinInventoryIsNull_ThrowArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => algorithm.Calculate(null, 10));
 }