Exemplo n.º 1
0
        public void GetTotal_returns_correct_price_where_multiple_discounts_are_applied()
        {
            // Arrange
            var offers = new List <IDiscountOffer>
            {
                new FreeMilkOffer(),
                new HalfPriceBreadOffer()
            };

            var basket  = new Basket();
            var calc    = new DiscountCalculator(offers);
            var handler = new CheckoutHandler(calc);

            basket.AddItem(new Butter());
            basket.AddItem(new Butter());
            basket.AddItem(new Bread());

            for (int i = 0; i < 8; i++)
            {
                basket.AddItem(new Milk());
            }

            // Act
            var result = handler.CalculateBasketTotal(basket);

            // Assert
            Assert.Equal(9M, result);
        }
        public void CalculateBasketTotal_throws_null_argument_exception_when_calc_is_null()
        {
            // Arrange
            var mock    = new Mock <IBasket>();
            var handler = new CheckoutHandler(null);

            // Assert
            Assert.Throws <ArgumentNullException>(() => handler.CalculateBasketTotal(mock.Object));
        }
Exemplo n.º 3
0
        public static Response doCheckout(List <Cart> carts, int UserID, int PaymentTypeID, DateTime date)
        {
            if (!carts.Any())
            {
                return(new Response(false, "Cant do checkout because cart is empty"));
            }

            Response response = CheckoutHandler.doCheckout(carts, UserID, PaymentTypeID, date);

            return(response);
        }
        public void CalculateBasketTotal_returns_correct_total_with_discount_applied()
        {
            //Arrange
            var mockBasket = new Mock <IBasket>();
            var mockCalc   = new Mock <IDiscountCalculator>();
            var handler    = new CheckoutHandler(mockCalc.Object);

            mockBasket.Setup(b => b.GetTotal()).Returns(1);
            mockCalc.Setup(c => c.CalculateDiscount(It.IsAny <IEnumerable <IProduct> >())).Returns(.5M);

            // Act
            var result = handler.CalculateBasketTotal(mockBasket.Object);

            // Assert
            Assert.Equal(.5M, result);
        }
        private CheckoutHandler CheckPaymentMethod(Order order)
        {
            CheckoutHandler ch    = null;
            var             payId = order.PaymentMethodId;

            if (!string.IsNullOrEmpty(payId))
            {
                if (_paymentHandlers.ContainsKey(payId))
                {
                    ch = _paymentHandlers[payId];
                }
                else
                {
                    ch = CheckoutHandler.GetCheckoutHandlerFromPaymentID(payId);
                    _paymentHandlers.Add(payId, ch);
                }
            }

            return(ch);
        }
Exemplo n.º 6
0
        public void GetTotal_returns_correct_discounted_price_for_one_free_milk()
        {
            // Arrange
            var offers = new List <IDiscountOffer>
            {
                new FreeMilkOffer(),
                new HalfPriceBreadOffer()
            };

            var basket  = new Basket();
            var calc    = new DiscountCalculator(offers);
            var handler = new CheckoutHandler(calc);

            for (int i = 0; i < 4; i++)
            {
                basket.AddItem(new Milk());
            }

            // Act
            var result = handler.CalculateBasketTotal(basket);

            // Assert
            Assert.Equal(3.45M, result);
        }
 public static void DoCheckout(int userId, int paymentId, DateTime date)
 {
     CheckoutHandler.DoCheckout(userId, paymentId, date);
 }
        private void ProcessOrders(OrderCollection ordersToSync)
        {
            string ordersToProcess = "";

            foreach (var order in ordersToSync)
            {
                ordersToProcess += order.Id + ",";
            }
            Logger.Log(string.Format("The list of order to run: {0}", ordersToProcess));

            foreach (var order in ordersToSync)
            {
                string state          = "";
                string currentOrderId = order.Id;

                try
                {
                    OrderCaptureInfo result;
                    CheckoutHandler  ch = CheckPaymentMethod(order);
                    var payed           = order.OrderFieldValues.First(of => of.OrderField.SystemName == "PaymentCaptured");

                    payed.Value = false;

                    if (ch != null && ch is IRemoteCapture)
                    {
                        result = order.Capture();
                    }
                    else
                    {
                        throw new ArgumentException("Payment method not valid for capture!", "order.PaymentMethodId");
                    }

                    Logger.Log(string.Format("Order ID {0} Successfuly Captured with result: {1}", currentOrderId, result != null ? result.Message : "{null}"));

                    //update custom fields to avoid being payed again
                    payed.Value = true;

                    Logger.Log(string.Format("Order ID {0} done!", currentOrderId));

                    state = SuccessValue;
                }
                catch (Exception ex)
                {
                    state          = ErrorValue;
                    _processError += string.Format("Error in Capture. Order ID = {0}, Exception = {1}", currentOrderId, ex);
                    Logger.Log(string.Format("Error in Capture. Order ID = {0}, Exception = {1}", currentOrderId, ex));
                }
                finally
                {
                    if (SendBackToERP)
                    {
                        // save capture changes and try to update ERP
                        if (!Global.IntegrationEnabledFor(order.ShopId))
                        {
                            UpdateOrder(order, state);
                        }
                        else
                        {
                            bool?result = OrderHandler.UpdateOrder(order, LiveIntegrationSubmitType.CaptureTask, SuccessValue, ErrorValue);
                            if (result == null)
                            {
                                UpdateOrder(order, state);
                            }
                            else if (!result.Value)
                            {
                                _processError += string.Format("Order ID {0} successfully captured but not updated to the ERP.\n"
                                                               , currentOrderId);
                            }
                        }
                    }
                }
            }

            Logger.Log("All orders done!");
        }
Exemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
 }
Exemplo n.º 10
0
 public static void DoCheckout(String UserID, String PaymentID)
 {
     CheckoutHandler.DoCheckout(UserID, PaymentID);
 }