public override decimal CalculateCostComponent(Order order)
        {
            decimal taxAmount = _taxRate * order.Cost.EffectivePrice * order.Quantity;

            order.Cost.TaxAmount = taxAmount;
            order.Cost.TaxRate = _taxRate;

            return taxAmount + CostComponent.CalculateCostComponent(order);
        }
        private decimal CalculateTotalPrice(Order order)
        {
            decimal totalPrice = 0.0M;
            if (order != null)
            {
                totalPrice = order.Quantity * order.Cost.EffectivePrice;
            }

            return totalPrice;
        }
        public void Process_OrderIsNotShipped_ShouldSetTheShipmentPropertyOfTheOrder()
        {
            var orderProcessor = new OrderProcessor(new FakeShippingCalculator());
            var order = new Order();

            orderProcessor.Process(order);

            Assert.IsTrue(order.IsShipped);
            Assert.AreEqual(1, order.Shipment.Cost);
            Assert.AreEqual(DateTime.Today.AddDays(1), order.Shipment.ShippingDate);
        }
        public void Process_OrderIsAlreadyShipped_ThrowsAnException()
        {
            var orderProcessor = new OrderProcessor(new FakeShippingCalculator());

            var order = new Order
            {
                Shipment = new Shipment()
            };

            orderProcessor.Process(order);
        }
        public object Process(Order order, IOrderConfig orderConfig)
        {
            ShippingCost = CreateShippingCostCalculator(orderConfig);  // Factory Method pattern

            // Decorator pattern - set up the types cost components to be calculated, in the desired order.
            CostComponent costComponent = new ShippingCostElement(this);
            costComponent = new IncomeTaxCostElement(costComponent);
            order.Cost.Total = costComponent.CalculateCostComponent(order);

            return order;
        }
        public void Process(Order order)
        {
            if (order.IsShipped)
            {
                throw new InvalidOperationException("This order is already processed.");
            }

            order.Shipment = new Shipment
            {
                Cost = _shippingCalculator.CalculateShipping(order),
                ShippingDate = DateTime.Today.AddDays(1)
            };
        }
        /// <summary>
        /// An implementation of IShippingCost for calculating FedEx shipping cost
        /// </summary>
        public decimal CalculateShippingCost(Order order, bool updateOrder = true)
        {
            decimal shippingCost = 0.0M;
            if (order != null && order.Cost != null)
            {
                // TODO: make the rate configurable or encapsulated
                shippingCost = Convert.ToDecimal(order.Weight) * 0.2M;
                if (updateOrder)
                {
                    order.Cost.ShippingCost = shippingCost;
                }
            }

            return shippingCost;
        }
        /// <summary>
        /// An implementation of IShippingCost for calculating USPS shipping cost
        /// </summary>
        public decimal CalculateShippingCost(Order order, bool updateOrder = true)
        {
            decimal shippingCost = 0.0M;
            if (order != null && order.Cost != null)
            {
                // TODO: make the rate configurable or encapsulated
                shippingCost = order.Cost.EffectivePrice * order.Quantity * 0.4M;
                if (updateOrder)
                {
                    order.Cost.ShippingCost = shippingCost;
                }
            }

            return shippingCost;
        }
Example #9
0
 static void Main(string[] args)
 {
     var orderProcessor = new OrderProcessor(new ShippingCalculator());
     var order = new Order { DatePlaced = DateTime.Now, TotalPrice = 100f };
     orderProcessor.Process(order);
 }
 public float CalculateShipping(Order order)
 {
     return 1;
 }
 /// <summary>
 /// Implementation of the CostComponent class's method for calculating the product price component
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 public override decimal CalculateCostComponent(Order order)
 {
     return CalculateTotalPrice(order);
 }
 public override decimal CalculateCostComponent(Order order)
 {
     return CostComponent.CalculateCostComponent(order) + ShippingCost.CalculateShippingCost(order);
 }