示例#1
0
        /// <summary>
        /// We really only need this - all the string formation is the
        /// responsibility of the caller now.  I left the two methods 'HtmlReceipt and Receipt'
        /// to maintain some consistancy to the original orderTest
        /// </summary>
        /// <param name="formatter"></param>
        /// <returns></returns>
        private string ReceiptProcessor(ReceiptFormatter formatter)
        {
            SubTotal = Taxes = Total = 0;
            var result = new StringBuilder();

            foreach (string headerFormat in formatter.HeaderFormats)
            {
                result.Append(ProcessReceiptFormat(headerFormat));
            }

            foreach (var line in _lines)
            {
                var thisAmount = line.Bike.DiscountMarker.discount(line.Quantity);
                foreach (string lineFormat in formatter.LineFormats)
                {
                    result.Append(ProcessReceiptFormat(lineFormat, line));
                }
                SubTotal += thisAmount;
            }
            Taxes = SubTotal * TaxRate;
            Total = SubTotal + Taxes;
            for (int i = 0; i < formatter.TailFormats.Count - 1; i++)
            {
                result.Append(ProcessReceiptFormat(formatter.TailFormats[i]));
            }
            result.Append(ProcessReceiptFormat(formatter.TailFormats.Last()));
            return(result.ToString());
        }
示例#2
0
 public string Receipt(ReceiptFormatter formatter)
 {
     return(ReceiptProcessor(formatter));
 }