public void CalculateOrderPriceWithNullOrderLine_ReturnZero()
        {
            var order = new SalesOrder();

            // Act
            var price = order.GetOrderPrice();

            // Assert
            Assert.Equal(0, price);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Given an order, calculate the best shipping amount according to ShippingPriceRate rule
        /// </summary>
        /// <param name="order"></param>
        /// <returns>The shipping amount sent and total shipping cost</returns>
        public Tuple <decimal, decimal> CalculatePriceBasedOptimalShippingAmount(SalesOrder order)
        {
            var totalPrice = order.GetOrderPrice();

            // From the ShippingPriceRate rule, we can see that we should send as much amount as possible

            var shippingCost   = 0m;
            var shippingWeight = order.GetOrderShippingWeight();

            if (totalPrice >= 0 && totalPrice <= 50)
            {
                shippingCost = shippingWeight * 5.5m;
            }
            else if (totalPrice > 50 && totalPrice < 100)
            {
                // As shipping rate between $50 and $100 is zero, the optimised shipping amount is max at 50kg
                if (shippingWeight <= 50)
                {
                    shippingCost = shippingWeight * 5.5m;
                }
                else
                {
                    shippingCost = shippingWeight * 0m;
                }
            }
            else if (totalPrice >= 100 && totalPrice <= 500)
            {
                shippingCost = shippingWeight * 10m;
            }
            else if (totalPrice > 500 && totalPrice < 1000)
            {
                // There is no rule for price rages [500, 1000], so assume that there is no cost for shipping
                shippingCost = 0;
            }
            else if (totalPrice >= 1000)
            {
                shippingCost = shippingWeight * 15m;
            }

            return(Tuple.Create(shippingWeight, shippingCost));
        }
        public void CalculateOrderPrice_ReturnCorrectPrice()
        {
            var order = new SalesOrder
            {
                Lines = new List <SalesOrderLine>
                {
                    new SalesOrderLine
                    {
                        Price = 10
                    },
                    new SalesOrderLine
                    {
                        Price = 20
                    }
                }
            };

            // Act
            var price = order.GetOrderPrice();

            // Assert
            Assert.Equal(30, price);
        }