public void Remove_product_from_empty_cart_should_make_the_cart_intact()
        {
            var cart = new ShoppingCart();

            cart.Remove(ProductMother.GetProduct1().Id);

            Assert.AreEqual(0, cart.Items.Count);
        }
Пример #2
0
        public void Add_1_product_to_empty_cart_should_make_cart_contain_1_product()
        {
            var emptyShoppingCart = new ShoppingCart();
            var product = ProductMother.GetProduct1();

            emptyShoppingCart.Add(product);

            Assert.AreEqual(1, emptyShoppingCart.Items[0].Quantity);
        }
        public void Remove_existing_product_should_remove_the_product_from_the_cart()
        {
            var cart = new ShoppingCart();
            var product = ProductMother.GetProduct1();
            cart.Add(product);

            cart.Remove(product.Id);

            Assert.AreEqual(false, cart.Exists(product.Id));
        }
Пример #4
0
        public void Add_product_to_cart_that_does_not_have_this_product_should_make_this_cart_contain_2_purchase_items()
        {
            var cart = new ShoppingCart();
            var product = ProductMother.GetProduct1();
            cart.Add(product);

            var product2 = ProductMother.GetProduct2();
            cart.Add(product2);

            Assert.AreEqual(2, cart.Items.Count);
        }
Пример #5
0
        public void Add_product_to_cart_that_already_exist_this_product_should_still_make_this_cart_contain_1_purchase_item()
        {
            var cart = new ShoppingCart();
            var product = ProductMother.GetProduct1();
            cart.Add(product);

            var product2 = ProductMother.GetProduct1();
            cart.Add(product2);

            Assert.AreEqual(1, cart.Items.Count);
        }
        public void Set_a_product_quantity_to_0_should_remove_this_product_from_cart()
        {
            var cart = new ShoppingCart();
            var product = ProductMother.GetProduct1();
            cart.Add(product, 2);

            cart.UpdateProductQuantity(product.Id, 0);

            var actualResult = cart.Exists(product.Id);
            Assert.AreEqual(false, actualResult);
        }
Пример #7
0
        public void Add_1_product_to_a_cart_containing_the_same_product_should_increment_the_product_count_by_1()
        {
            var cart = new ShoppingCart();
            cart.Add(ProductMother.GetProduct1());

            var productSameAsExistingOne = ProductMother.GetProduct1();
            cart.Add(ProductMother.GetProduct1());

            var productCount = cart.Items.Find(p => p.Product.Id == productSameAsExistingOne.Id).Quantity;

            Assert.AreEqual(2, productCount);
        }
        public void Set_a_product_quantity_to_a_number_should_make_the_cart_contain_this_number_of_this_product()
        {
            var cart = new ShoppingCart();
            var product = ProductMother.GetProduct1();
            cart.Add(product);

            var quantity = 3;
            cart.UpdateProductQuantity(product.Id, quantity);

            var actualResult = cart.GetProductQuantity(product.Id);
            Assert.AreEqual(quantity, actualResult);
        }
        public void Remove_non_existing_product_should_make_the_cart_intact()
        {
            var cart = new ShoppingCart();
            var prod1 = ProductMother.GetProduct1();
            cart.Add(prod1, 2);
            var prod2 = ProductMother.GetProduct2();
            cart.Add(prod2, 4);

            cart.Remove(ProductMother.GetProduct3().Id);

            Assert.AreEqual(2, cart.Items.Count);
        }
Пример #10
0
        public void Checkout_shopping_cart_should_yield_an_order_in_processing_state()
        {
            IPurchaseItemList shoppingCart = new ShoppingCart();
            shoppingCart.Add(ProductMother.GetProduct1(), 3);
            shoppingCart.Add(ProductMother.GetProduct2(), 2);
            CustomerBase customer = CustomerMother.GetCustomer1();
            IPaymentMethod payeMethod = customer.CreditCards[0];
            IShippingMethod shippingMethod = new OvernightShipping();

            var customerOrder = CustomerOrderService.Checkout(shoppingCart, customer, payeMethod, shippingMethod);

            Assert.AreEqual((object)EOrderStatus.Processing, customerOrder.Status);
        }
Пример #11
0
        public void Create_order_by_giving_shoppingcart_and_customer_and_creditcard_and_shippingmethod_should_yield_a_successful_order()
        {
            IPurchaseItemList shoppingCart = new ShoppingCart();
            shoppingCart.Add(ProductMother.GetProduct1(), 3);
            shoppingCart.Add(ProductMother.GetProduct2(), 2);
            CustomerBase customer = CustomerMother.GetCustomer1();
            IPaymentMethod payeMethod = customer.CreditCards[0];
            IShippingMethod shippingMethod = new OvernightShipping();

            var customerOrder = CustomerOrderService.Checkout(shoppingCart, customer, payeMethod, shippingMethod);

            //CollectionAssert.AreEquivalent(cart.Items, order.Items); //Does NOT work
            Assert.AreEqual(shoppingCart.GetTotalPrice(), customerOrder.TotalCost - customerOrder.ShippingCost);
        }
Пример #12
0
        public void Add_product_to_filled_cart_should_increment_the_total_price()
        {
            var cart = new ShoppingCart();
            var existingProduct = ProductMother.GetProduct1();
            cart.Add(existingProduct);
            cart.Add(existingProduct);

            var newProduct = ProductMother.GetProduct2();
            cart.Add(newProduct);

            var expectedTotalPrice = existingProduct.RetailPrice * 2 + newProduct.RetailPrice;

            Assert.AreEqual(expectedTotalPrice, cart.GetTotalPrice());
        }
Пример #13
0
        public void Process_an_order_should_charge_customer_credit_card()
        {
            IPurchaseItemList shoppingCart = new ShoppingCart();
            shoppingCart.Add(ProductMother.GetProduct1(), 3);
            shoppingCart.Add(ProductMother.GetProduct2(), 2);
            CustomerBase customer = CustomerMother.GetCustomer1();
            IPaymentMethod payeMethod = customer.CreditCards[0];
            IShippingMethod shippingMethod = new OvernightShipping();

            var beforedAmount = payeMethod.TotalChargedAmount;
            var customerOrder = CustomerOrderService.Checkout(shoppingCart, customer, payeMethod, shippingMethod);
            var orderTotalPrice = customerOrder.TotalCost;

            Assert.AreEqual((object)(beforedAmount + orderTotalPrice), payeMethod.TotalChargedAmount);
        }
Пример #14
0
        public static CustomerOrder GetCustomerOrderInProcessing1()
        {
            var cart = new ShoppingCart();
            cart.Add(ProductMother.GetProduct1(), 3);
            cart.Add(ProductMother.GetProduct2(), 2);

            var buyer = CustomerMother.GetCustomer1();
            var shippingMethod = new StandardShipping();
            var paymentMethod = CreditCardsMother.GetCreditCard1();

            return new CustomerOrder
            {
                Id = 1,
                OrderDateTime = DateTime.Now.AddDays(1),
                Items = cart.Items,
                Customer = buyer,
                Status = EOrderStatus.Processing,
                ShippingMethod = shippingMethod.MethodName(),
                PaymentMethod = paymentMethod.PaymentName(),
                ProductCost = 200,
                ShippingCost = shippingMethod.CalculatePrice(),
                TotalCost = 200 + shippingMethod.CalculatePrice()
            };
        }
Пример #15
0
        public void Add_product_with_quantity_of_3_should_increment_the_product_count_by_3()
        {
            var cart = new ShoppingCart();
            var productToAdd = ProductMother.GetProduct1();
            cart.Add(productToAdd, 3);

            var productCount = cart.Items.Find(p => p.Product.Id == productToAdd.Id).Quantity;
            Assert.AreEqual(3, productCount);
        }