Example #1
0
        static void Main(string[] args)
        {
            var food       = new Category("Food");
            var electronic = new Category("Electronic");

            var apple       = new Product("Apple", 100.0, food);
            var banana      = new Product("Banana", 200.0, food);
            var mobilePhone = new Product("Mobile Phone", 1000.0, electronic);
            var notebook    = new Product("Notebook", 3000.0, electronic);

            var cart = new Business.Domains.ShoppingCart();

            cart.AddItem(apple, 1);
            cart.AddItem(banana, 1);
            cart.AddItem(mobilePhone, 3);
            cart.AddItem(notebook, 1);

            var campaign1 = new Campaign(food, 20.0, 2, DiscountType.Rate);
            var campaign2 = new Campaign(food, 30.0, 2, DiscountType.Amount);
            var campaign3 = new Campaign(electronic, 30.0, 1, DiscountType.Amount);

            cart.ApplyCampaigns(campaign1, campaign2, campaign3);

            var coupon = new Coupon(500.0, 10, DiscountType.Amount);

            cart.ApplyCoupon(coupon);

            cart.Print();
        }
Example #2
0
        public void Should_return_discount_if_there_is_an_applicable_campaign()
        {
            var category   = new Category("Electronic");
            var notebook   = new Product("Notebook", 2000.0, category);
            var smartPhone = new Product("SmartPhone", 1000.0, category);

            var campaign = new Campaign(category, AmountOfDiscount, MinimumItemQuantity, DiscountType.Rate);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(notebook, Quantity);
            sut.AddItem(smartPhone, Quantity);
            sut.ApplyCampaigns(campaign);

            var result = sut.GetCampaignDiscount();

            var total = sut.LineItems.Where(a => a.Product.Category.Title.Equals(category.Title)).Sum(a => a.Quantity * a.Product.UnitPrice);

            result.Should().NotBe(default(double));
            result.Should().Be(total * AmountOfDiscount / 100);
        }
Example #3
0
        public void Should_return_delivery_cost_for_line_items()
        {
            var productCategory = new Category("Electronic");
            var product         = new Product("Notebook", 1000.0, productCategory);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(product, Quantity);

            var result = sut.GetDeliveryCost();

            result.Should().NotBe(default(double));
        }
Example #4
0
        public void Should_return_zero_discount_if_there_is_no_coupon()
        {
            var productCategory = new Category("Electronic");
            var product         = new Product("Notebook", 100.0, productCategory);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(product, Quantity);

            var result = sut.GetCouponDiscount();

            result.Should().Be(default(double));
        }
Example #5
0
        public void Should_return_zero_discount_if_there_is_no_applicable_coupon()
        {
            var productCategory = new Category("Electronic");
            var product         = new Product("Notebook", 100.0, productCategory);

            var coupon = new Coupon(MinimumPurchaseAmount, AmountOfDiscount, DiscountType.Amount);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(product, Quantity);
            sut.ApplyCoupon(coupon);

            var result = sut.GetCouponDiscount();

            result.Should().Be(default(double));
        }
Example #6
0
        public void Should_return_total_amount_after_discounts_cost_for_cart()
        {
            var productCategory = new Category("Electronic");
            var product         = new Product("Notebook", 1000.0, productCategory);

            var coupon = new Coupon(MinimumPurchaseAmount, AmountOfDiscount, DiscountType.Amount);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(product, Quantity);
            sut.ApplyCoupon(coupon);

            var result = sut.GetTotalAmountAfterDiscounts();

            result.Should().NotBe(default(double));
        }
Example #7
0
        public void Should_print_details_for_cart()
        {
            var productCategory = new Category("Electronic");
            var product         = new Product("Notebook", 1000.0, productCategory);

            var coupon = new Coupon(MinimumPurchaseAmount, AmountOfDiscount, DiscountType.Amount);

            var sut = new Business.Domains.ShoppingCart();

            sut.AddItem(product, Quantity);
            sut.ApplyCoupon(coupon);

            sut.Print();

            var result = sut;

            result.Should().NotBeOfType <Exception>();
        }
Example #8
0
        public void Should_create_line_item_by_adding_product_with_quantity()
        {
            var category = new Category("Electronic");
            var products = new List <Product>();

            var sut = new Business.Domains.ShoppingCart();

            for (int i = 1; i < LineItemCount + 1; i++)
            {
                var product = new Product($"Notebook-{i}", 1000.0 * i, category);
                sut.AddItem(product, Quantity);
                products.Add(product);
            }

            var result = sut;

            result.LineItems.Should().HaveCount(LineItemCount);
            result.LineItems.Select(a => a.Product).Count().Should().Be(products.Count);
            result.LineItems.Sum(a => a.Quantity).Should().Be(LineItemCount * Quantity);
        }