Example #1
0
        public void Checkout_get_total_price_bulk_matching_offer_mixed_items_at_checkout()
        {
            // Setup
            ICheckout checkout          = new CheckoutController(productInventory);
            Product   inventoryProductA = productInventory.Get("A");
            MultiDeal multiDealA        = inventoryProductA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(inventoryProductA);
            }
            Product   inventoryProductB = productInventory.Get("B");
            MultiDeal multiDealB        = inventoryProductB.MultiDeal;

            for (int i = 0; i < multiDealB.Units; i++)
            {
                checkout.Scan(inventoryProductB);
            }
            int expectedPrice = multiDealA.MultiDealPrice + multiDealB.MultiDealPrice;

            // Act
            int actualTotalPrice = checkout.GetTotalPrice();

            // Assert
            Assert.AreEqual(expectedPrice, actualTotalPrice);
        }
Example #2
0
        public virtual async Task AddressAndPayment_RedirectToCompleteWhenSuccessful()
        {
            const string cartId = "CartId_A";

            var order = CreateOrder();

            var formCollection = new Dictionary <string, StringValues> {
                { "PromoCode", new[] { "FREE" } }
            };

            using var context = CreateContext();
            await context.Database.CreateExecutionStrategy().ExecuteAsync(
                async() =>
            {
                using (Fixture.BeginTransaction(context))
                {
                    var cartItems = CreateTestCartItems(cartId, itemPrice: 10, numberOfItems: 1);
                    context.AddRange(cartItems.Select(n => n.Album).Distinct());
                    context.AddRange(cartItems);
                    context.SaveChanges();

                    var controller = new CheckoutController(formCollection);

                    var result = await controller.AddressAndPayment(context, cartId, order);

                    Assert.Equal(order.OrderId, result);
                }
            });
        }
Example #3
0
        public void Checkout_get_total_price_at_complete_checkout()
        {
            // Setup
            ICheckout checkout   = new CheckoutController(productInventory);
            Product   productA   = productInventory.Get("A");
            MultiDeal multiDealA = productA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(productA);
            }
            checkout.Scan(productA);
            Product   productB   = productInventory.Get("B");
            MultiDeal multiDealB = productB.MultiDeal;

            for (int i = 0; i < multiDealB.Units; i++)
            {
                checkout.Scan(productB);
            }
            checkout.Scan(productB);
            int expectedPrice = multiDealA.MultiDealPrice + productA.Price + multiDealB.MultiDealPrice + productB.Price;

            // Act
            int actualTotalPrice = checkout.CompleteCheckout();

            // Assert
            Assert.AreEqual(expectedPrice, actualTotalPrice);
        }
Example #4
0
        public void Checkout_get_total_price_bulk_matching_offer_same_item_at_checkout_inc_offer_change()
        {
            // Setup
            ICheckout checkout          = new CheckoutController(productInventory);
            string    testSku           = "A";
            Product   inventoryProductA = productInventory.Get(testSku);
            MultiDeal multiDealA        = inventoryProductA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(inventoryProductA);
            }
            int       newDealUnits = multiDealA.Units - 1;
            int       newDealPrice = multiDealA.MultiDealPrice * 3;
            int       numOfMatchingDealsAfterChange       = checkout.Count(testSku) / newDealUnits;
            int       numberOfMiscProductsAfterDealChange = checkout.Count(testSku) % newDealUnits;
            int       newExpectedPrice = (newDealPrice * numOfMatchingDealsAfterChange) + (inventoryProductA.Price * numberOfMiscProductsAfterDealChange);
            MultiDeal newMultiDeal     = new MultiDeal(newDealUnits, newDealPrice, multiDealA.ValidFromDate, multiDealA.ValidBeforeDate);

            // Act
            int totalPriceBeforeChange = checkout.GetTotalPrice();

            Assert.AreEqual(multiDealA.MultiDealPrice, totalPriceBeforeChange);
            // Change inventory multiDeal
            productInventory.Replace(new Product(testSku, inventoryProductA.Price, newMultiDeal));
            int totalPriceAfterChange = checkout.GetTotalPrice();

            // Assert
            // prove that offer change is reflected
            Assert.AreNotEqual(totalPriceBeforeChange, totalPriceAfterChange);
            Assert.AreEqual(newExpectedPrice, totalPriceAfterChange);
        }
 public CartSteps(ScenarioContext scenarioContext)
 {
     _driver  = scenarioContext["WEB_DRIVER"] as IWebDriver;
     products = new productsController(scenarioContext);
     cart     = new CartController(scenarioContext);
     checkout = new CheckoutController(scenarioContext);
 }
Example #6
0
        public async Task Pay_OrderWithIdeal()
        {
            var controller = new CheckoutController();
            var charge     = new ChargeRequest
            {
                Amount   = 70.0,
                Currency = "EUR",
                Payments =
                    new List <PaymentRequest>
                {
                    new IdealPaymentRequest
                    {
                        Amount   = 70.0,
                        Currency = "EUR",
                        Details  =
                            new IdealDetailsRequest
                        {
                            IssuerId     = "RABONL2U",
                            SuccessUrl   = "",
                            FailedUrl    = "",
                            CancelledUrl = "",
                            ExpiredUrl   = "",
                            PurchaseId   = Guid.NewGuid().ToString("N"),
                            Description  = "Test description."
                        }
                    }
                }
            };
            var response = await controller.ProceedPaymentAsync(charge);

            Assert.AreEqual(70m, response.Amount);
            Assert.AreEqual("Open", response.Status);
        }
        public void WhenClearShoppingCart_ThenShoppingCartIsEmpty()
        {
            // Arrange
            List <Product> products = new List <Product>()
            {
                new Product()
                {
                    Id = 1, Name = "A", StockQty = 2
                }
            };
            List <ShoppingCart> carts = new List <ShoppingCart>()
            {
                new ShoppingCart()
                {
                    Id = 1, ProductId = 1, ProductName = "A", Quantity = 1
                }
            };

            mockCartRepo.Setup(x => x.GetAll()).Returns(carts);
            mockProdRepo.Setup(x => x.Get(products[0].Id)).Returns(products[0]);
            mockCartRepo.Setup(x => x.Clear()).Returns(true);

            // Act
            var controller = new CheckoutController(mockProdRepo.Object, mockCartRepo.Object);
            var result     = controller.Clear() as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
        }
Example #8
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    index = Convert.ToInt32(e.CommandArgument);
            string id    = Session["id"].ToString();

            CheckoutController.DoCheckout(int.Parse(id), index, DateTime.Now);
            Response.Redirect("MemberHome.aspx?id=" + index);
        }
Example #9
0
 public void SetUp()
 {
     _gatewayAuthenticationService = new Mock <IGatewayAuthenticationService>();
     _gatewayChekoutService        = new Mock <IGatewayCheckoutService>();
     _completeOrderService         = new Mock <ICompleteOrderService>();
     _completeOrderService.Setup(x => x.DelayExecution(It.IsAny <int>()));
     _checkoutController = new CheckoutController(_gatewayAuthenticationService.Object, _gatewayChekoutService.Object, _completeOrderService.Object);
 }
Example #10
0
        public void Checkout_create_checkout()
        {
            // Setup
            // Act
            ICheckout checkout = new CheckoutController(productInventory);

            // Assert
            Assert.IsNotNull(checkout);
        }
Example #11
0
        public MainWindow()
        {
            InitializeComponent();

            this.auditor            = new Auditor();
            this.shipper            = new Shipper();
            this.checkoutController = new CheckoutController();
            this.checkoutController.CheckoutProcessing += this.auditor.AuditOrder;
            this.checkoutController.CheckoutProcessing += this.shipper.ShipOrder;
        }
Example #12
0
        public void TestDeliveryDates()
        {
            var controller = new CheckoutController();

            controller.Request.Cookies.Add(new System.Web.HttpCookie("meal_id", "a7d1c44f-39e2-430e-b5bd-e614be20da7f"));
            var result        = controller.Index() as ViewResult;
            var deliverydates = (List <string[]>)result.ViewBag.Deliveries;

            Assert.IsTrue(deliverydates.Count > 0);
        }
        public void AddressAndPayment()
        {
            // Arrange
            CheckoutController controller = new CheckoutController();

            // Act
            ViewResult result = controller.AddressAndPayment() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Example #14
0
 public CheckoutControllerTests()
 {
     this.billingService  = Substitute.For <IBillingService>();
     this.deliveryService = Substitute.For <IDeliveryService>();
     this.orderService    = Substitute.For <IOrderService>();
     this.controller      = Substitute.For <CheckoutController>(
         this.billingService,
         this.orderService,
         this.deliveryService);
     this.fixture = new Fixture();
 }
Example #15
0
        public MainWindow()
        {
            this.InitializeComponent();
            Window.Current.SizeChanged += App.WindowSizeChanged;

            this.auditor            = new Auditor();
            this.shipper            = new Shipper();
            this.checkoutController = new CheckoutController();
            this.checkoutController.CheckoutProcessing += this.auditor.AuditOrder;
            this.checkoutController.CheckoutProcessing += this.shipper.ShipOrder;
        }
Example #16
0
 protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "SelectPaymentType")
     {
         int Row = 0;
         Row = Convert.ToInt16(e.CommandArgument.ToString());
         String PaymentID = GridView2.Rows[Row].Cells[0].Text.ToString();
         String UserID    = Session["LoginSession"].ToString();
         CheckoutController.DoCheckout(UserID, PaymentID);
         Response.Redirect("ViewCart.aspx");
     }
 }
Example #17
0
        public void Checkout_Should_Return_Price_With_Discount()
        {
            ICheckout checkout = new CheckoutController(_mockRepository, _pricingService);

            checkout.Scan("A"); //50
            checkout.Scan("B"); //30
            checkout.Scan("A"); //50

            decimal result = checkout.GetTotalPrice();

            result.Should().Be(130);
        }
        public MainPage()
        {
            this.InitializeComponent();

            this.auditor            = new Auditor();
            this.shipper            = new Shipper();
            this.checkoutController = new CheckoutController();
            this.checkoutController.CheckoutProcessing += this.auditor.AuditOrder;
            this.checkoutController.CheckoutProcessing += this.shipper.ShipOrder;
            this.auditor.AuditProcessingComplete       += this.displayMessage;
            this.shipper.ShippingProcessingComplete    += this.displayMessage;
        }
Example #19
0
        public void Checkout_scan_item_at_checkout()
        {
            // Setup
            ICheckout checkout = new CheckoutController(productInventory);

            // Act
            Product product = productInventory.Get("A");

            checkout.Scan(product);

            // Assert
            Assert.AreEqual(1, checkout.CountAll());
        }
Example #20
0
        public void CreateCheckoutController_WhenParametersAreNotNull()
        {
            // Arrange
            Mock <IShoppingCart>   shoppingCartMock   = new Mock <IShoppingCart>();
            Mock <IOrderFactory>   orderFactoryMock   = new Mock <IOrderFactory>();
            Mock <ICartIdentifier> cartIdentifierMock = new Mock <ICartIdentifier>();

            //Act
            CheckoutController checkoutController = new CheckoutController(shoppingCartMock.Object, orderFactoryMock.Object, cartIdentifierMock.Object);

            // Assert
            Assert.That(checkoutController, Is.Not.Null);
        }
        public MainWindow()
        {
            InitializeComponent();

            _auditor            = new Auditor();
            _shipper            = new Shipper();
            _checkoutController = new CheckoutController();
            _checkoutController.CheckoutProcessing += _auditor.AuditOrder;
            _checkoutController.CheckoutProcessing += _shipper.ShipOrder;

            _auditor.AuditProcessingComplete += DisplayMessage;
            _shipper.ShipProcessingComplete  += DisplayMessage;
        }
Example #22
0
        public async Task Complete_ReturnsErrorIfInvalidOrder()
        {
            using (var context = CreateContext())
            {
                using (Fixture.BeginTransaction(context))
                {
                    var controller = new CheckoutController();

                    var result = await controller.Complete(context, -3333);

                    Assert.Equal("Error", result);
                }
            }
        }
        public MainPage()
        {
            InitializeComponent();

            Auditor auditor = new Auditor();
            Shipper shipper = new Shipper();

            _checkoutController = new CheckoutController();

            _checkoutController.CheckoutProcessing += auditor.AuditOrder;
            _checkoutController.CheckoutProcessing += shipper.ShipOrder;
            auditor.AuditProcessingComplete        += DisplayMessage;
            shipper.ShipProcessingComplete         += DisplayMessage;
        }
Example #24
0
        public void Checkout_scan_items_in_bulk_at_checkout()
        {
            // Setup
            ICheckout       checkout        = new CheckoutController(productInventory);
            IList <Product> trolleyContents = shoppingTrolley.GetAll();

            // Act
            foreach (Product product in trolleyContents)
            {
                checkout.Scan(product);
            }

            // Assert
            Assert.AreEqual(trolleyContents.Count, checkout.CountAll());
        }
Example #25
0
        public void ShouldReturnOrder()
        {
            // Arrange
            var fixture    = new Fixture();
            var controller = new CheckoutController();
            var cart       = fixture.CreateMany <CartItem>();

            // Act
            var order = controller.Checkout(cart);

            // Assert
            order.Should().NotBeNull();
            order.TotalQuantity.Should().Be(cart.Count());
            order.TotalPrice.Should().Be(cart.Sum(item => item.Book.Price));
        }
Example #26
0
        public void Checkout_get_total_price_single_item_at_checkout()
        {
            // Setup
            ICheckout checkout = new CheckoutController(productInventory);
            Product   product  = productInventory.Get("A");
            int       price    = product.Price;

            checkout.Scan(product);

            // Act
            int totalPrice = checkout.GetTotalPrice();

            // Assert
            Assert.AreEqual(price, totalPrice);
        }
Example #27
0
        public virtual async Task Complete_ReturnsErrorIfInvalidOrder()
        {
            using var context = CreateContext();
            await context.Database.CreateExecutionStrategy().ExecuteAsync(
                async() =>
            {
                using (Fixture.BeginTransaction(context))
                {
                    var controller = new CheckoutController();

                    var result = await controller.Complete(context, -3333);

                    Assert.Equal("Error", result);
                }
            });
        }
Example #28
0
        public async Task CheckoutAsyncReturnsCorrectBasketTotal()
        {
            var controller = new CheckoutController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // create basket object to pass in (value £9.29)
            var basketJSON = "{\"Items\":[{\"SKU\":\"T23\",\"Quantity\":1},{\"SKU\":\"A99\",\"Quantity\":7},{\"SKU\":\"C40\",\"Quantity\":2},{\"SKU\":\"B15\",\"Quantity\":5}]}";

            var response = await controller.GetBasketTotal(basketJSON) as OkNegotiatedContentResult <decimal>;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.AreEqual(response.Content, 9.29m);
        }
Example #29
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int      PaymentTypeID = int.Parse(dropdownlist.SelectedValue);
            DateTime date          = DateTime.Now;

            Response response = CheckoutController.doCheckout(carts, u.ID, PaymentTypeID, date);

            if (response.successStatus)
            {
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                ErrorLabel.Visible = true;
                ErrorLabel.Text    = response.message;
            }
        }
Example #30
0
        public void Setup()
        {
            _controllerExceptionHandler = new Mock <ControllerExceptionHandler>();
            _requestContext             = new Mock <RequestContext>();
            _httpRequestBase            = new Mock <HttpRequestBase>();

            _httpContextBase = new Mock <HttpContextBase>();
            _httpContextBase.Setup(x => x.Request).Returns(_httpRequestBase.Object);

            _exceptionContext = new ExceptionContext
            {
                HttpContext    = _httpContextBase.Object,
                RequestContext = _requestContext.Object
            };

            _subject = new CheckoutController(null, null, null, null, null, null, null, null, null, null, null, _controllerExceptionHandler.Object, null, null);
        }
        public void Setup()
        {
            _controllerExceptionHandler = new Mock<ControllerExceptionHandler>();
            _requestContext = new Mock<RequestContext>();
            _httpRequestBase = new Mock<HttpRequestBase>();

            _httpContextBase = new Mock<HttpContextBase>();
            _httpContextBase.Setup(x => x.Request).Returns(_httpRequestBase.Object);

            _exceptionContext = new ExceptionContext
            {
                HttpContext = _httpContextBase.Object,
                RequestContext = _requestContext.Object
            };

            _subject = new CheckoutController(null, null, null, null, null, null, null, null, null, null,null, _controllerExceptionHandler.Object,null);
        }