Exemplo n.º 1
0
        public void Setup()
        {
            discountCollection = new SupermarketCheckout.DiscountCollection
            {
                ValidityRange =
                    new SupermarketCheckout.Utils.DateTimeRange(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1))
            };

            checkout = new SupermarketCheckout.Checkout {
                DiscountCollection = discountCollection
            };
        }
Exemplo n.º 2
0
        public void TestPayItemsWithDiscountNegative()
        {
            var apple = new Item {
                Name = "Apple", Price = 30
            };
            var banana = new Item {
                Name = "Banana", Price = 50
            };
            var peach = new Item {
                Name = "Peach", Price = 60
            };

            checkout.AddItem(2, apple);
            checkout.AddItem(7, banana);
            checkout.AddItem(4, peach);

            var invalidDiscountCollection = new SupermarketCheckout.DiscountCollection
            {
                ValidityRange =
                    new SupermarketCheckout.Utils.DateTimeRange(new DateTime(DateTime.Now.Year - 1, 6, 10),
                                                                new DateTime(DateTime.Now.Year - 1, 6, 16))
            };

            var discountApple = new Discount {
                Name = "2 for 45", Quantity = 2, Price = 45
            };
            var discountBanana = new Discount {
                Name = "3 for 130", Quantity = 3, Price = 130
            };
            var discountPeach = new Discount {
                Name = "5 for 40", Quantity = 5, Price = 40
            };

            invalidDiscountCollection.Add(apple, discountApple);
            invalidDiscountCollection.Add(banana, discountBanana);
            invalidDiscountCollection.Add(peach, discountPeach);

            checkout.DiscountCollection = invalidDiscountCollection;
            var checkoutBill = checkout.PayItems();

            var paidApple = new CheckoutItem(apple, SupermarketCheckout.Checkout.NoDiscount)
            {
                Amount           = 2, Price = 60,
                AppliedDiscounts = 0
            };
            var paidBanana = new CheckoutItem(banana, SupermarketCheckout.Checkout.NoDiscount)
            {
                Amount           = 7, Price = 350,
                AppliedDiscounts = 0
            };
            var paidPeach = new CheckoutItem(peach, SupermarketCheckout.Checkout.NoDiscount)
            {
                Amount           = 4, Price = 240,
                AppliedDiscounts = 0
            };

            Assert.True(checkoutBill.Items.Contains(paidApple));
            Assert.True(checkoutBill.Items.Contains(paidBanana));
            Assert.True(checkoutBill.Items.Contains(paidPeach));
            Assert.AreEqual(650, checkoutBill.Total);
        }
Exemplo n.º 3
0
 public void Setup()
 {
     discountCollection = new SupermarketCheckout.DiscountCollection();
     discountCollection.ValidityRange =
         new SupermarketCheckout.Utils.DateTimeRange(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1));
 }