public void TestMethodCalculate()
        {
            OrderRequest request = new OrderRequest();

            request.CustomerId      = "8e4e8991-aaee-495b-9f24-52d5d0e509c5";
            request.LoyaltyCard     = "CTX0000001";
            request.TransactionDate = Convert.ToDateTime("2020-03-03");
            request.Basket          = new OrderBasketItem[3] {
                new OrderBasketItem()
                {
                    ProductId = "PRD01", Quantity = 3, UnitPrice = 1.2M
                }, new OrderBasketItem()
                {
                    ProductId = "PRD02", Quantity = 2, UnitPrice = 2.0M
                }, new OrderBasketItem()
                {
                    ProductId = "PRD04", Quantity = 1, UnitPrice = 2.3M
                }
            };

            IShoppingCalculation sc       = new ShoppingCalculation(request);
            OrderResponse        response = sc.Calculate();

            Assert.IsFalse(string.Compare(request.CustomerId, response.CustomerId) != 0, " CustomerId not match expected: " + request.CustomerId + " actual: " + response.CustomerId);
            Assert.IsFalse(request.LoyaltyCard != response.LoyaltyCard, " LoyaltyCardnot match");
            Assert.IsFalse(request.TransactionDate != response.TransactionDate, " TransactionDate not match");
            Assert.IsFalse(response.TotalAmount != 9.9M, "TotalAmount incorrect");
            Assert.IsFalse(response.GrandTotal != 9.3M, "GrandTotal incorrect");
            Assert.IsFalse(response.DiscountApplied != 0.6M, "DiscountApplied incorrect");
            Assert.IsFalse(response.PointsEarned != 9.2M, "PointsEarned incorrect");
        }
Пример #2
0
 /// <summary>
 /// Backend API entry to generate order response
 /// </summary>
 /// <param name="request">OrderRequest object from front end</param>
 /// <returns>OrderResponse object after calculation</returns>
 public OrderResponse CalculateOrder(OrderRequest request)
 {
     try
     {
         IShoppingCalculation sc       = new ShoppingCalculation(request);
         OrderResponse        response = sc.Calculate();
         return(response);
     }
     catch (CustomExceptions e)
     {
         // log exception if needed in future
         return(null);
     }
     catch (Exception e)
     {
         // system exception caught, add logic here and throw out
         throw;
     }
 }