Ejemplo n.º 1
0
        public string Receipt(IReceiptFormatter formatter = null)
        {
            if (formatter == null)
            {
                formatter = new DefaultFormatter();
            }

            var totalAmount = 0d;
            var documentSb  = new StringBuilder();

            var headerSb = new StringBuilder($"Order Receipt for {Company}");

            formatter.FormatHeader(headerSb);
            documentSb.Append(headerSb);

            var allLinesSb = new StringBuilder();

            if (_lines.Any())
            {
                foreach (Line line in _lines)
                {
                    double thisAmount = line.GetChargeAmount() - _discountHandler.Handle(line);
                    var    lineSb     = new StringBuilder($"{line.Quantity} x {line.Bike.Brand} {line.Bike.Model} = {thisAmount:C}");
                    formatter.FormatLine(lineSb);
                    allLinesSb.Append(lineSb);

                    totalAmount += thisAmount;
                }

                formatter.FormatAllLines(allLinesSb);
            }

            documentSb.Append(allLinesSb);

            var subTotalSb = new StringBuilder($"Sub-Total: {totalAmount:C}");

            formatter.FormatSubTotal(subTotalSb);
            documentSb.Append(subTotalSb);

            double tax   = totalAmount * TaxRate;
            var    taxSb = new StringBuilder($"Tax: {tax:C}");

            formatter.FormatTax(taxSb);
            documentSb.Append(taxSb);

            var totalSb = new StringBuilder($"Total: {totalAmount + tax:C}");

            formatter.FormatTotal(totalSb);
            documentSb.Append(totalSb);

            formatter.FormatDocument(documentSb);

            return(documentSb.ToString());
        }
Ejemplo n.º 2
0
        private string GetReceiptString(IReceiptFormatter formatterType)
        {
            var orderInfo = new OrderInfo
            {
                Company   = Company,
                Lines     = _lines.Select(line => new OrderLine(line)).ToList(),
                TaxRate   = DefaultTaxRate,
                Discounts = _discounts
            };

            orderInfo.ApplyQuantityDiscounts();
            return(formatterType.GetReceiptForOrder(orderInfo));
        }
 public ReceiptConsoleAppender(IReceiptFormatter formatter)
 {
     this._formatter = formatter;
 }
Ejemplo n.º 4
0
 public Basket(ITaxCalculator taxCalculator, IReceiptFormatter receiptFormatter) : this(taxCalculator, receiptFormatter, new List <ICanBeSold>())
 {
 }
Ejemplo n.º 5
0
 public Basket(ITaxCalculator taxCalculator, IReceiptFormatter receiptFormatter, List <ICanBeSold> items)
 {
     _taxCalculator    = taxCalculator;
     _receiptFormatter = receiptFormatter;
     _items            = items;
 }
Ejemplo n.º 6
0
 public ReceiptSaver(string savePath, IReceiptFormatter formatter = null)
 {
     Path      = savePath ?? "";
     Formatter = formatter ?? ReceiptFormatter.Default;
 }
Ejemplo n.º 7
0
 public void SetUp()
 {
     _taxCalculator    = Substitute.For <ITaxCalculator>();
     _receiptFormatter = Substitute.For <IReceiptFormatter>();
 }