Example #1
0
        internal int AccumulatePrice(int quantity, IPriceStrategy priceStrategy)
        {
            IEnumerable <Batch> strategiedBatches = priceStrategy.Apply(this.batches);

            int totalPrice     = 0;
            var stockProcessor = new StockProcessor(quantity);

            stockProcessor.Process(strategiedBatches, (q, batch) => totalPrice += batch.GetPriceFor(q));

            return(totalPrice);
        }
Example #2
0
        internal void ReduceStock(int quantity, IPriceStrategy priceStrategy)
        {
            IEnumerable <Batch> strategiedBatches = priceStrategy.Apply(this.batches);

            var stockProcessor = new StockProcessor(quantity);

            stockProcessor.Process(strategiedBatches, (q, batch) =>
            {
                batch.ReduceQuantity(q);

                if (batch.IsEmpty())
                {
                    this.batches.Remove(batch);
                }
            });
        }