Exemple #1
0
#pragma warning disable CS0246 // The type or namespace name 'Success' could not be found (are you missing a using directive or an assembly reference?)
        /// <summary>
        /// Handles the payment
        /// </summary>
        /// <param name="moneyGiven"></param>
        /// <returns></returns>
        private Success HandlePayment(decimal moneyGiven)
#pragma warning restore CS0246 // The type or namespace name 'Success' could not be found (are you missing a using directive or an assembly reference?)
        {
            decimal valueToReturn = moneyGiven - Cart.GetTransactionValue();

            if (tillDrawer.ContainsEnough(valueToReturn))
            {
                ICashSet givenSet = CashController.SmallestSetForValue(moneyGiven);

                ICashSet availableCash = new CashSet(tillDrawer.DrawerContent);
                availableCash.Add(givenSet);

                ICashSet returnSet = PaymentController.Payout(valueToReturn, availableCash);

                if (returnSet != null)
                {
                    consoleDisplay.Print(string.Format("\nReturn {0}, distributed as: {1}",
                                                       valueToReturn.ToString(),
                                                       returnSet.ToString()));

                    tillDrawer.Add(givenSet);
                    tillDrawer.Remove(returnSet);

                    return(new Success(true));
                }
                else
                {
                    return(new Success(false, "\nUnable to allocate sufficient cash; request a different payment method"));
                }
            }
            else
            {
                return(new Success(false, "\nNot enough money in the drawer; request a different payment method"));
            }
        }
Exemple #2
0
        public void CanMakeSingleTypeLimitedCashSet(decimal value)
        {
            CashSet cashSet = (CashSet)CashController.SmallestSetForValue(value, Mocks.MockCashSets.StandardSet);

            ICash item = (from cashItem
                          in cashSet.CashStack
                          where cashItem.Key.UnitValue == value
                          select cashItem.Key).FirstOrDefault();

            cashSet.CashStack.TryGetValue(item, out int amount);

            Assert.AreEqual(1, amount);
        }