private IShoppingBasketItem CreateBasketItem(long id, Item name, decimal unitPrice, int quantity, IEnumerable <ITaxRule> taxRules)
        {
            var subTotal   = unitPrice * quantity;
            var basketItem = new DefaultShoppingBasketItem(id, name, unitPrice, taxRules)
            {
                Quantity = quantity,
                SubTotal = subTotal,
                Total    = subTotal
            };

            return(basketItem);
        }
示例#2
0
        public decimal CalculateTax(IShoppingBasket basket, IShoppingBasketItem item)
        {
            var unitItemTax = 0m;

            foreach (var band in _taxBands)
            {
                var applicableValue = (band.Cap ?? item.UnitPrice) - band.Threshold;

                var temporaryItem = new DefaultShoppingBasketItem {
                    SubTotal = applicableValue, Quantity = 1
                };                                                                                               // remove explicit instantiation from here
                unitItemTax += band.TaxRule.CalculateTax(basket, temporaryItem);
            }

            var itemTax = unitItemTax * item.Quantity;

            UpdateTotals(basket, item, itemTax);

            return(itemTax);
        }